Server streaming
The first method of streaming we’ll look at is server streaming. Server streaming is when the client sends a single request to the server, and the server responds with zero or more messages as part of a single RPC response. A typical scenario might be performing a query that can return many results.
To illustrate this, let’s look at an example of a service that defines a method for searching a database. Clients will send in a search term and an optional maximum number of results to be returned.
We start by making a new folder in $GOPATH/src/practical_grpc called streaming. We’ll need a few directories to be created first, since protoc
won’t create them for you.
You can run the following to get started:
mkdir -p$GOPATH
/src/practical_grpc/streamingcd
$GOPATH
/src/practical_grpc/streaming mkdir -p ./{
proto,server/proto,database/proto}
Creating the protobuf file
Create a new file at proto/database.proto with the following content.
Protocol...