5

I want to write a thrift service implementation in Scala (using Scrooge) but without the use of Finagle, since I couldn't write a ruby/python client for Finagle servers. The problem is that with scrooge the service doesn't seem to implement "Processor" class.

Assume I have a thrift definition like this:

service TestService {
   void testFunction(1: string message);
}

and I generated the scala files using scrooge, when I tried to use the standard implementation of thrift for scala with that to run the server:

val st = new TServerSocket(9999)
val processor = new TestService.Processor(new TestServiceImpl)
val arg = new TThreadPoolServer.Args(st)
arg.processor(processor) 
val server = new TThreadPoolServer(arg)
server.serve()

The generated TestService object doesn't seem to have the Processor inner class. Any idea how to do that without Finagle? or as another solution, how to write a python or ruby client to finagle thrift servers?

Fernando Correia
  • 21,803
  • 13
  • 83
  • 116
Ahmed Farghal
  • 1,294
  • 11
  • 17

3 Answers3

6

You must use the finagle thrift implementation with Scrooge. Note that it is all wire and IDL compatible, so you can use whatever implementations you want, given that you share the IDL.

You can write Ruby or Python clients for the finagle thrift service: it speaks the same protocol.

  • The doesn't work, I have a method called freeze() that returns Future[Unit] and the python client just hangs when trying to call it. Note that I'm using scala-bootstrapper – Ahmed Farghal Jul 18 '12 at 22:24
  • What does the method return exactly? A `Future.value`? Can you paste the code? – marius a. eriksen Jul 18 '12 at 22:37
  • This is the code `def freeze(s: String): Future[Unit] = { println("Frozen:" + s); Future.Unit }` – Ahmed Farghal Jul 18 '12 at 22:41
  • What about the setup? This should work just fine with the vanilla thrift clients. Can you show me the `ServerBuilder` line? A more complete example would be appreciated -- it's difficult to tell what's wrong with what you have. – marius a. eriksen Jul 19 '12 at 02:31
  • Here is a sample project [link](https://github.com/AhmedSoliman/thiftest), run the server with "sbt run", client "python client.py". – Ahmed Farghal Jul 19 '12 at 08:40
  • Marius - are you saying that there's no way/reason to use scrooge if you're not using the `--finagle` option? I.e. that [17032602](https://stackoverflow.com/questions/17032602/) is basically an invalid question? – Robert Fleming Feb 21 '14 at 01:24
5

Based on the project you linked to, it appears that you have a transport mismatch between client and server.

Your python client is using the buffered transport:

transport = TTransport.TBufferedTransport(transport)

But your scala server is using the framed transport:

.codec(ThriftServerFramedCodec())

If you change the python client to use the framed transport, your issue should go away:

transport = TTransport.TFramedTransport(transport)
2

My problem has been solved by using the same transport in both python and scala.

in my python client.

transport = TTransport.TFramedTransport(transport)

You can find the sample working link

Ahmed Farghal
  • 1,294
  • 11
  • 17