Chapter 2. Getting Started with gRPC
Enough with the theory on gRPC; let’s apply what you learned in Chapter 1 to build a real-world gRPC application from the ground up. In this chapter, you will use both Go and Java to build a simple gRPC service and a client application that invokes the service you developed. In the process you’ll learn about specifying a gRPC service definition using protocol buffers, generating a server skeleton and client stub, implementing a service’s business logic, running a gRPC server with the service you implemented, and invoking the service through the gRPC client application.
Let’s use the same online retail system from Chapter 1, where we need to build a service that is responsible for managing the products of a retail store. The service can be remotely accessed and the consumers of that service can add new products to the system and also retrieve product details from the system by providing the product ID. We’ll model this service and consumer using gRPC. You may pick the programming language of your choice to implement this, but in this chapter, we will use both the Go and Java languages to implement this sample.
You can try out both the Go and Java implementations of the sample in the source code repository for this book.
In Figure 2-1, we illustrate the client–server communication patterns of the
for each method invocation. The server hosts a gRPC service that offers two remote methods: