Write a thrift server in scala using scrooge and client in python or ruby

冷暖自知 提交于 2019-12-06 04:54:24

问题


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?


回答1:


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:


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.




回答3:


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



来源:https://stackoverflow.com/questions/11549490/write-a-thrift-server-in-scala-using-scrooge-and-client-in-python-or-ruby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!