依赖
<!--grpc和spring-boot集成框架,包括grpc-server和grpc-client -->
<dependency>
<groupId>net.devh</groupId>
<artifactId>grpc-spring-boot-starter</artifactId>
</dependency>
服务端
配置项
grpc:
server:
port: 0
address:
接口实现类与服务器进行绑定,注解@GrpcService
客户端
配置项
grpc:
server:
port: 0
client:
#这个名称很重要
userservice:
#address: static://localhost:9999
enable-keep-alive: true
keep-alive-without-calls: true
negotiation-type: plaintext
获取stub,注解@GrpcClient
,参数要对应配置
三种类型的stub**newStub**
:Creates a new async stub that supports all call types for the service**newBlockingStub**
: Creates a new blocking-style stub that supports unary and streaming output calls on the service(仅支持简单RPC和服务端流式)**newFutureStub**
:Creates a new ListenableFuture-style stub that supports unary calls on the service
优雅