gRPC — The Server

Implementing a gRPC Server in Java

KRISHNA KISHORE V
4 min readDec 28, 2023
Image URL: https://egkatzioura.files.wordpress.com/2021/07/grpc-icon-color.png

In the previous article, we introduced ourselves to the gRPC framework and touched upon what protobufs are. We have also seen a simple .proto file that defines Student objects. In this article, we will take the same proto file, generate Java classes from it and implement a gRPC server in Java.

So, let's jump right in.

Protobuf definitions

Protobuf definitions are just text-based files with the .proto extension. They are also language-neutral, and platform-neutral. With protobufs we define how we want our data structure to be. Then use the protoc tool to compile these .proto files and generate source code, typically as part of the build process. This generated source code is used to write and read our data easily over the wire between client and server.

So both the server and client should have these proto files precompiled and loaded into the memory. We will now see how we can generate the source code from the .proto files using a Java gRPC server.

Java gRPC Server Implementation

As we already mentioned, any language that implements the gRPC server must first get the proto files compiled. This step can be easily integrated into the build script files. In this example…

--

--

KRISHNA KISHORE V

Full Stack Tech Lead | Software Consultant | Technical Content Writer