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

Client streaming

Client streaming is the opposite of server streaming. In client streaming RPCs, the client sends multiple messages to the server, which in turn sends back a single response. The response is typically returned after receiving all of the client messages, but that isn’t a hard requirement.

To get a better understanding of client streaming, let’s take a look at another example application. This time we’ll create a service that accepts a set of files. Once the client has sent all of its files, the service will return a zip file containing all of the files that were received.

Creating the protobuf file

As we did in the server streaming example, let’s start with the protobuf definition in proto/archiver.proto.

Protocol Buffer

syntax = "proto3";

package practical.grpc.v1;

service Archiver {
  rpc Zip(stream ZipRequest) returns (ZipResponse);
}

message ZipRequest {
  string file_name = 1;
  bytes contents   = 2;
}

message ZipResponse...