Hi Vijay,

Thanks a lot for the comments.
So I will implement option 1, probably in a separate thread with the sync 
API.

Julien


Le vendredi 2 juin 2017 18:14:34 UTC+2, Julien a écrit :
>
> Hello,
>
> I have a server with several clients. From time to time, the server must 
> send a notification to some clients.
> I can’t find a proper way to do this. I had 2 different solutions to do 
> that:
>
> 1.  Create an RPC function which returns a stream of notifications.
> Something like:
> rpc GetNotification(google.protobuf.Empty) returns (stream Notification) 
> {}
>
> The client would call this function “permanently” in a dedicated thread 
> with the async interface:
> stub->AsyncGetNotification(...)
> ...
> while (!stopped) {
>   nextStatus = completionQueue.AsyncNext(...);
>   if (nextStatus == grpc::CompletionQueue::GOT_EVENT) {
>     // handle the notification
>     ...
>   }
> }
>
> On the server side, the GetNotification function would just write the 
> notification when there is no notification to send, and would do nothing 
> the rest of the time.
> But this means that there would be as many GetNotification functions 
> executed at the same time as there are connected clients. I don’t expect to 
> have much clients running at the same time (let’s say ~10-20), but I don’t 
> like that much.
>
> 2.  Create a simple RPC function which returns a notification:
> rpc GetNotification(google.protobuf.Empty) returns (Notification) {}
>
> The client would call it periodically (let’s say every 5 seconds) and 
> would handle the notification if there is one, and would do nothing if 
> there is none.
> On the server side, the GetNotification function would return an empty 
> notification if there is none, or the notification with the appropriate 
> data when needed.
> I don’t like this solution much because it is not really efficient.
>
> Is there a better solution than the two above ones?
> Otherwise, which one is the best?
>
> Thanks.
>
> Julien
>
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
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/7dd29228-cb9a-4c2c-93c5-2c63c35498b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to