Grpc:Grpc C++ 客户端和 Grpc java 服务器,异步双向流

Grpc: Grpc C++ client and Grpc java server, asynchronous bidirectional stream

我正在尝试为双向流编写 cpp 客户端 api。

使用以下客户端代码,我可以在服务器上实例化一个 Stream 观察器。然而,问题在于在服务器 StreamObserver 上调用 onNext 函数。

是否有某种协议可以使用 cpp 客户端和 java 服务器进行此调用?

原型文件:

// A client-to-server stream RPC to append data
rpc append(stream ratis.common.RaftClientRequestProto)
  returns (stream ratis.common.RaftClientReplyProto) {}

服务器代码

@Override
public void onNext(RaftClientRequestProto request) {
  try {
    final RaftClientRequest r = ClientProtoUtils.toRaftClientRequest(request);
    LOG.info("recieved request " + r.getCallId());
    final PendingAppend p = new PendingAppend(r);
    slidingWindow.receivedRequest(p, this::processClientRequestAsync);
  } catch (Throwable e) {
    responseError(e, () -> "onNext for " + ClientProtoUtils.toString(request));
  }
}

客户代码

    RaftClientRequestProto req = create_request(read_requet, sizeof(ContainerCommandRequestProto));
    grpc::ClientContext ctx;
    std::shared_ptr<ClientReaderWriter<RaftClientRequestProto, RaftClientReplyProto>> cli_stream(stub->append(&ctx));

    std::thread writer([cli_stream]() {
            RaftClientReplyProto resp;
    std::cout << "goind to read " << std::endl;
    cli_stream->Read(&resp);
    std::cout << "read done" << std::endl;
    });

    std::cout << "Thread started" << std::endl;
    std::this_thread::sleep_for(std::chrono::milliseconds(10000));
    std::cout << "Doing writes" << std::endl;
    cli_stream->Write(req);
    cli_stream->WritesDone();
    std::cout << "writes done" << std::endl;

这个问题是因为 protobuf 版本不同。