3

我们使用 Apache thrift(在我们的案例中是在 Windows 上)来定义由我们的一个可执行文件公开的多个服务。我们通常最终使用新方法扩展一个服务接口,否则我们将不得不创建新线程(至少一个)来服务新定义的“节俭服务”

有没有办法在 thrift 中使用相同的底层线程来处理多个 thrift 服务定义?

4

1 回答 1

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.

于 2014-06-15T11:39:35.080 回答