如何使用@RabbitListener优雅地停止使用消息 [英] How to gracefully stop consuming messages with @RabbitListener

查看:1091
本文介绍了如何使用@RabbitListener优雅地停止使用消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以正常停止ListenerContainer及其关联的Consumers.

Is there a way to gracefully stop a ListenerContainer, and its associated Consumers.

我要实现的目标.

  1. 停止消耗消息.
  2. 优雅地停止ListenerContainer.
  3. 等待长期运行的使用者,并在完成后确认.

我可以使用consumer.stop()停止ListenerContainers,但是活动的长时间运行的使用者不会成功完成,并且处理过的消息也不会得到确认,因此一旦ListenerContainer恢复,就将再次对其进行处理.

I'm able to stop the ListenerContainers using consumer.stop(), but active long running consumers won't complete successfully, and processed messages won't be acked and will therefore be processed again, once the ListenerContainer has been resumed.

输出

Waiting for workers to finish.
Workers not finished.
Closing channel for unresponsive consumer: Consumer@6d229b1c

邮件已处理,但未确认.

The message was processed, but not acked.

我可以使用setForceCloseChannel(false)实现正常关机,但是是否可以验证被取消的使用方是否已完成? SimpleMessageListenerContainer.doShutDown()具有本地范围的列表"canceledConsumers".

I might be able to achieve a graceful shutdown using setForceCloseChannel(false), but is it possible to verify if the cancelled consumers has finished? SimpleMessageListenerContainer.doShutDown() has a local scoped List "canceledConsumers".

推荐答案

增加关闭超时时间.

请参见消息侦听器容器配置.

shutdownTimeout

当容器关闭时(例如,如果关闭了其封闭的ApplicationContext),它将等待处理运行中的消息直至达到此限制.默认为五秒钟.

When a container shuts down (for example, if its enclosing ApplicationContext is closed), it waits for in-flight messages to be processed up to this limit. Defaults to five seconds.

/**
 * 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优雅地停止使用消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆