The structure of the generated Java gRPC classes

This project contains a basic gRPC service:

The project can generate the Java classes according to the .proto files defined in the project, and here is the class diagram of the greeting related classes together with generated classes:

From the above class diagram, there are several notes:

In addition, the handwritten GreetingServerImpl class extends the GreetingServiceGrpc.GreetingServiceImplBase inner class:

package greeting.server;

import com.proto.greeting.GreetingRequest;
import com.proto.greeting.GreetingResponse;
import com.proto.greeting.GreetingServiceGrpc;
import io.grpc.stub.StreamObserver;

public class GreetingServerImpl extends GreetingServiceGrpc.GreetingServiceImplBase {

    public void greet(GreetingRequest request, StreamObserver<GreetingResponse> responseObserver) {
                .setResult("Hello : "+request.getFirstName()).build());

And the GreetingServer uses the GreetingServerImpl:

package greeting.server;

import io.grpc.Server;
import io.grpc.ServerBuilder;


public class GreetingServer {
    public static void main(String[] args) throws IOException, InterruptedException {
        int port = 50052;

        Server server = ServerBuilder.forPort(port)
                .addService(new GreetingServerImpl())

        System.out.println("Server started");
        System.out.println("Listing on port : "+ port);

        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            System.out.println("Received Shutdown Request");
            System.out.println("Server Stopped");


Above is the structure of the generated Java gRPC classes.


My Github Page:

Powered by Jekyll and Theme by solid

If you have any question want to ask or find bugs regarding with my blog posts, please report it here: