Creating a semi event-based behavior using gRPC

41 views
Skip to first unread message

afshi...@gmail.com

unread,
May 11, 2020, 11:03:41 AM5/11/20
to grpc.io

Hi

I have a special requirement for my application that I need to notify my client application from some changes in server side. I'm using gRPC for transferring my data from server to client and I was thinking for a workaround for my problem.
I thought maybe I could postpone sending my gRPC response to when my data is ready. So my application could simulate a semi event-based with following pseudo-code:
  1. Client calls getData() rpc call.
  2. Server checks if any data is available. if data is available go to 4.
  3. Wait for data to become available.
  4. Send data to client.
  5. Client process received data and goes to step 1.
  6. If connection is broken, Client goes to step 1.
In this way, whenever any data is ready on server, it will be sent to client. But I wonder if this approach is correct and feasible? Assuming that data may be ready after hours we may keep a connection open between client and server. Is there any better way to do what I need?

Best regards

ravi....@gmail.com

unread,
May 11, 2020, 2:05:41 PM5/11/20
to grpc.io
The scenario you have described is more suited to Pub/Sub implementation. Maybe you can consider building your solution around a message broker, wherein the updates of data change(whenever happens) is published on the message queue and the client can read the updates as and when it comes. But if for some reason, you want to do the same in gRPC, you can have async streaming based RPC to ship out changes. But you need to be careful of the pitfalls of long running RPCs for e.g. for channel management gRPC may decide to end a connection due to various reasons. Also, your client application won't be notified of the broken connection until it actually uses the channel to send something   which I doubt your application would be doing as it would be waiting to consume change messages only

afshi...@gmail.com

unread,
May 12, 2020, 4:58:35 AM5/12/20
to grpc.io
I have been thinking about using a queue providers (like 0MQ), but I prefer not to add too many different models to project at same time if possible.
Why you say that client will not notice the connection is broken unless it actually uses channel to send something? if I have a used ClientAsyncReader (or ClientAsyncResponseReader) to read from channel and connection is broken, CompletionQueue::Next() should get tag with ok==false, isn't it? So I should be able to find out that connection is broken without sending anything on it.
Finally, is starting new rpc call has a high burden or gRPC server/client? I ask this because I want to know if trying to pull new data from client side every new seconds is a bad idea or not.

Thanks a lot for your time.
Reply all
Reply to author
Forward
0 new messages