Spring JMS - 忽略指数消息重新传递策略

时间:2014-05-11 14:45:39

标签: java spring jms activemq spring-jms

我们正在尝试使用spring jms为ActiveMQ设置重新传递策略。我们为重新交付设置了指数回退,但它似乎被忽略了 - 消息重新交付之间的时间间隔是固定的而不是指数增长。

有谁知道可能是什么问题?这是我们的spring-jms配置:

<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"
    p:brokerURL="${activemq_url}">
    <property name="redeliveryPolicy" ref="redeliveryPolicy" />
</bean>

<bean id="redeliveryPolicy" class="org.apache.activemq.RedeliveryPolicy">
    <property name="queue" value="*" />
    <property name="initialRedeliveryDelay" value="10000" />
    <property name="redeliveryDelay" value="10000" />
    <property name="maximumRedeliveries" value="-1" />
    <property name="useExponentialBackOff" value="true" />
    <property name="backOffMultiplier" value="5" />
</bean>

<bean id="cachingConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory" 
    p:targetConnectionFactory-ref="connectionFactory" p:sessionCacheSize="10" 
    />

<!-- A JmsTemplate instance that uses the cached connection and destination -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="cachingConnectionFactory" />
    <property name="messageConverter" ref="messageConverter" />
    <property name="sessionTransacted" value="true" />
</bean>

<!-- The Spring message listener container configuration -->
<jms:listener-container container-type="default"
    destination-type="queue" connection-factory="connectionFactory"
    acknowledge="transacted" concurrency="1" cache="consumer">
    <jms:listener destination="testQueue" ref="testService"
        method="onMessage" />
</jms:listener-container>

谢谢!

编辑:这是一个日志示例,每5秒重新发送一次:

11 May 2014 18:52:00  WARN DefaultMessageListenerContainer - Execution of JMS message listener failed, and no ErrorHandler has been set.
javax.jms.JMSException: Sun May 11 18:52:00 IDT 2014
at ...
11 May 2014 18:52:05  WARN DefaultMessageListenerContainer - Execution of JMS message listener failed, and no ErrorHandler has been set.
javax.jms.JMSException: Sun May 11 18:52:05 IDT 2014
at ...
11 May 2014 18:52:10  WARN DefaultMessageListenerContainer - Execution of JMS message listener failed, and no ErrorHandler has been set.
javax.jms.JMSException: Sun May 11 18:52:10 IDT 2014
at ...
11 May 2014 18:52:15  WARN DefaultMessageListenerContainer - Execution of JMS message listener failed, and no ErrorHandler has been set.
javax.jms.JMSException: Sun May 11 18:52:15 IDT 2014
at ...
11 May 2014 18:52:20  WARN DefaultMessageListenerContainer - Execution of JMS message listener failed, and no ErrorHandler has been set.
javax.jms.JMSException: Sun May 11 18:52:20 IDT 2014
at ...

1 个答案:

答案 0 :(得分:0)

所以,我想我发现了这个问题: 当我之前测试策略时,我抛出了JMSException以获取要重新传递的消息。

我改变了抛出到Exception / RuntimeException的异常,指数退避工作。

我不确定为什么JMSException导致指数退避政策被忽略......有没有人有任何想法?