0

I am new to Apache Thrift. I think it is a pretty awesome tool that is able to use IDL to define the protocol between client and server so that it could exchange information easily and programmers could save efforts to write extra code.

However, I am not sure why Thrift needs to have server support, e.g. TSimpleServer? Does that mean that Thrift contains the server infrastructure that is enough to provide service? Then, as a developer, we do not need to setup a server by ourselves?

Or, we still need to have a server being setup, which needs to align with Thrift's server requirements?

JensG
  • 12,102
  • 4
  • 40
  • 51
user2547081
  • 189
  • 2
  • 8

1 Answers1

1

As you probably already found out, Apache Thrift is both an serialization framework and RPC framework. So what does that mean?

Pieces of the puzzle

The serialization part of it is the piece of the puzzle that exists to serialize the classes etc. you generated from the Thrift IDL. As a result, you will get some amount of bytes ready to be sent to somewhere else. And of course, it also enables you to deserialize that pile of bytes into something useful again. Depending on what transport/protocol stack you use, the bytes may be a steream containing binary data, or a file containing some JSON, or a memory buffer containing whatever TProtocol you choose.

The second piece is the infrastructure which allows you to send and receive remote procedure calls (RPC) across any TTransport you can think of. Thrift includes support for Sockets, HTTP, Pipes and some more, depending on the language bindings you plan to use.

Modularity is Key

One of the strongest points about Apache Thrift is modularity. The entire transport/protocol stack I just described is designed as a set of pluggable pieces. This not only allows you to freely combine the existing pieces to e.g. form a socket server that offers three services over one endpoint, communicating via gziped messages in framed compact format. It also enables you to write your own specific TTransport in a very short time frame, if you need it.

Last, not least there are people out there using Apache Thrift to let their applications communicate through MQ systems, either using only the serialization part of Thrift, or writing their own transports and/or protocols. Some samples can be found in the /contrib folder of the source tree.

Do we need a server?

Technically, we don't need one. But since Apache Thrift is also an RPC framework, servers are a core piece of the puzzle. And you know what? It is really handy to have these options available ready for use, instead writing your own TThreadPoolServer or TNonblockingServer from scratch!

Community
  • 1
  • 1
JensG
  • 12,102
  • 4
  • 40
  • 51
  • Thanks a lot for your answer. I learnt a lot from it. I still have one question. For example, if I choose to use TNonblockingServer, it means that Apache Thrift will setup the server for me, is that right? Then, if I am using python and tornado, does that mean that tornado is redundant? or it will lead to conflict? thx – user2547081 Mar 04 '16 at 22:05
  • There are special options for Twisted and Tornado. Try `thrift --help` for more info. I'm no Python expert, so I'm out here :-) -- "*it means that Apache Thrift will setup the server for me*" You still will need to write some glue code. Have a look at the [tutorial](https://thrift.apache.org/tutorial/) and/or the [Thrift Test suite](https://git-wip-us.apache.org/repos/asf?p=thrift.git;a=tree;f=test;h=a2edaf27c4b67cbd6ef7d4a91215cd5a391e42bd;hb=HEAD), this will make things much clearer. – JensG Mar 05 '16 at 00:03