如何使用@RabbitListener优雅地停止使用消息
有没有一种方法可以优雅地停止ListenerContainer和及其相关联的Consumers。
- 停止使用消息。
- 优雅地停下来ListenerContainer。
- 等待长期运行的消费者,并在完成后确认。
我可以停止ListenerContainers使用consumer.stop(),但是长期运行的使用者不会成功完成,并且一旦ListenerContainer恢复后,已处理的消息也不会被确认,因此将再次进行处理。
Waiting for workers to finish.Workers not finished.
Closing channel for unresponsive consumer: Consumer@6d229b1c
邮件已处理,但未确认。
我也许可以使用来实现正常关机setForceCloseChannel(false),但是是否可以验证被取消的使用者是否已完成?SimpleMessageListenerContainer.doShutDown()具有本地范围的列表“
canceledConsumers”。
回答:
增加关闭超时。
请参阅消息侦听器容器配置。
当容器关闭时(例如,如果关闭了其封闭的ApplicationContext),它将等待处理运行中的消息直至达到此限制。默认为五秒钟。
/** * The time to wait for workers in milliseconds after the container is stopped. If any
 * workers are active when the shutdown signal comes they will be allowed to finish
 * processing as long as they can finish within this timeout. Defaults
 * to 5 seconds.
 * @param shutdownTimeout the shutdown timeout to set
 */
public void setShutdownTimeout(long shutdownTimeout) {
以上是 如何使用@RabbitListener优雅地停止使用消息 的全部内容, 来源链接: utcz.com/qa/419563.html








