ActiveMQ待处理消息

时间:2019-01-07 12:46:31

标签: java spring jms activemq

我有一个类似于ActiveMQ的问题: http://activemq.2283324.n4.nabble.com/Messages-stuck-in-pending-td4617979.html 并已经尝试过此处发布的解决方案。

有些消息似乎卡在了队列中,甚至可以在那儿呆几天而不被占用。我有足够多的消费者在大多数时间都是免费的,所以这不是消费者“饱和”的问题。

ActiveMQ重新启动时,一些未决消息立即被消耗掉。不久前,我遇到了这样的情况:我有25个免费消费者可排队(在管理面板中可见),其中包含7条“卡死”消息。其中四个立即被消耗掉,但其他三个仍被卡住。另一个奇怪的事情是-新消息不断排入队列并被立即使用,而3条旧消息仍被阻塞。

在消费者方面,我在春季的配置如下:

<jms:listener-container concurrency="${activemq.concurrent.consumers}" prefetch="1">
    <jms:listener destination="queue.request" response-destination="queue.response" ref="requestConsumer" method="onRequest"/>
</jms:listener-container>

<bean id="prefetchPolicy" class="org.apache.activemq.ActiveMQPrefetchPolicy">
        <property name="queuePrefetch" value="1" />
</bean>

<bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
    <property name="brokerURL" value="${activemq.broker.url}?initialReconnectDelay=100&amp;maxReconnectDelay=10000&amp;startupMaxReconnectAttempts=3"/>
    <property name="prefetchPolicy" ref="prefetchPolicy"/>
</bean>

1 个答案:

答案 0 :(得分:1)

The "stuck" messages are probably considered as "in delivery", restarting the broker will close the connections and as the message are yet not acknowledged, the broker considers them as not delivered and will deliver them again.

There may be several problem leading to such a situation, most common ones are a problem in transaction / acknowledgment configuration, bad error / acknowledgment management on consumer side (the message is consumed but never acknowledged) or consumer being stuck on an endless operation (for example a blocking call to a third party resource which doesn't respond and there is no timeout handling).