問題描述
有沒有辦法優雅地停止 ListenerContainer
及其關聯的 Consumers
.
Is there a way to gracefully stop a ListenerContainer
, and its associated Consumers
.
我正在努力實現的目標.
- 停止使用消息.
- 優雅地停止
ListenerContainer
. - 等待長時間運行的消費者,完成后確認.
我可以使用 consumer.stop()
停止 ListenerContainers
,但活動的長時間運行的消費者不會成功完成,處理的消息也不會acked 并因此將在 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() 有一個本地范圍的列表cancelledConsumers".
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".
推薦答案
增加關機超時時間.
請參閱消息偵聽器容器配置.
關機超時
當容器關閉時(例如,如果其封閉的 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 消費消息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!