SimpleMessageListenerContainer shutdowntimeout [英] SimpleMessageListenerContainer shutdowntimeout

本文介绍了SimpleMessageListenerContainer shutdowntimeout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用spring-rabbit-1.7.3.RELEASE.jar

I am using spring-rabbit-1.7.3.RELEASE.jar

我已经在我的xml中使用shutdownTimeout参数定义了一个SimpleMessageListenerContainer.

I have defined a SimpleMessageListenerContainer in my xml with shutdownTimeout parameter.

bean id="aContainer"
class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer">
    <property name="connectionFactory" ref="rabbitConnectionFactory" />
    <property name="queueNames" value="aQueue" />
    <property name="adviceChain" ref="retryAdvice" />
    <property name="acknowledgeMode" value="AUTO" />
    <property name="shutdownTimeout" value="900000" />
</bean>

当我的服务关闭并且"aQueue"中仍然有消息时,我希望shutdownTimeout将允许对消息进行处理.但这似乎没有发生.

When my service shuts down and there are still messages in "aQueue", I expect that the shutdownTimeout would allow the messages to get processed. But this doesn't seem to happen.

在进一步调查中,我发现SimpleMessageListenerContainer中定义的await()方法始终返回true.

On further investigation I found out that the await() method defined in SimpleMessageListenerContainer is always returning true.

this.cancellationLock.await(Long.valueOf(this.shutdownTimeout), TimeUnit.MILLISECONDS); 

我想了解用于等待的逻辑如何工作,如何获取锁以及在代码末尾需要进行哪些其他配置才能使代码正常工作.

I would like to understand how the logic for await works, how it acquires lock and what additional configuration is required at my end to make the code work.

推荐答案

它正在等待消费者,那些忙于处理已经获取但尚未确认的消息的消费者.关闭期间,没人会从队列中轮询新消息.

It waits for the consumers on-the-fly, those who are busy to process already fetched but not yet acknowledged messages. Nobody is going to poll fresh messages from the queue during shutdown.

ActiveObjectCounter等待所有内部CountDownLatch被释放.当我们:

The ActiveObjectCounter awaits on the all internal CountDownLatchs to be released. And that happens when we:

public void handleShutdownSignal(String consumerTag, ShutdownSignalException sig) {

因此,这实际上可能是您在shutdownTimeout期间取消并释放了所有使用者(默认为private volatile int concurrentConsumers = 1;)的事实.

So, that really might be a fact that all your consumers (private volatile int concurrentConsumers = 1; by default) are cancelled and released during that shutdownTimeout.

但是再次:当状态为shutdown时,没有机构可以轮询来自Broker的新消息.

But again: no body is going to poll new messages from the Broker when the state is shutdown.

这篇关于SimpleMessageListenerContainer shutdowntimeout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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