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.