activemq死信队列

       DLQ-死信队列(Dead Letter Queue)用来保存处理失败或者过期的消息。

出现以下情况时,消息会被redelivered:

 A transacted session is used and rollback() is called.

 A transacted session is closed before commit is called.

 A session is using CLIENT_ACKNOWLEDGE and Session.recover() is called.

当一个消息被redelivered超过maximumRedeliveries(缺省为6次,具体设置请参考后面的链接)次数时,会给broker发送一个"Poison ack",这个消息被认为是a poison pill,这时broker会将这个消息发送到DLQ,以便后续处理。

缺省的死信队列是ActiveMQ.DLQ,如果没有特别指定,死信都会被发送到这个队列。

缺省持久消息过期,会被送到DLQ,非持久消息不会送到DLQ可以通过配置文件(activemq.xml)来调整死信发送策略。

 

activemq.xml配置

       添加相应的配置到xml文件中。

<destinationPolicy>

            <policyMap>

              <policyEntries>

                <policyEntry queue=">">

                        <deadLetterStrategy>

                                <individualDeadLetterStrategy queuePrefix="DLQ." useQueueForQueueMessages="true"/>

                        </deadLetterStrategy>

                </policyEntry>

                <policyEntry topic=">" >

                    <!-- The constantPendingMessageLimitStrategy is used to prevent

                         slow topic consumers to block producers and affect other consumers

                         by limiting the number of messages that are retained

                         For more information, see:

 

                         http://activemq.apache.org/slow-consumer-handling.html

 

                    -->

                  <pendingMessageLimitStrategy>

                    <constantPendingMessageLimitStrategy limit="1000"/>

                  </pendingMessageLimitStrategy>

                </policyEntry>

              </policyEntries>

            </policyMap>

        </destinationPolicy>

 

测试

       通过测试死信队列三种情况的一种,到浏览器查验。

 

posted on 2018-12-13 17:29  纸菠萝  阅读(344)  评论(0编辑  收藏  举报