#Spring boot starter for Google RPC.
Auto-configures and run the embedded gRPC server with @GRpcService-enabled beans as part of spring-boot application.
repositories {
jcenter()
// maven { url "http://oss.jfrog.org/oss-snapshot-local" } //for snashot builds
}
dependencies {
compile('org.lognet:grpc-spring-boot-starter:0.0.2')
}
- Start by generating stub and server interface(s) from your
.proto
file(s). - Annotate your server interface implementation(s) with
@org.lognet.springboot.grpc.GRpcService
- Optionally configure the server port in your
application.yml/properties
. Default port is6565
grpc:
port : 6565
In the 'grpc-spring-boot-starter-demo' project you can find fully functional example with integration test.
The service definition from .proto
file looks like this :
service Greeter {
rpc SayHello ( HelloRequest) returns ( HelloReply) {}
}
Note the generated io.grpc.examples.GreeterGrpc
class with static function bindService
.(The generated classes were intentionally committed for demo purposes).
All you need to do is to annotate your service implementation with @org.lognet.springboot.grpc.GRpcService
@GRpcService(grpcServiceOuterClass = GreeterGrpc.class)
public static class GreeterService implements GreeterGrpc.Greeter{
@Override
public void sayHello(GreeterOuterClass.HelloRequest request, StreamObserver<GreeterOuterClass.HelloReply> responseObserver) {
final GreeterOuterClass.HelloReply.Builder replyBuilder = GreeterOuterClass.HelloReply.newBuilder().setMessage("Hello " + request.getName());
responseObserver.onNext(replyBuilder.build());
responseObserver.onCompleted();
}
}
- Customized gRPC server builder with compression/decompression registry, custom
Executor
service and transport security. ServerInterceptor
support.
Apache 2.0