All tutorials and documentation suggest that each Thrift server can serve one service (1 handler 1 processor 1 server, all given in constructors etc).
From my point of view (elegance of design) it would be better if many or all services definitions can be independent.
All tutorials and documentation suggest [...]
No, that's not really the case. Docs and tutorials exist to explain stuff, so they naturally focus on the easy cases, just for the sake of simplicity.
But indeed former versions of Thrift did not offer such a feature. Since version 0.9.2 we have Support for Multiplexing Services on any Transport, Protocol and Server widely implemented throughout the codebase.
The usage is very simple. The details depend on the language. This is, for example, a C# client:
TTransport trans;
trans = new TSocket("localhost", 9090);
trans = new TFramedTransport(trans);
trans.Open();
TProtocol Protocol = new TBinaryProtocol(trans, true, true);
TMultiplexedProtocol multiplex;
multiplex = new TMultiplexedProtocol( Protocol, Constants.NAME_BENCHMARKSERVICE);
BenchmarkService.Iface bench = new BenchmarkService.Client( multiplex);
multiplex = new TMultiplexedProtocol( Protocol, Constants.NAME_AGGR);
Aggr.Iface aggr = new Aggr.Client( multiplex);
In this case we have a server offering two services over the same socket, the BenchmarkService
and the Aggr
service. The server part is set up in a similar manner. The whole example can be found in the code base under /lib/csharp/test/Multiplex
.