Creating and using stubs
At this point in this chapter, we have a server that exposes a service implementation. Now we focus on the client side. Before a client can send RPCs to the server, it must first establish a connection to the server and then create a stub, whose methods are invoked to send RPCs to the server.
The mechanism for creating a gRPC client, establishing a connection to a server, and instantiating stubs differs from one target language to another. The gRPC documentation site’s tutorials provides examples for each of the officially supported languages.
The examples below will show the steps for building a Ruby client. At the end, we’ll have a Ruby client that is issuing RPCs to our Go server, demonstrating the interoperability across languages.
Before we start writing Ruby code, we’ll first generate the Ruby code from our proto
source file. Ruby code generation for messages and enums is built into a protoc
, so no
plugin is needed. We will need a plugin...