Difficulty: intermediate
Estimated Time: 15 minutes

IMPORTANT: You need to do the steps in sequence in order for the state of the lesson's learning environment to be consistent. Otherwise, you'll get behaviors that might be confusing.


Objective

The objective of this scenario is to demonstrate how to how to create a gRPC client and server in Go using the protoc executable to auto-generate boilerplate code and then use the autogenerated code within a server and client code also written in Go.

The demonstration is created using the sample code defined in the tutorial published by the gRPC/CNCF found here.

Also, you'l be able to view the auto-generated code in the version of Visual Studio Code that's built directly into the Katacoda interactive learning environment.

Scenario Contents

Here's a listing of the lessons in the scenario.

Lesson 1 - Get protoc executable up and runnning

Lesson 2 - Get the demonstrations gRPC API source code

Lesson 3 - Generate the gRPC message objects in JavaScript using protoc

Lesson 4 - Generate the gRPC message objects in C# using protoc

To proceed, click the Start Scenario button.

You've crossed the finish line!

In this scenario you learned:

  • Get protoc executable up and runnning
  • Install the Go plugin for gRPC
  • Get the example code
  • Generate the server and client code using protoc
  • Run the gRPC server and client

Auto-generating gRPC Code Using protoc and GoLang

Step 1 of 5

Get the protoc executable up and runnning

Objective

The objective of this lesson is to demonstrate how to download protoc binary executable for the GitHub repository and install it on your computer.

protoc is binary executable that is designed to auto-generate boilerplate gRPC code. protoc uses the plugin design pattern. Thus, developers can write an add-in for protoc that will auto-generate code for the given language in a particular way. In this lesson you're going to use protoc with the JavaScript and C# plugins to auto-generate objects that correspond to gRPC messages defined in the lesson's .proto file. The objects will contain the fields of the corresponding gRPC message. Also, each object will contain the logic that serializes and deserializes the object's data into and from the Protocol Buffers binary format.

In this lesson we'll be installing protoc under the Linux operating system. To disover which version of Linux your system is running execute the following command.

uname -a

Steps

Step 1: Create working directory

mkdir protoc

Step 2: Navigate to working directory

cd protoc

Step 3: Download the release zip from GitHub using curl:

curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.12.0-rc2/protoc-3.12.0-rc-2-linux-x86_64.zip

Step 4: Unzip fhe file

unzip protoc-3.12.0-rc-2-linux-x86_64.zip

Step 5: Copy protoc in the system's /bin directory.

cp bin/protoc /bin/protoc

Typically /bin is the environment PATH, thus protoc can be executed from anywhere on the computer.

Step 6: Navigate back to the HOME directory

cd ~