問(wèn)題描述
有沒(méi)有辦法優(yōu)雅地停止 ListenerContainer
及其關(guān)聯(lián)的 Consumers
.
Is there a way to gracefully stop a ListenerContainer
, and its associated Consumers
.
我正在努力實(shí)現(xiàn)的目標(biāo).
- 停止使用消息.
- 優(yōu)雅地停止
ListenerContainer
. - 等待長(zhǎng)時(shí)間運(yùn)行的消費(fèi)者,完成后確認(rèn).
我可以使用 consumer.stop()
停止 ListenerContainers
,但活動(dòng)的長(zhǎng)時(shí)間運(yùn)行的消費(fèi)者不會(huì)成功完成,處理的消息也不會(huì)acked 并因此將在 ListenerContainer 恢復(fù)后再次處理.
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
消息已處理,但未確認(rèn).
The message was processed, but not acked.
我或許可以使用 setForceCloseChannel(false)
實(shí)現(xiàn)正常關(guān)閉,但是否可以驗(yàn)證取消的消費(fèi)者是否已完成?SimpleMessageListenerContainer.doShutDown() 有一個(gè)本地范圍的列表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".
推薦答案
增加關(guān)機(jī)超時(shí)時(shí)間.
請(qǐng)參閱消息偵聽器容器配置.
關(guān)機(jī)超時(shí)
當(dāng)容器關(guān)閉時(shí)(例如,如果其封閉的 ApplicationContext 已關(guān)閉),它會(huì)等待處理中的消息,直至達(dá)到此限制.默認(rèn)為五秒.
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) {
這篇關(guān)于如何優(yōu)雅地停止使用@RabbitListener 消費(fèi)消息的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!