Search code examples
c++thrift

How to use our own I/O framework inside a Thrift client?


On the server side, everything is ok.

But on the client side, it seems we cannot just use Thrift to process the protocol, and send/receive the data by using our own I/O framework(such as muduo or other ones).

Is there any way to implement this with C++?


Solution

  • I think this is a legitimate question, and it can be extended to the more general question:

    How do I use other transport mechanisms with Apache Thrift?

    As Hcorg pointed out, because of ist modular structure of the framework, it is not quite hard to achieve that. Basically, one has to follow these steps (this is true for all languages supported by Thrift, not only C++)

    • derive a specialized class from TTransport. In some cases this is an interface, not a base class, but that does not really matter.
    • implement all the methods needed
    • for the server side, you may need a TServerTransport derivative

    The existing implementations may serve as models, and despite the number of methods in TTransport, most of them are not really hard to implement.

    Additionally, I also provided a specialized transport implementation to use STOMP with Delphi, based on a TStreamTransport. The relevant code can be found in the /contrib Folder and is worth a look. You know, one of the nice things about Thrift is that stuff work very similar in all languages.