如何实现通用的 Thrift 代理? [英] How to implement a generic Thrift Proxy?

查看:51
本文介绍了如何实现通用的 Thrift 代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Apache Thrift 中是否可以创建通用代理?例如在代理中,我想做请求/响应日志记录或测量性能.流程应该类似于客户端 <-> 通用代理 <-> 所有 RPC 调用的服务器.

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.

推荐答案

实施自定义 Thrift分层"协议或自定义 Thrift 传输,以根据需要拦截您的调用.

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

许多语言都采用了多路复用协议,它使用了一个通用的TProtocolDecorator.这段代码对于该任务看起来非常方便.看TMultiplexedProtocol的实现 看看它是如何使用的.基本上 TProtocolDecorator 类完成了大部分的魔法,你只需要像往常一样覆盖一些方法并将你新开发的协议插入到 Thrift 传输/协议堆栈中.

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.

或者,您的目标可以通过添加分层传输来实现,类似于 TBufferedTransport.但是在这种情况下,您没有数据背后的语义,您只能看到字符串,而在协议级别,您有诸如 WriteMessageBeginReadMessageBegin 之类的方法,它们使生活变得更加容易.

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.

这篇关于如何实现通用的 Thrift 代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆