1

I'm trying to write a finagle-thrift service that applies filters in the server.

finagle-thrift generates a service interface (Iface) from the thrift IDL that you implement and then pass to the Thrift.serveIface(addr, Iface) method. There is another method Thrift.serve(addr, Service[Req, Rep]) which could be used to serve a slightly more generic service. Services can be composed, so I'd like to do something like Thrift.service(addr, myFilter andThen myService) but I don't know how to convert an Iface to a Service.

The Thrift.serveIface method uses a private method serverFromIface which does the Iface to Service transformation that would allow me to compose the service with filters before passing it to Thrift.serve. see: https://github.com/twitter/finagle/blob/master/finagle-thrift/src/main/scala/com/twitter/finagle/rich.scala

Since that transformation is private, I don't know how I am supposed to apply filters in the server.

postfuturist
  • 22,211
  • 11
  • 65
  • 85

1 Answers1

0

I discovered a way to construct a Service directly. The code generator creates a class with the name of the service + "$FinagleService". That can be constructed with a reference to the Iface implementation and a TProtocolFactory to produce a Service object that is composable with filters and can be served by the Thrift object.

Here is an example with a service named "Hello":

val service = new Hello$FinagleService(
  iface = new Hello[Future]() {...},
  protocolFactory = Protocols.binaryFactory()
)
val compositeService = myFilter andThen service
Thrift.serve(addr, compositeService)
postfuturist
  • 22,211
  • 11
  • 65
  • 85