How to implement multi rpc call in defined in one service?

34 views
Skip to first unread message

xh757...@gmail.com

unread,
Sep 7, 2018, 12:15:39 AM9/7/18
to grpc.io
I do know this seems weird. Here is the sample definition of protobuf:

service Sample {
  rpc Get (GetRequest) returns (GetResponse) {}
  rpc Set (SetRequest) returns (SetResponse) {}
}
message GetRequest{...}
message GetResponse{...}
message SetRequest{...}
message SetResponse{...}

What I'm doing is to implement these services on the server end using async api.
I learned the basic usage from the helloworld greeter_async_server.cc, which defined
    HelloRequest request_;
    HelloReply reply_;
And call RequestSayHello using the ONLY request and reply required in the ONLY rpc call
    service_->RequestSayHello(&ctx_, &request_, &responder_, cq_, cq_, this);

I guess I might try to define all the messages in my "CallData" class like
class SampleCallData{
public:
   ...
private:
  GetRequest gRequest;
  GetResponse gRsp;
  SetRequest sRequest;
  SetResponse sRsp;
}

I'm not sure if my question is clear enough.
Here is what I wonder:
1. Will this kind of implementation work?(To implement all the rpc call defined in protobuf file)
2. Is there another way to do better?(I know I can define multi services)
3. If this will work, how does grpc bind the indeed request and response with rpc call?(In details, in the handleRpc() func, new SampleCallData() is called while it won't pass any value of request)

New to here, thanks a lot.


xh757...@gmail.com

unread,
Sep 9, 2018, 11:51:57 PM9/9/18
to grpc.io
I found similar definition in route_guide sample protobuf file, while the C++ implementation used sync api which is easy to understand. How could it be if we use async way?

在 2018年9月7日星期五 UTC+8下午12:15:39,xh757...@gmail.com写道:
Reply all
Reply to author
Forward
0 new messages