CHAPTER 9Advanced gRPC Applications

In the first half of this chapter, you will learn how to implement streaming communication patterns in gRPC applications. In the latter half, you will learn to implement common server and client functionality as middleware components. Along the way, you will learn how to send and receive binary data and understand more about Protocol Buffers. Let's jump in!

Streaming Communication

As you learned in Chapter 8, data is exchanged between client and server as protobuf messages. You learned to build gRPC applications following the Unary RPC pattern. In this pattern, a client sends a request to the server and then waits for the server to send back a response. More specifically, the client application calls an RPC method, sends a request as a protobuf message, and then waits for the response message from the server. There is only one message exchange that happens between the client and the server.

Next, we are going to learn three new communication patterns: server-side streaming, client-side streaming, and a combination of the two, bidirectional streaming. In these three patterns, it is possible to exchange more than one request and response message during a single method call. Let's learn about these, starting with server-side streaming.

Server-Side Streaming

In server-side streaming, when a client makes a request, the server may send more than one response message. Consider the GetRepos( ) RPC method of the Repo service that we implemented ...

Get Practical Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.