Spring JMS Activemq - set dead letter queue-name (DLQ)

吃可爱长大的小学妹 提交于 2020-01-02 04:07:12

问题


We have 3 different projects that are running on the same ACTIVEMQ broker. Currently there is a single "DLQ" queue, we would like to set the dlq for each web application like so:

dlq_webapp1
dlq_webapp2
dlq_webapp3

This way we will have more control on the retry flow. how can we configure it to be like so? here are some of our messaging beans:

    <bean id="redeliveryConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="${activemq_url}" />
    <property name="redeliveryPolicy" ref="redeliveryPolicy" />
    <property name="nonBlockingRedelivery" value="true" />
</bean>

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

<!-- Redelivery: retry after 3sec, 6sec,9sec,12sec,15sec finally put in 
    DLQ -->

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


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

回答1:


I think you need to configure the deadLetterStrategy at the broker. Please refer the examples at - ActiveMQ DLQ

You can choose the individualDeadLetterStrategy which creates a separate DLQ for each queue (depends upon your destination policy). You can have a different prefix for each of your project/application. So that you can have only one consumer per project/application which consumes the DLQ messages from all DLQs starting with the respective prefix (use wildcards while creating consumer).




回答2:


You can go to your Apache ActiveMQ folder. there you will get activemq.xml in /config folder.
add this code in under the <broker> tag in you activemq.xml file

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


来源:https://stackoverflow.com/questions/32296656/spring-jms-activemq-set-dead-letter-queue-name-dlq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!