是否可以在没有 RPC 的情况下使用 Apache Thrift?

是否可以在没有 RPC 的情况下使用 Apache Thrift?

问题描述:

我在互联网上搜索,但找不到任何有用的信息.首先,我正在考虑使用 Protocol Buffers,但它没有提供内置功能来跟踪多条消息(一条消息完成,第二条消息开始)或消息自定界,但我在 Thrift 白皮书中阅读了此功能,看起来不错对我来说.现在我正在考虑使用 Thrift 而不是 Protocol Buffers.

I searched on the internet but couldn't find anything useful. First, I was thinking to use Protocol Buffers but it doesn't provide built in feature to track multiple messages (where one message finish and second starts) or message self delimiting, but I read about this feature in Thrift white paper and it seems good to me. Now I am thinking to use Thrift instead of Protocol Buffers.

我正在开发不需要 RPC 的自定义协议,有人可以建议我是否可以在没有 RPC 的情况下使用 Thrift(就像它在 Protocol Buffers 中一样,只需使用流函数)和一些起点作为 thrift 文档有点麻烦.

I am working on custom protocol for that I don't require RPC, could someone suggest if I can use Thrift without RPC (as its in the Protocol Buffers, one simply use the streams function) and some starting point as thrift documentation is a bit cumbersome.

谢谢!

Apache Thrift 确实是一个RPC 和序列化框架.序列化部分用作 RPC 机制的一部分,但可以独立使用.对于各种语言,有可用的示例和/或支持帮助程序类.如果您的特定语言不是这种情况,则必要的代码几乎可以归结为(伪代码):

Apache Thrift is indeed a RPC- and serialization framework. The serialization part is used as part of the RPC mechanism, but can be used standalone. For the various languages there are samples and/or supporting helper classes available. If this is not the case for your particular language, the necessary code pretty much boils down to this (pseudo code):

var data = InitializeMyDataStructure(...);

var trans = new TStreamTransport(...);
var prot = new TJSONProtocol(trans);

data.write(prot);

传输和协议都是可插入的,因此您可以使用自己的协议和(例如)文件传输代替 JSON 和流.或者任何其他对您的用例有意义且受您的目标语言支持的组合.

Both transport(s) and protocol are pluggable, so instead JSON and a stream you are free to use your own protocol, and (for example) a file transport. Or whatever else combination makes sense for your use case and is supported for your target language.

因为 thrift 文档有点麻烦.

as thrift documentation is a bit cumbersome.

您可以自由提出任何问题,无论是在这里还是在邮件列表中.此外,我们有一个很好的教程,测试服务器/客户端对也是典型用例的好例子.

You are free to ask any question, be it here or in the mailing list. Furthermore, we have a nice tutorial and the Test server/client pairs are also good examples for typical use cases.