Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Python and Scala smoke the peace pipe

Python and Scala smoke the peace pipe

Apache brings them the peace pipe. This pipe is called Thrift. With Thrift you can communicate distributed services. Let's say that the functionality is similar to RESTful APIs but there are some big differences that perhaps can be interesting for your next project."

Alexandre González

May 10, 2013
Tweet

More Decks by Alexandre González

Other Decks in Programming

Transcript

  1. Basic •   bool •   byte •   i16

    , signed. •   i32 , signed. •   i64 , signed. •   double •   string 5
  2. Structs struct TypesExample { 1: i32 number=10, 2: i64 bigNumber,

    3: double decimals, 4: string name="thrifty" } 01. 02. 03. 04. 05. 06. 6
  3. Containers •   list <type> is an ordered list of

    elements. •   set <type> is a unordered set of unique elements. •   map <type1, type2> unique keys to values ( dict in python). 7
  4. Exceptions Like an struct but declared with the exception keyword:

    exception IAmNotLearningAnythingException { 1: string message; } 01. 02. 03. 8
  5. Services service amazingScalaMethod { string getHelloWorld ( 1: string worldName;

    ) throws ( 1: WorldNotFound wnfe; ) } 01. 02. 03. 04. 05. 06. 07. 9
  6. •   TFileTransport , use files. •   TFramedTransport ,

    for non-blocking servers: frames starting with length at the beginning. •   TMemoryTransport , user memory for I/O. •   TSocket , blocking socket. •   TZlibTransport , compressed transport. 11
  7. Is not enough? If you really need that, you can

    do that overwritting the writeMessageBegin() for example sending the checksum of your data. 12
  8. •   TBinaryProtocol , quicker than text protocols but less

    debuggable. •   TCompactProtocol & TDenseProtocol , compact binary without & with metadata. •   TDebugProtocol , human readable. •   TJSONProtocol & TSimpleJSONProtocol , xml? :) SimpleJSON is WO. 14
  9. Field identifiers (it’s better to provide them, if not will

    be autonumeric negative number): struct Example { 1: i32 yourLovelyAttrib i32 youDoNotLikeThis } 01. 02. 03. 04. 16
  10. Possibilities: adding field new server but old client, the new

    server will know that the client is outdated & implement default behaviour for outdated requests. new client but old server, the old server will ignore the extra field. 17
  11. Possibilities: removing a field new server but old client, the

    old client send the field and the new server will ignore it. new client but old server (the most dangerous), no suitable default behaviour. The recommendation is deploy the new server before the new clients. 18
  12. Similar things out there •  SOAP •  CORBA •  COM

    •  Pillar •  Protocol buffers 23