0
votes

I am trying to write a cpp client for a bi-directional stream api.

With the following client code, I am able to instantiate a Stream observer on the server. However the problem is with the invocation of the onNext function on the Server StreamObserver.

Is there a certain protocol to make this call using a cpp client and java server ?

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;
1

1 Answers

-1
votes

This issue was because of difference in protobuf version.