Slide 1

Slide 1 text

Python & Scala smoke the peace pipe

Slide 2

Slide 2 text

how? Thrift!

Slide 3

Slide 3 text

•  Types •  Transport •  Protocol •  Versioning •  Processors 3

Slide 4

Slide 4 text

types

Slide 5

Slide 5 text

Basic •   bool •   byte •   i16 , signed. •   i32 , signed. •   i64 , signed. •   double •   string 5

Slide 6

Slide 6 text

Structs struct TypesExample { 1: i32 number=10, 2: i64 bigNumber, 3: double decimals, 4: string name="thrifty" } 01. 02. 03. 04. 05. 06. 6

Slide 7

Slide 7 text

Containers •   list is an ordered list of elements. •   set is a unordered set of unique elements. •   map unique keys to values ( dict in python). 7

Slide 8

Slide 8 text

Exceptions Like an struct but declared with the exception keyword: exception IAmNotLearningAnythingException { 1: string message; } 01. 02. 03. 8

Slide 9

Slide 9 text

Services service amazingScalaMethod { string getHelloWorld ( 1: string worldName; ) throws ( 1: WorldNotFound wnfe; ) } 01. 02. 03. 04. 05. 06. 07. 9

Slide 10

Slide 10 text

transport

Slide 11

Slide 11 text

•   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

Slide 12

Slide 12 text

Is not enough? If you really need that, you can do that overwritting the writeMessageBegin() for example sending the checksum of your data. 12

Slide 13

Slide 13 text

protocol

Slide 14

Slide 14 text

•   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

Slide 15

Slide 15 text

versioning

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

processors

Slide 20

Slide 20 text

interface TProcessor { bool process(TProtocol in, TProtocol out) throws TException } 01. 02. 03. 04. 20

Slide 21

Slide 21 text

summarizing

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Similar things out there •  SOAP •  CORBA •  COM •  Pillar •  Protocol buffers 23

Slide 24

Slide 24 text

demo

Slide 25

Slide 25 text

Thanks! •  for listening! •  PyGrunn for bringing me! •  this FB paper! 25

Slide 26

Slide 26 text

Contact me •  @agonzalezro •  agonzalezro@gmail.com •  agonzalezro.github.io 26