如何配置 activemq 队列,使其不使用默认的死信队列来处理过期消息

问题描述 投票:0回答:2

我正在尝试实现一种策略,当 activemq 队列中的消息过期时,它们不会被移动到默认的死信队列 ActiveMQ.DLQ,而是会进入另一个死信队列。

我的应用程序使用驼峰上下文进行路由和 bean 定义。我查看了http://activemq.apache.org/message-redelivery-and-dlq-handling.html,我不确定如何实现 individualDeadLetterStrategy。

我想尝试创建一个 Redelivery 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 中

java apache-camel jms activemq
2个回答
1
投票

您提到的页面解释了如何在代理配置中配置DLQ。

例如,从上述页面获取的此配置对代理进行配置,以便名为

MyMessageQueue
的队列的不可传递消息转到
DLQ.MyMessageQueue
,而不是标准的
ActiveMQ.DLQ

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

可能不是很清楚,目的地通配符

queue=">"
表示“所有队列”。有关这些通配符的说明,请参阅此页

由于目标配置是在这些通配符的帮助下完成的,因此建议以允许您使用此类通配符对具有特殊配置需求的目标进行“分组”的方式命名队列和主题。


0
投票
在最新版本的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

© www.soinside.com 2019 - 2024. All rights reserved.