using grpc for push notification

14,438 views
Skip to first unread message

Chaitanya Gangwar

unread,
Jan 22, 2016, 3:28:18 PM1/22/16
to grpc.io
Hi,

I have a requirement, where  multiple clients send (register) a request to server and continue, whenever server have data, server will push the data to clients. it may be possible that server may not have data at present and will keep pushing data whenever it has. Some other thread is providing the data to server.

Can i do this with grpc without blocking the server and client. What i understand from grpc streaming is that client will be waiting for data till server sends out the data and after receiving the data it closes the connection.

please help, if i can do this using grpc and if yes how should i design this.

thanks
Chaitanya

Josh Humphries

unread,
Jan 22, 2016, 3:32:37 PM1/22/16
to Chaitanya Gangwar, grpc.io
This is a straight-forward streaming-response style endpoint in GRPC. (Use the "stream" keyword for the response when defining this method in a proto source file.)

The client doesn't necessarily "wait for" data. It receives it asynchronously. A streaming response means that the server can send zero or more messages in reply to the request.

The RPC can remain active for the entire duration that the client is connected, and the server can use the response stream (once initiated by a client -- via the initial request) to send data, as it comes in.





----
Josh Humphries
Manager, Shared Systems  |  Platform Engineering
Atlanta, GA  |  678-400-4867

--
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+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/e37958cb-ef5b-4cfe-83f6-2bc5aec28ee0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Chaitanya Gangwar

unread,
Jan 22, 2016, 3:51:19 PM1/22/16
to grpc.io
Thanks josh for the reply. So for this case i need both async server and client. sync rpc will not work. please correct me if i am wrong. also do we have any example which i can look into. i checked async helloworld but that is simple rpc do we have any example for async stream rpc.

Josh Humphries

unread,
Jan 22, 2016, 4:53:42 PM1/22/16
to Chaitanya Gangwar, grpc.io
There is an example of streaming, at least in a proto file:
In this case, the server is expected to just immediately send the requested number of messages.


Assuming you had some "registry" of streams that represent clients to which you forward data:

In your server implementation, you'd just register the StreamObserver (that's what its called in the Java runtime anyway).

(That's the interface you implement on the server.)

When your server receives data from whatever other source, it can consult this registry of streams and then call onNext to send the client(s) data. Unregister when the stream errors or when you close the stream. You close it via calling onComplete or onError (latter will send error code to the client).



----
Josh Humphries
Manager, Shared Systems  |  Platform Engineering
Atlanta, GA  |  678-400-4867

--
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+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.

John Coffey

unread,
Jun 14, 2017, 3:08:46 PM6/14/17
to grpc.io, chaitany...@gmail.com, j...@squareup.com
Josh/Chaitanya, I have a similar application - are there any C++ examples that do this kind of thing?  I just posted a new question to the newsgroup asking and then I found this thread.

John

chaitanya gangwar

unread,
Jun 15, 2017, 12:55:10 AM6/15/17
to John Coffey, grpc.io, j...@squareup.com
Hi John,

When i was working on this, there was no example in grpc package to do the same. Actually, what you need here is asynchronous streaming, but in examples, there are 2 variant, one is synchronous stream (routeguide) and normal async rpc (helloworld). You have to understand both the examples and need to implement async stream yourself. I may have some poc code with me where i tested this functionality. Ill check my repo and will post it to you. May be that will be of some help for you.

Thanks
Chaitanya

You received this message because you are subscribed to a topic in the Google Groups "grpc.io" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grpc-io/FKeg4yfB-Jo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to grpc-io+unsubscribe@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.

John Coffey

unread,
Jun 15, 2017, 9:09:22 AM6/15/17
to grpc.io, joh...@gmail.com, j...@squareup.com
Chaitanya, 

that would be really useful, thanks, I will look forward to seeing the code.  It is strange that gRPC does not have asynchronous stream support, you would think this kind of listener/observe pattern would be a pretty popular feature.

John
To unsubscribe from this group and all its topics, send an email to grpc-io+u...@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.

chaitanya gangwar

unread,
Jun 15, 2017, 11:54:52 AM6/15/17
to John Coffey, grpc.io, j...@squareup.com
Hi John,

I have added 2 variant of routeguide example, one for asyn stream with one rpc and other for async stream multiple rpc. You can take a look at the code. this was working with grpc 0_11 version. This will give you a good idea of how to use grpc for asyn stream.

https://drive.google.com/open?id=0B1MMqYKUHgtJQWN4cjB6U25LdTQ

Thanks
Chaitanya

To unsubscribe from this group and all its topics, 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.
Message has been deleted

pira...@gmail.com

unread,
Aug 16, 2017, 11:21:46 AM8/16/17
to grpc.io, joh...@gmail.com, j...@squareup.com
Hi Chaitanya,

Thank you for you sharing! Can you provide the .proto file with it? It's hard to understand without the .proto file, and I can't change the code and recompile it. 

Thanks
Sean

chaitanya gangwar

unread,
Aug 16, 2017, 11:33:38 AM8/16/17
to pira...@gmail.com, grpc.io, John Coffey, j...@squareup.com
proto file is in same folder under proto directory.

To unsubscribe from this group and all its topics, 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.

pira...@gmail.com

unread,
Aug 16, 2017, 11:51:18 AM8/16/17
to grpc.io






Hi Chaitanya,

There are two rar files inside the share, I can't find proto directory or files in both of them. please help me.

Thanks
Sean


chaitanya gangwar

unread,
Aug 16, 2017, 12:23:56 PM8/16/17
to pira...@gmail.com, grpc.io
Oh i think i missed the grpc proto file. But its the same as present in git repository example folder. This code is modification of example present in grpc source. You just need to make a small change, add "stream" keyword in return argument.

https://github.com/grpc/grpc/blob/master/examples/protos/route_guide.proto

-Chaitanya

To unsubscribe from this group and all its topics, 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.

pira...@gmail.com

unread,
Aug 16, 2017, 12:36:49 PM8/16/17
to grpc.io, pira...@gmail.com
Get it! Thank you for your help. You are wonderful.
 

rav...@gmail.com

unread,
Nov 29, 2017, 4:33:00 PM11/29/17
to grpc.io
Hi Chaitanya,

Could you please share async stream code? 
The link seem to be broken now.

thanks.
Message has been deleted

mscud...@googlemail.com

unread,
Mar 16, 2018, 11:17:05 AM3/16/18
to grpc.io
Could you please repost the examples of th c++ async route guide demos,
Would be very helpful.

Thanks, Marco.

Chaitanya Gangwar

unread,
Mar 16, 2018, 12:45:31 PM3/16/18
to grpc.io

Hi All,

Previous files got deleted somehow. I am uploading it again. Please use this link :

https://drive.google.com/file/d/1jqviARRz5muVCdsBjw3WPH8xSSGpXrv1/view?usp=sharing

Thanks
Chaitanya
Message has been deleted

jonatha...@gmail.com

unread,
Sep 10, 2018, 2:04:01 PM9/10/18
to grpc.io
Hello everyone,

would anyone have an example in C#/.NET Core?

Thanks,

Jonathan
Reply all
Reply to author
Forward
0 new messages