Search code examples
spring-bootamazon-sqsspring-kafkagraceful-shutdown

Does adding graceful shutdown to a Spring Boot service stop Kafka and SQS listeners from picking up new requests?


I recently added graceful shutdown to a handful of Spring Boot services (server.shutdown=graceful). These services all have Kafka and SQS listeners in them. Does this property also cause the listeners to stop taking new messages/events, and continue to handle ones in-progress, similar to how it works for HTTP requests? I'm concerned that when a new deployment goes live during the graceful shutdown period of the previous one, there will be multiple instances of the same Kafka/SQS consumers, which may lead to issues.

A few of the services are on Spring Boot 2.3+, so I was able to use the Spring Boot provided configuration in our application profile. But for others, I had to implement something like this.


Solution

  • Well, those listeners work "gracefully" even without such an option. This option applies only for Web server. The listeners you mention are based on containers with SmartLifecycle contract impl. When you stop an application, that contract is called and no more data is pulled from the messaging middleware. However whatever this container has already passed to the processor is still going to be processed.

    It does not mean that you don't need to use that graceful property since the Web server is exactly the status of your application exposed into environment your application is running.