英文:
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.
英文:
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.
答案1
得分: 0
以下是翻译好的部分:
"那些监听器即使没有这样的选项也可以“优雅”地工作。这个选项仅适用于 Web 服务器。您提到的监听器基于具有 SmartLifecycle
契约实现的容器。当您停止应用程序时,将调用该契约,并且不再从消息中间件拉取数据。但是,无论这个容器已经传递给处理器的数据仍然会被处理。
这并不意味着您不需要使用 graceful
属性,因为 Web 服务器确切地反映了您的应用程序在运行环境中的状态。"
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论