[英]Grpc: Grpc C++ client and Grpc java server, asynchronous bidirectional stream
I am trying to write a cpp client for a bi-directional stream api. 我正在尝试为双向流api编写cpp客户端。
With the following client code, I am able to instantiate a Stream observer on the server. 使用以下客户端代码,我可以在服务器上实例化Stream观察器。 However the problem is with the invocation of the onNext function on the Server StreamObserver.
但是,问题在于在服务器StreamObserver上调用onNext函数。
Is there a certain protocol to make this call using a cpp client and java server ? 是否有某种协议可以使用cpp客户端和java服务器进行此调用?
Proto file: 原始文件:
// A client-to-server stream RPC to append data
rpc append(stream ratis.common.RaftClientRequestProto)
returns (stream ratis.common.RaftClientReplyProto) {}
Server code 服务器代码
@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));
}
}
Client code 客户代码
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版本不同而引起的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.