Book Image

Practical gRPC

By : Joshua B. Humphries, David Konsumer, David Muto, Robert Ross, Carles Sistare
Book Image

Practical gRPC

By: Joshua B. Humphries, David Konsumer, David Muto, Robert Ross, Carles Sistare

Overview of this book

While building systems that contain several components, you need a framework that is fast and has minimal network overhead. gRPC is one such open-source tool that is quickly becoming popular and gaining popularity with programmers. Practical gRPC introduces you to gRPC and explains how it compares and contrasts with similar technologies. You’ll be introduced to key technologies such as Protocol Buffers, and work your way up from basic gRPC usage, all the way through to its more advanced capabilities. You’ll learn the best practices for defining and evolving your gRPC APIs, and discover how different tools can be leveraged to get the most out of gRPC and even extend it. By the end of this book, you'll have all the information you need to get started building systems with gRPC.
Table of Contents (13 chapters)
11
11. Extending gRPC services

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/streaming
cd $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...