Keeping a client-streaming RPC open and sending messages (often times this
would semantically be "notifications") to the server as they become
available (=not immediately)  is one of the main use cases of client-side
streaming and it's definitely a legitimate use case.
Whenever using long-lived streaming RPC, you there are some additional
concerns you need to be aware of. I highly recommend this talk
https://www.youtube.com/watch?v=Naonb2XD_2Q

On Wed, Jun 26, 2019 at 10:59 AM Sam <[email protected]> wrote:

> Hi all,
>
> I’m using gRPC’s client-side streaming functionality (C#) to send many
> messages to a server. Most examples I can see on the web show a certain
> amount of messages sent and then read a reply. Like the *SumExample* in
> C#:
>
> using (var call = client.Sum())
> {
>     await call.RequestStream.WriteAllAsync(numbers);
>     Console.WriteLine("Sum Result: " + await call.ResponseAsync);
> }
>
>
> I use the client-side streaming in a slightly different way: a long lived
> stream to the server. I have multiple threads sending to the server and I
> use it like this:
>
> I have a *Connection* class that wraps the gRPC client, the
> implementation goes something like this:
>
> public class Connection
> {
>    private readonly IClientStreamWriter<Request> _clientSideStream;
>
>    public Connection(RequestService.RequestServiceClient client)
>    {
>        // get a reference to the stream
>        _clientSideStream = client.TransactionExchangeClientStream().
> RequestStream;
>    }
>
>     // called a lot by multiple threads
>    public async Task SendAsync(Request request)
>    {
>        await _clientSideStream.WriteAsync(request);
>    }
>
>
>     // when the app decides to stop talking entirely to the server
>     public async Task CloseConnection()
>     {
>        await _clientSideStream.CompleteAsync().ConfigureAwait
> <http://clientsidestream.completeasync%28%29.configureawait/>(false);
>     }
> }
>
>
> I keep a reference to *IClientStreamWriter* so that I can *WriteAsync* to
> it. After some time (potentially days, maybe more) the application might
> need to close the connection. Note that for now, I actually don’t event
> care about the response.
>
> Is this valid use of client-side streaming ? Anything I should be careful
> about ?
>
> Sam
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/grpc-io/613fea5a-fe51-40b5-a69f-cbf82190b797%40googlegroups.com
> <https://groups.google.com/d/msgid/grpc-io/613fea5a-fe51-40b5-a69f-cbf82190b797%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 

Jan

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/CACF4M0RaehrjZJ5oeTMhyjrHM20iF6E-%3Dqk6h7LrOiRYkczamg%40mail.gmail.com.

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to