一、 安装protobuf插件
IntelliJ IDEA 上操作
image.png
image.png
我的已经安装,所以出现在了Installed tab下
二、代码相关
创建maven项目grpc3
修改pom文件如下
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.qf
grpc3
1.0-SNAPSHOT
io.grpc
grpc-all
1.20.0
kr.motd.maven
os-maven-plugin
1.4.1.Final
org.springframework.boot
spring-boot-maven-plugin
org.xolstice.maven.plugins
protobuf-maven-plugin
com.google.protobuf:protoc:3.0.0:exe:${os.detected.classifier}
grpc-java
io.grpc:protoc-gen-grpc-java:0.15.0:exe:${os.detected.classifier}
compile
compile-custom
创建proto文件
目录:src/main/proto
文件名:helloworld.proto
syntax = "proto3";
option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";
package helloworld;
// 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 {