3

We use Apache thrift (on Windows on our case) for defining multiple services exposed by one of our executable. We usually end up extending one service interface with new methods because otherwise we would have to create new threads (at lest one) to service the new defined "thrift service"

Is there a way to handle multiple thrift service definitions using the same underlying threads in thrift ?

Ghita
  • 4,465
  • 4
  • 42
  • 69
  • 1
    Possible duplicate of http://stackoverflow.com/questions/6905737/id-like-to-use-multiple-services-on-one-transport-thrift/16071414#16071414 and http://stackoverflow.com/questions/19614648/service-multiplexing-using-apache-thrift – JensG Jun 15 '14 at 11:49

1 Answers1

1

Starting with 0.9.x, Thrift supports a multiplexing protocol for some languages. Several implementations have been added since then for the remaining languages.

As usual, the path to follow is very similar. You add the TMultiplexedProtocol on both sides to your transport stack. There are also a few examples in the code base.

There are a few implications that come with this:

  • Since TMultiplexedProtocol is an layered protocol, all services share the same endpoint protocol (e.g. binary) and transport (e.g. sockets). In most cases this is exactly what you want. If you need different transports or endpoint protocols, you still have to set up different services.

  • Replacing a server by a multiplexed server is theoretically possible, although not fully implemented for all languages yet, see below. The details can be found in THRIFT-1915.

Regarding compatibility: The new multiplexing uses a delimiter char. The existing code could be modified in such a way, where there is a default service (which would be the old, unmultiplexed service) which gets called whenever no delimiter is found in the name. If the default is null or empty, the code behaves as in the actual solution.

If you need this comparingly simple modification for your language(s) of choice and want to provide a patch, we will gladly review and integrate it.

JensG
  • 13,148
  • 4
  • 45
  • 55