java - 未应用 ActiveMQ 5.7.0 redeliveryPolicy

标签 java spring jms activemq

我正在使用 ActiveMQ 5.7.0 并尝试实现重新交付策略。我有两个队列需要为其设置重新传递策略。但是在测试中,它不适用我的策略。它没有遵循下面的配置,而是以 1 秒的间隔重试 7 次(不是我指定的)。

  <!--  ActiveMQ destinations to use  -->
  <amq:queue id="destinationOne" physicalName="${activemq.one.queuename}">
    <amq:properties>
        <amq:redeliveryPolicy destination="One.DLQ" maximumRedeliveries="5" initialRedeliveryDelay="300000" useExponentialBackOff="true" backOffMultiplier="2" maximumRedeliveryDelay="3600000"/>
    </amq:properties>
  </amq:queue>
  <amq:queue id="destinationTwo" physicalName="${activemq.two.queuename}">
    <amq:properties>
        <amq:redeliveryPolicy destination="Two.DLQ" maximumRedeliveries="5" initialRedeliveryDelay="300000" useExponentialBackOff="true" backOffMultiplier="2" maximumRedeliveryDelay="3600000"/>
    </amq:properties>
  </amq:queue>

我定义了两个监听器,它们正在应用如下队列:
  <bean id="oneMessageListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="connectionFactory" ref="jmsConnectionFactory"/>
    <property name="destination" ref="destinationOne"/>
    <property name="messageListener" ref="jmsOneListener" />
    <property name="autoStartup" value="false" />    
    <property name="sessionTransacted" value="true"/>
    <property name="concurrentConsumers" value="2" />
  </bean>
  <bean id="twoMessageListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="connectionFactory" ref="jmsConnectionFactory"/>
    <property name="destination" ref="destinationTwo"/>
    <property name="messageListener" ref="jmsTwoListener" />
    <property name="autoStartup" value="false" />    
    <property name="sessionTransacted" value="true"/>
    <property name="concurrentConsumers" value="2" />
  </bean>

最佳答案

我同意 Tim 的回答:策略是在底层连接工厂对象上定义的。对于您的场景,我认为您需要定义 2 个单独的 ActiveMQ 连接工厂,并使用自己的策略,然后为每个连接工厂定义一个单独的 Spring 连接工厂,然后正确使用

这是我之前在 ActiveMQ v5.5 上使用的示例:

<bean id="rawConnectionFactory1" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="${broker.url}" />
    <property name="redeliveryPolicy" ref="policy1" />
    <property name="useCompression" value="true" />
</bean>
<bean id="rawConnectionFactory2" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="${broker.url}" />
    <property name="redeliveryPolicy" ref="policy2" />
    <property name="useCompression" value="true" />
</bean>


<bean id="policy1" class="org.apache.activemq.RedeliveryPolicy">
    <property name="initialRedeliveryDelay" value="20000" />
    <property name="useExponentialBackOff" value="false" />
    <property name="useCollisionAvoidance" value="false" />
    <property name="maximumRedeliveries" value="0" />
</bean>
<bean id="policy2" class="org.apache.activemq.RedeliveryPolicy">
    <property name="initialRedeliveryDelay" value="60000" />
    <property name="useExponentialBackOff" value="false" />
    <property name="useCollisionAvoidance" value="false" />
    <property name="maximumRedeliveries" value="5" />
</bean>


<bean id="connectionFactory1" class="org.springframework.jms.connection.CachingConnectionFactory">
    <property name="targetConnectionFactory" ref="rawConnectionFactory1" />
    <property name="sessionCacheSize" value="30" />
</bean>
<bean id="connectionFactory2" class="org.springframework.jms.connection.CachingConnectionFactory">
    <property name="targetConnectionFactory" ref="rawConnectionFactory2" />
    <property name="sessionCacheSize" value="10" />
</bean>

关于java - 未应用 ActiveMQ 5.7.0 redeliveryPolicy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13847606/

相关文章:

java - 掌握 web.xml 在所有 webapp 项目中使用

java - 在不检查异常的情况下查找我们是否在线程绑定(bind)请求中的安全方法

java - 为什么 Spring Integration 管理配置默认不起作用?

jms - 配置 JMS (ActiveMQ) 队列,使其仅包含最后一条消息

java - 在文本字段中使用 if/else 吗?

java - 删除此 java 代码重复项

Java为什么接口(interface)扩展接口(interface)

java - 延迟初始化: failed to lazily initialize a collection

java - 哪种类型的 Spring 集成 channel ?

java - HornetQ 与 Artemis ActiveMQ 转移