how to manual control grpc server start or not
sometimes i want to manual start the grpc-server.
There is currently no way to do that directly. But there is one thing that you can do.
Recreate the bean(s) created from https://github.com/yidongnan/grpc-spring-boot-starter/blob/master/grpc-server-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/server/autoconfigure/GrpcServerFactoryAutoConfiguration.java and just omit the server lifecycle. Then you have full control about starting and stopping the server.
Does this answer your question?
Yes, I also hope that I can start it manually. Sometimes my own function has not been initialized yet, but it has been started automatically, which caused me some troubles.
Myabe you can take a look here: https://github.com/yidongnan/grpc-spring-boot-starter/blob/master/grpc-server-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/server/serverfactory/GrpcServerLifecycle.java
/**
* Creates and starts the grpc server.
*
* @throws IOException If the server is unable to bind the port.
*/
protected void createAndStartGrpcServer() throws IOException {
if (this.server == null) {
final Server localServer = this.factory.createServer();
this.server = localServer;
localServer.start();
log.info("gRPC Server started, listening on address: " + this.factory.getAddress() + ", port: "
+ this.factory.getPort());
// Prevent the JVM from shutting down while the server is running
final Thread awaitThread = new Thread(() -> {
try {
localServer.awaitTermination();
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
}
});
awaitThread.setName("grpc-server-container-" + (serverCounter.incrementAndGet()));
awaitThread.setDaemon(false);
awaitThread.start();
}
}
If I have some free time, I will check whether I can turn the autostart off (configurable).