【问题标题】:Dump apache thrift messages for debugging purposes?转储 apache thrift 消息以进行调试?
【发布时间】:2021-02-24 10:35:46
【问题描述】:

Apache Thrift 是开源 RPC 框架更受欢迎的选择之一(gRPC 也是自发布以来获得大量跟踪的框架)。

在我的 设置中,我使用TMultiplexedProcessor。我想这可能是任何TProcessor,因为我只是对打印发送的任何内容感兴趣。

这有一个方法叫做:

  bool process(std::shared_ptr<protocol::TProtocol> in,
               std::shared_ptr<protocol::TProtocol> out,
               void* connectionContext) override {

我的想法是再次覆盖它,以便我可以打印 in 参数 - 但是我如何将 TProtocol 写入输出? (乍一看,序列化成字符串似乎并不简单)

我感觉可能还有其他或更简单的方法。所以我的问题是如何转储通过 thrift 收到的所有消息(用于调试目的)?

【问题讨论】:

    标签: c++ c++ c++17 rpc thrift thrift-protocol


    【解决方案1】:

    TProtocolTapTDebugProtocol

    用法示例见thrift_dump.cpp:

      shared_ptr<TProtocol> iprot(new TBinaryProtocol(itrans));
      shared_ptr<TProtocol> oprot(
          new TDebugProtocol(
            shared_ptr<TTransport>(new TBufferedTransport(
              shared_ptr<TTransport>(new TFDTransport(STDOUT_FILENO))))));
    
      TProtocolTap tap(iprot, oprot);
    
     std::string name;
          TMessageType messageType;
          int32_t seqid;
          for (;;) {
            tap.readMessageBegin(name, messageType, seqid);
            tap.skip(T_STRUCT);
            tap.readMessageEnd();
          }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-18
      • 1970-01-01
      • 1970-01-01
      • 2015-04-29
      • 1970-01-01
      • 2014-12-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多