Asynchronous Basics question

57 views
Skip to first unread message

John Coffey

unread,
Jun 13, 2017, 2:32:16 PM6/13/17
to grpc.io
I have a general question about using the Asynchronous APIs.  I basically want to write a client that listens for updates as they are received by the server.  

On the server side, there seem to be multiple ways to define this in the proto file, and I am not sure which one I should use.   Looking at the examples greeters applications, it looks like one of these streams the replies while the other does not.  This is a bit confusing as the introduction of the 'stream' keyword does not prevent async communications.  Could someone explain the difference.  

Previously, I developed a grpc service using Stream responses using the Synchronous API, and I could basically have my client wait in a separate thread for the individual responses to get received.   In this case I had do do quite a bit of thread management on the server and the client which (if I am not mistaken) I may be able to simplify if I use a truly asynchronous API.

Below you can see the 2 types of rpc definitions in the proto files I mentioned above.

// The greeting service definition.

service
MultiGreeter {
 
// Sends multiple greetings
  rpc sayHello
(HelloRequest) returns (stream HelloReply) {}
}

This is the streaming version

// The greeting service definition.
service
Greeter {
 
// Sends a greeting
  rpc
SayHello (HelloRequest) returns (HelloReply) {}
}

Non Streaming version

Yang Gao

unread,
Jun 16, 2017, 5:14:25 PM6/16/17
to John Coffey, grpc.io
stream is part of your API definition while sync/async is about implementation.

You should decide whether to have "stream" according to whether you can have more than one reply messages.
As you said, whether to use async or sync implementation is about your resource limitations. If you have a server with a large number of pending streams, you should consider async implementation.
If your client wants to listen to many servers for the update, you may want to use async as well.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/7087cd4b-930f-4766-b040-68f73269dbf4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages