1

I am trying to integrate a gRPC interface, written in Go by someone else, into my Spring Boot project. From my understanding, the process involves using protoc to convert the .proto file into .java files, which are then copied into the Java project. Afterward, I attempt to create a client and make calls using the following code:

public class MyGrpcClient {
    private final MyServiceGrpc.MyServiceBlockingStub blockingStub;

    public MyGrpcClient() {
        ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 50051)
                .usePlaintext()
                .build();

        blockingStub = MyServiceGrpc.newBlockingStub(channel);
    }

    public MyResponse callRemoteService(MyRequest request) {
        return blockingStub.myMethod(request);
    }
}

However, I noticed that the generated files from protoc do not contain anything similar to the MyServiceGrpc.MyServiceBlockingStub class. I'm wondering where the issue might lie and what could be causing this problem.

I have already followed the necessary steps to generate the .java files using protoc, and I have checked that the necessary dependencies are included in my Maven/Gradle build file. I'm unsure why the MyServiceGrpc.MyServiceBlockingStub class is not present in the generated files.

Any insights or suggestions on how to troubleshoot and resolve this issue would be greatly appreciated.

Thank you in advance for your help!

Zeke Lu
  • 6,349
  • 1
  • 17
  • 23
superDu
  • 67
  • 9
  • Does this answer your question? [GRPC-GO:Client stub not shown in the generated pb.go file](https://stackoverflow.com/questions/60039457/grpc-goclient-stub-not-shown-in-the-generated-pb-go-file) – Jishan Shaikh Jun 10 '23 at 03:19
  • Can you share your protoc setup and proto definition? – Alejandro Lorefice Jun 10 '23 at 17:43
  • 1
    It's confusing but there are 2 steps (and plugins) that you need to use with `protoc` when generating gRPC services. The first (`--java_out`) compiles the messages, the second (`--grpc-java_out`) compiles the protobuf `service` including `rpc` methods. I'm not familiar with Java but you'll need to install [`protoc-gen-grpc-java`](https://github.com/grpc/grpc-java/tree/master/compiler). This is often done using Maven|Gradle but you can install the binary directly, rename it (to `protoc-gen-grpc-java`) and then `protoc --proto_path=${PWD} --java_out=${PWD} --grpc-java_out=${PWD} ${PWD}/*.proto` – DazWilkin Jun 10 '23 at 19:09
  • `protoc` finds plugins by looking for a binary file prefixed `protoc-gen` e.g. `protoc-gen-grpc-java`) and mapping these to flags appending `_out` (and often `_opt`) e.g. `--grpc-java_out` – DazWilkin Jun 10 '23 at 19:11

0 Answers0