Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

protobuf service can not found in the output file

I define a rpc service in a proto file, but I can not found any interface or method in the output java file.

$ protoc -v 
libprotoc 2.5.0

proto file:

service EchoService {
    rpc Echo (Person) returns (Person);
}

compile script:

#!/bin/bash

for file in `find src/main/proto -name "*.proto"`; do
    protoc --proto_path=src/main/proto --java_out=src/main/java/ $file
done
like image 221
chaopeng Avatar asked Oct 23 '13 03:10

chaopeng


People also ask

How do I create a proto file?

You can use any text editor to create a . proto file. If you'd like to have syntax highlighting there are also editors that would give you that. I use IntelliJ but a quick Google search found an Eclipse plugin which appears to be free: https://code.google.com/p/protobuf-dt/.

What is a service in Protobuf?

Protocol buffers are a mechanism for sending data through the series of tubes known as the Internet. One common use of them is to define gRPC specifications — essentially a form of remote procedure calls. With gRPC service definitions, you create a “service” that has RPC methods.

What is Protobuf file?

Protocol buffers are a combination of the definition language (created in .proto files), the code that the proto compiler generates to interface with data, language-specific runtime libraries, and the serialization format for data that is written to a file (or sent across a network connection).


1 Answers

See the java_generic_services option. You need to add this to your .proto file:

option java_generic_services = true;

However, this is only useful if you have some RPC implementation to use with it (or want to write your own). The option defaults to false because it is expected that most RPC implementations will want to write a custom code generator rather than use the "generic" generated services.

like image 99
Kenton Varda Avatar answered Oct 23 '22 11:10

Kenton Varda