简体   繁体   中英

Difference between proto package and java_package in gRPC proto file?

I am a beginner to gRPC. .proto file has package and option java_package fields. As per my understanding, java_pacakge is a more sophisticated field to put the generated code. My question is do we need to define pacakge if we already defined java_package? Second question is, I'm enabling retry through service config. In retry config file service name should be pkg.ServiceName, so if I don't have package defined, can I simply ignore package name and just define service name in retry config?

Do we need to define package if we already defined java_package?

Absolutely. package is the wire-level namespacing used for gRPC methods and for messages included in Anys. It would also be used for non-Java languages.

You should always have package , and often you will have java_package . The main reason for both is that Java uses reverse DNS for its namespacing whereas protobuf does not. For example, google.rpc is a protobuf package, but com.google.rpc would be the equivalent Java package, to follow the normal conventions.

In retry config file service name should be pkg.ServiceName, so if I don't have package defined, can I simply ignore package name?

Yes, you would simply have ServiceName because there is no package. However, that means your service could collide with anyone else that also chooses not to have a package. Not having a package is possible, but is discouraged in the same way not having a Java package is possible but discouraged.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM