6

I'm having some trouble generating stubs from my .proto file in GRPC. Here's what the .proto file looks like

`syntax = "proto3";`
// The greeting service definition.
service Greeter {
    // Sends a greeting
    rpc SayHello (HelloRequest) returns (HelloReply) {}
}

// The request message containing the user's name.
message HelloRequest {
    string name = 1;
}

// The response message containing the greetings
message HelloReply {
    string message = 1;
}

The file does generate protocal buffer code, but I'm not getting any service stubs out of it. I.E. I can't use blocking stubs.

I attempted to use the "java_multiple_files=true" fix, but this just splits the generated proto file into a few separate proto files.

I'm currently using the following command prompt line to generate my proto files.

protoc --proto_path= src\proto\protoFile.proto --java_out=src\sourceThings

Let me know if you have any ideas, or need any more information.

Thanks! -DJ

admix
  • 1,752
  • 3
  • 22
  • 27

1 Answers1

8

To get gRPC stubs, you need to tell protoc to use the gRPC plugin, like:

protoc --java_out=src/sourceThings --grpc-java_out=src/sourceThings

You'll need to make sure that the program protoc-gen-grpc-java is in your PATH, or you'll need to specify its location using a flag like:

--plugin=protoc-gen-grpc-java=path/to/protoc-gen-grpc-java

See: https://github.com/grpc/grpc-java/tree/master/compiler

Kenton Varda
  • 41,353
  • 8
  • 121
  • 105
  • Hey kenton, quick question. I used the following gradle import to bring protoc-gen-grpc-java into my program "compile group: 'io.grpc', name: 'protoc-gen-grpc-java', version: '0.15.0'". However, when I run my command line prompt, the system throws the following error: "--grpc-java_out: protoc-gen-grpc-java: The system cannot find the file specified". This is my command line prompt "protoc --java_out=src/sourceStuff --grpc-java_out=src/sourceStuff --proto_path= src\proto\biGuide.proto". Do you have any idea what might be going wrong? –  Jul 26 '16 at 16:26
  • For simplicities sake, here's two gyzaos that show my gradle import and the result of the command line prompt. https://gyazo.com/c5a7ae1cccf2ecd4c8dc25afec1f0ba2 || https://gyazo.com/3460a2bc4b7a3890bb488889e2f390bc –  Jul 26 '16 at 16:32
  • Nevermind, downloaded the plugin directly from here https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22io.grpc%22%20a%3A%22protoc-gen-grpc-java%22 and pointed the command line towards it. If you have any insight on how to do this without a static reference in the command line, I'd love to here it –  Jul 26 '16 at 19:49
  • Yes, for generating stubs, protoc plugin must be set at windows $PATH You can this link for reference. https://gist.github.com/akkida746/e813a015da358cfee27850d6f65a9de6 – Akash5288 Nov 16 '17 at 17:05