Client-Streaming gRPC Calls
Explore how client-streaming gRPC calls allow a client to send multiple messages to a server before receiving a single response. Understand the implementation in ASP.NET Core using Protobuf modifications, server-side handling with asynchronous streams, and client code to open, write to, and complete the stream. This lesson helps you build efficient communication for scenarios like IoT data streaming.
We'll cover the following...
Client-streaming calls work by having a client send a stream of messages to the server. Then, when the client closes the stream, the server returns a single object as the response. This functionality is useful in situations where a client would need to send periodic updates to the server. For example, the client might be an IoT device that sends some sensor metrics to the server. Being able to write those into a stream saves bandwidth because we won't have to make a separate request for every metric being sent.
To implement the client-streaming functionality, we have the following code widget, which already contains the code for both the client and server applications.
syntax = "proto3";
option csharp_namespace = "BasicGrpcService";
package basic_grpc_service;
service Chatbot {
rpc SendMessage (ChatRequest) returns (ChatReply);
}
message ChatRequest {
string name = 1;
string message = 2;
}
message ChatReply {
string message = 1;
}
To create an example of a client-streaming RPC we'll ...