SOA with Thrift and Finagle
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

SOA with Thrift and Finagle

on

  • 7,772 views

 

Statistics

Views

Total Views
7,772
Views on SlideShare
7,768
Embed Views
4

Actions

Likes
9
Downloads
84
Comments
0

1 Embed 4

https://twitter.com 4

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

SOA with Thrift and Finagle Presentation Transcript

  • 1. SERVICE ORIENTED ARCHITECTUREWITH THRIFT AND FINAGLELuka Zakrajšek@bancekFirst Scala meetup in LjubljanaMay 23, 2013
  • 2. HIIm Luka. I work at Koofr,Slovenian startup of the year
  • 3. DISTRIBUTED SYSTEMSredundancymodularityflexibilityneeds to be simple
  • 4. IT ENDS UP LIKE THIS
  • 5. COMPONENTS MUST TALKSOAPXML-RPCRESTGoogle Protocol BuffersApache Thrift
  • 6. EXAMPLE
  • 7. APACHE THRIFTframework, for scalable cross-languageservices developmentcode generation engineC++, Java, Python, PHP, Ruby, Erlang,Perl, Haskell, C#, Cocoa, JavaScript,Node.js, Smalltalk, OCaml, Delphi, ...Developed by Facebook,opensourced in April 2007
  • 8. APACHE THRIFTType systemTransport layerProtocol layerProcessorsServer
  • 9. TWITTER FINAGLEextensible asynchronous (reactive)RPC system for the JVMuniform client and server APIsfor several protocolshigh performance and concurrencywritten in Scalaprovides both Scala and Java idiomatic APIs
  • 10. TWITTER FINAGLEAsynchronous client/server for multiple protocols:HTTPMemcachedRedisProtobufThriftMySQLmDNS...
  • 11. THRIFT IDLping.thriftnamespace java com.example.pingtypedef string UUIDtypedef i64 DateTimestruct Message {1: required UUID id;2: required string body;3: optional DateTime sent;}service Ping {Message ping(1:Message msg)}
  • 12. SCALA SERVER/CLIENTFinagle for server/clientScrooge for code generationsbt-scrooge for SBT pluginhttps://github.com/bancek/sbt-scrooge
  • 13. SCALA SERVERimport com.twitter.util.Futureimport com.example.ping._class PingImpl extends Ping.FutureIface {def ping(message: Message): Future[Message] = {val returnMessage = message.copy(message="pong")Future.value(returnMessage)}}
  • 14. SCALA SERVERimport java.net.InetSocketAddressimport org.apache.thrift.protocol.TBinaryProtocolimport com.twitter.finagle.thrift.ThriftServerFramedCodecimport com.twitter.finagle.builder.ServerBuilderval port = 1234val processor = new PingImpl()val service = new Ping.FinagledService(processor,new TBinaryProtocol.Factory())ServerBuilder().bindTo(new InetSocketAddress(port)).codec(ThriftServerFramedCodec()).name("ping").build(service)
  • 15. SCALA CLIENTimport java.net.InetSocketAddressimport org.apache.thrift.protocol.TBinaryProtocolimport com.twitter.finagle.Serviceimport com.twitter.finagle.CodecFactoryimport com.twitter.finagle.thrift.{ThriftClientFramedCodec,ThriftClientRequest}import com.twitter.finagle.builder.ClientBuilderimport com.example.ping._val serviceCodec = ThriftClientFramedCodec()val service: Service[ThriftClientRequest, Array[Byte]] =ClientBuilder().hosts(new InetSocketAddress(host, port)).codec(serviceCodec).build()
  • 16. SCALA CLIENTval message = Message(id = "12341234-1234-1234-1234-123412341234",body = "ping",sent = 1369315198125)val pongFuture = client.ping(message)pongFuture.onSuccess { pong =>println(pong.message)}
  • 17. PYTHON CLIENTThrift code generator:Thrift library dependency:thrift --gen py:new_style,utf8strings ping.thriftpip install thrift
  • 18. PYTHON CLIENTfrom thrift.transport import TSocket, TTransportfrom thrift.protocol import TBinaryProtocolfrom ping import Pingfrom ping.ttypes import Messagetransport = TSocket.TSocket(localhost, 1234)transport = TTransport.TFramedTransport(transport)protocol = TBinaryProtocol.TBinaryProtocol(transport)transport.open()
  • 19. PYTHON CLIENTclient = Ping.Client(protocol)message = Message(id=12341234-1234-1234-1234-123412341234,body=ping,sent=1369315198125)pong = client.ping(message)print pong.message
  • 20. QUESTIONS?