gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 03:52:03 27 4
gpt4 key购买 nike

我们正在尝试使用 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 ...

最佳答案

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

我将抛​​出的异常更改为 Exception/RuntimeException,指数回退起作用了。

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

关于java - Spring JMS - 指数消息重新传递策略被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23593980/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com