Auto configuring and run the embedded gRPC server with @GrpcService-enabled beans as part of spring-boot application.
Support Spring Cloud(registe services to consul or eureka and fetch gRPC server information)
Support Spring Sleuth to trace application
Support global and customer gRPC server/client interceptors
2.x.x.RELEASE support Spring Cloud Finchley.
The latest version: 2.0.1.RELEASE
1.x.x.RELEASE support Spring Cloud Edgware 、Dalston、Camden.
The latest version: 1.4.1.RELEASE
To add a dependency using Maven, use the following:
<dependency>
<groupId>net.devh</groupId>
<artifactId>grpc-server-spring-boot-starter</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
To add a dependency using Gradle:
dependencies {
compile 'net.devh:grpc-server-spring-boot-starter:2.0.1.RELEASE'
}
Annotate your server interface implementation(s) with @GrpcService
@GrpcService(GreeterGrpc.class)
public class GrpcServerService extends GreeterGrpc.GreeterImplBase {
@Override
public void sayHello(HelloRequest req, StreamObserver<HelloReply> responseObserver) {
HelloReply reply = HelloReply.newBuilder().setMessage("Hello ====> " + req.getName()).build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
}
}
To add a dependency using Maven, use the following:
<dependency>
<groupId>net.devh</groupId>
<artifactId>grpc-client-spring-boot-starter</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
To add a dependency using Gradle:
dependencies {
compile 'net.devh:grpc-client-spring-boot-starter:2.0.1.RELEASE'
}
Use @GrpcClient("gRPC server name")
annotation or grpcChannelFactory.createChannel("gRPC server name")
to get Channel
@GrpcClient("gRPC server name")
private Channel serverChannel;
set gRPC host and port in application.properties, default host is 0.0.0.0 and default port is 9090
grpc.server.port=9090
grpc.server.address=0.0.0.0
gRPC request
GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(serverChannel);
HelloReply response = stub.sayHello(HelloRequest.newBuilder().setName(name).build());
set gRPC server host and port in application.properties, default host is [127.0.0.1] and default port is [9090]
grpc.client.(gRPC server name).host[0]=
grpc.client.(gRPC server name).port[0]=
https://github.com/yidongnan/grpc-spring-boot-starter/tree/master/examples