B
B
bova2019-11-06 13:42:36
Java
bova, 2019-11-06 13:42:36

How to add services to gRPC server at startup via Spring Boot?

I started to study GRPC framework based on examples from the Internet.
There was a question about "configuring" the GRPC server when it starts from Spring Boot via the @GRpcService annotation.
More precisely, there is the main Spring Boot class

@SpringBootApplication
public class SpringGrpcApplication {
    public static void main(String args[]) {
        SpringApplication.run(SpringGrpcApplication.class, args);
    }
}

and there is a GRPC service Java class
@GRpcService
public class HelloWorldServiceImpl  extends HelloWorldServiceGrpc.HelloWorldServiceImplBase {
...
@Override
    public void sayHello(Person request, StreamObserver<Greeting> responseObserver) {
...
 responseObserver.onCompleted();
    }
}

When SpringGrpcApplication is launched, a grpc server with a deployed HelloWorldServiceImpl service is automatically created
.
It is clear how to do this if you start the server directly like
Server server = ServerBuilder.forPort(6789).addService(ProtoReflectionService.newInstance()).addService(new HelloWorldServiceImpl()).build();
I would be grateful for any ideas and tips.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question