gRPC: How to Make Server Streaming Calls

Yair Fernando
Level Up Coding
Published in
4 min readJan 25, 2021

--

In this article, I’ll cover a gRPC call using Server Streaming response— implementing a client and server Go applications.

This is the third article of the series:

  1. How to Make Effective Unary Calls
  2. How to Make Client Streaming Calls
  3. How to Make Server Streaming Calls
  4. How to Make Bi-directional Streaming Calls

In a server streaming rpc call, the client sends a single request, and the server responds with a stream of messages. This is useful when the server needs to do bulks operations, and instead of waiting until the server finishes processing the data, the server can send objects one by one using streaming.

Server Streaming Response

Project Description

For this project, we will create a Documents service with one gRPC endpoint that will allow the client to send a request to fetch documents.

The endpoint will not require any request message, so we will send an empty hash.

The server then will process some documents and start sending streaming responses to the client.

The client can also stop accepting messages from the server at any point in time, either because it already got what it wanted, or because the server is taking too long to send messages.

Let’s create another folder inside the grpc_calls, and call it server_stream.

Inside this folder create the following structure.

gRPC Server Stream Folder Structure

The definition of the documents.proto file is the following:

In this proto file I defined the service documents, the endpoint, and the…

--

--