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

Exposing services

Now that we have created a Protocol Buffer service, compiled it to Go, and created an implementation of the server interface, we are ready to spin up a server program that clients can use to invoke the logic in our service implementation.

The mechanism for registering service implementations differs slightly for each target language. The gRPC documentation site’s tutorials provides examples for each of the officially supported languages.

For Go, in addition to the server interface, protoc also generates a registration method that servers use to expose service implementations. Each such method accepts a *grpc.Server and a service implementation. In a given server, only a single implementation of a particular service is allowed. (Attempts to register more than one implementation of the same service interface will result in a panic.)

So let’s pull together this information by writing a Go program that will expose our service implementation. We’ll create...