gRPC multiple services in cpp async server

1,375 views
Skip to first unread message

AK

unread,
Jan 19, 2017, 1:09:16 PM1/19/17
to grpc.io

I know there is an example helloworld program in gRPC source. However, being new to this, I don't understand how to write more than one async services in the server. The example here talks about spawning new instances of a class to handle SayHello service calls.

  1. How to add new services, for example SayBye, so that I can make calls to it from client?
  2. How to make the server identify which service call was made by the client ?

Vijay Pai

unread,
Jan 26, 2017, 12:41:28 PM1/26/17
to grpc.io
I would suggest, based on your description, that you might just want multiple methods in the same service (which you can do by just declaring multiple different rpc entries in your .proto file). If you need multiple services, though, you can do that just by registering each service one after another. There are examples of this in test/cpp/end2end/hybrid_end2end_test.cc

To know which service call is made, remember that you have to register your calls ahead of time at the server. You can see this in the RequestSayHello line of the example. The last argument of that function is the "tag" that will get posted on the completion queue when this requested method is actually called. So, you will know which method it is by making sure to always post a unique tag for each method call that you are registering at the server.

Regards,
Vijay
Reply all
Reply to author
Forward
0 new messages