Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement a generic Thrift Proxy?

Tags:

rpc

thrift

In Apache Thrift is it possible to create a generic proxy? For e.g. in proxy I want to do request/response logging or measure performance. The flow should be like Client <-> Generic Proxy <-> Server for all RPC calls.

like image 769
Arun Gopalpuri Avatar asked Apr 20 '26 20:04

Arun Gopalpuri


1 Answers

Implement an custom Thrift "layered" protocol or a custom Thrift transport which intercepts your calls as needed.

A lot of languages have adopted the multiplexed protocol which uses a generic TProtocolDecorator. That piece of code looks quite handy for that task. Look at the implementation of TMultiplexedProtocol to see how it's used. Basically the TProtocolDecorator class does most of the magic, you only need to override some methods and plug your newly developed protocol into the Thrift transport/protocol stack as usual.

Alternatively, your goal could be achieved by adding a layered transport, similar to TBufferedTransport. But in that case you do not have the semantics behind the data, you only see strings whereas at the protocol level you have methods like WriteMessageBegin or ReadMessageBegin which make live much easier.

like image 174
JensG Avatar answered Apr 23 '26 10:04

JensG