Kasun Kariyawasam
Kasun Kariyawasam

Reputation: 2447

Hosting multiple netty servers for grpc inside a tomcat server, application redeploy issue

I am developing a microservice application and deploy them in single tomcat server. So I am not using spring boot. I am using just spring.

Let's say we have applications call master-data and common-service When I deploy them in tomcat I can access them via port 8080. But I wanted them to transfer to grpc communication endpoints. Then I had to install grpc libries and netty for each modules. Now I can access their grpc endpoint in ports 6565 and 7575.

I used spring bean @PostConstruct annotation and separately run the grpc servers in separate ports (6565 and 7575). Now It works fine.

But when I add new changes to master-data and redeploy it in tomcat without shuting down the tomcat, It will gives me java.net.BindException: Address already in use and when I run ps -ef | grep netty in terminal I could see there are processes still tuning on.

It seems like grpc server is not properly shut down because of tomcat is not shutting down.

Can anybody give me a proper solution ?

Upvotes: 2

Views: 1377

Answers (1)

Eric G
Eric G

Reputation: 4058

gRPC Java servers need to be shutdown by invoking their shutdown() method. I don't have much (any) knowledge about integrating gRPC Java with Tomcat/Spring, but there's no built-in integration on the gRPC side so you will need to ensure the gRPC servers are receiving a programmatic shutdown() signal somehow.

The grpc-java-contrib repository contains additional utilities for working with gRPC Java, including with Spring. In particular, it sounds like GrpcServerHost might be helpful for managing a server's lifecycle in a Spring environment.

Upvotes: 1

Related Questions