Reading streams from the server
A server-streaming gRPC call is the opposite of the client-streaming one. The client sends a singular object in its request. This is what will trigger the server stream to open. While the stream is open, multiple response objects can be sent to the client.
Server streaming is frequently used to retrieve a collection of items from a server. This is what we will use it for in the following example.
Adding a server-streaming RPC to Protobuf
First, we will add a server-streaming rpc to the Protobuf definition. In the following example, we will use an empty request object, which is one of the so-called well-known types that we will cover in Chapter 8, Using Well-Known Types to Make Protobuf More Handy:
- Add the following
import
statement above the package directive in thedevice_management.proto
file in theGrpcDependencies
project:import "google/protobuf/empty.proto";
- Then, add the following
rpc
definition to theDeviceManager...