项目使用maven构建,执行mvn compile 命令后,proto文件自动生成java文件,这个功能需要依赖相关编译插件。
一、pom.xml配置
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.test.grpcTest
grpc-api
0.0.1-SNAPSHOT
jar``
grpc-api
UTF-8
io.grpc
grpc-netty
1.0.0
io.grpc
grpc-protobuf
1.0.0
io.grpc
grpc-stub
1.0.0
io.grpc
grpc-all
0.13.2
kr.motd.maven
os-maven-plugin
1.4.1.Final
org.xolstice.maven.plugins
protobuf-maven-plugin
0.5.0
com.google.protobuf:protoc:3.0.0:exe:${os.detected.classifier}
grpc-java
io.grpc:protoc-gen-grpc-java:1.0.0:exe:${os.detected.classifier}
compile
compile-custom
二、proto文档(IDL文档)编辑和编译成java文件
//指定proto3格式
syntax = "proto3";
//一些生成代码的设置
option java_multiple_files = false;//以非外部类模式生成
option java_package = "com.test.grpcTest.grpc_api";//所在包名
option java_outer_classname = "Grpc";//最外层类名称
message UnaryRequest{
string serviceName = 1;
string methodName = 2;
bytes data = 3;
string request_id = 4;//参数默认都为可选&#