This document discusses service oriented architecture using Thrift and Finagle. It introduces Apache Thrift as a framework for scalable cross-language services development with code generation. It also discusses Twitter's Finagle, an extensible asynchronous RPC system for the JVM. An example is provided of defining a ping service in Thrift IDL and implementing Scala clients and servers using Finagle and code generation with Scrooge. Python client code is also demonstrated.
9. TWITTER FINAGLE
extensible asynchronous (reactive)
RPC system for the JVM
uniform client and server APIs
for several protocols
high performance and concurrency
written in Scala
provides both Scala and Java idiomatic APIs
12. SCALA SERVER/CLIENT
Finagle for server/client
Scrooge for code generation
sbt-scrooge for SBT plugin
https://github.com/bancek/sbt-scrooge
13. SCALA SERVER
import com.twitter.util.Future
import 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 SERVER
import java.net.InetSocketAddress
import org.apache.thrift.protocol.TBinaryProtocol
import com.twitter.finagle.thrift.ThriftServerFramedCodec
import com.twitter.finagle.builder.ServerBuilder
val port = 1234
val processor = new PingImpl()
val service = new Ping.FinagledService(processor,
new TBinaryProtocol.Factory())
ServerBuilder()
.bindTo(new InetSocketAddress(port))
.codec(ThriftServerFramedCodec())
.name("ping")
.build(service)