Camel 如何将ActiveMQ队列配置为不对过期消息使用默认死信队列

fdx2calv  于 9个月前  发布在  Apache
关注(0)|答案(2)|浏览(82)

我正在尝试实现一种策略,当一个ActiveMQ队列中的消息过期时,它们将进入另一个死信队列,而不是移动到默认的死信队列ActiveMQ.DLQ。
我的应用程序使用camel-context进行路由和bean定义。我看过http://activemq.apache.org/message-redelivery-and-dlq-handling.html,我不知道如何实现individualDeadLetterStrategy。
我想尝试创建一个Retrieval Policy bean并将其添加到我的连接工厂,但我在这里没有看到死信策略的属性http://activemq.apache.org/redelivery-policy.html
我也考虑过使用错误处理程序,但我的用例不是错误场景。
我的问题是如何为单个队列配置/指定死信队列。
我已经配置了我的应用程序,使其像下面这样生成队列

<route id="myRoute">
            <from uri="direct:insertToQueue" />
            <doTry>
                <bean ref="processorBean" method="getQueueRequest"/>
                <to uri="activemqProducer:queue:myQueue" />
                <doCatch>
                    <exception>java.lang.Exception</exception>
                    <handled>
                        <constant>true</constant>
                    </handled>
                    <bean method="getExceptionResponse" ref="processorBean" />
                </doCatch>
            </doTry>
        </route>

activemq组件“activemqProducer”的定义如下:

<bean id="activemqProducer" class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="configuration" ref="jmsConfigProducer"/>
    </bean>

    <bean id="jmsConfigProducer" class="org.apache.camel.component.jms.JmsConfiguration" scope="prototype">
        <property name="connectionFactory" ref="jmsFactoryProducer"/>
        <property name="transacted" value="false"/>
        <property name="deliveryPersistent" value="true"/>
        <property name="timeToLive" value="5000"/>
    </bean>

    <bean id="jmsFactoryProducer" class="org.apache.activemq.pool.PooledConnectionFactory"
          init-method="start" destroy-method="stop" scope="prototype">
        <property name="connectionFactory" ref="jmsConnectionFactory" />
        <property name="maxConnections" value="${jms.maximum.connection}" />
        <property name="maximumActiveSessionPerConnection" value="${jms.maximum.active}" />
    </bean>

    <bean id ="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL"><value>${message.broker}</value></property>
        <property name="userName"><value>${message.broker.username}</value></property>
        <property name="password"><value>${message.broker.password}</value></property>
        <property name="optimizeAcknowledge" value="true"/>

        <property name="useAsyncSend" value="true" />
    </bean>

如何为myQueue包含单个死信队列的配置。如果这不可能,那么我如何告诉activemq在myQueue中保留过期的消息呢

eaf3rand

eaf3rand1#

page you mention说明了如何在代理配置中配置DLQ。
例如,从上述页面获取的此配置配置代理,以便名为MyMessageQueue的队列的不可传递消息转到**DLQ.MyMessageQueue,而不是标准的ActiveMQ.DLQ**

<destinationPolicy>
<policyMap>
  <policyEntries>
    <policyEntry queue=">">
      <deadLetterStrategy>
        <individualDeadLetterStrategy queuePrefix="DLQ." useQueueForQueueMessages="true"/>
      </deadLetterStrategy>
    </policyEntry>
  </policyEntries>
</policyMap>
</destinationPolicy>

可能不太清楚的是目的地队列queue=">",这意味着“所有队列”。有关这些通配符的解释,请参见this page
由于目标配置是在这些通配符的帮助下完成的,因此建议您**以一种允许您使用此类通配符将具有特殊配置需求的目标“分组”的方式来命名队列和主题。

2o7dmzc5

2o7dmzc52#

在最新版本的ActiveMQ(例如Artemis)中,有一种方法可以定义不同的过期地址(取决于队列名称上的正则表达式):

<address-setting match="com.company.demo.MyQueue">
   <expiry-address>com.company.demo.EXP.MyQueue</expiry-address>
</address-setting>

更多信息:https://activemq.apache.org/artemis/docs/latest/message-expiry.html

相关问题