添加优雅关闭到Spring Boot服务会阻止Kafka和SQS监听器接收新的请求吗?

huangapple go评论64阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年5月10日 21:52:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76219257.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定