activeMQ死消息队列的管理
2011-09-23 16:01
363 查看
DLQ-死信队列(Dead LetterQueue)用来保存处理失败或者过期的消息。出现以下情况时,消息会被redeliveredA 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() iscalled.当一个消息被redelivered超过maximumRedeliveries(缺省为6次,具体设置请参考后面的链接)次数时,会给broker发送一个"Poisonack",这个消息被认为是a poison pill,这时broker会将这个消息发送到DLQ,以便后续处理。缺省的死信队列是ActiveMQ.DLQ,如果没有特别指定,死信都会被发送到这个队列。缺省持久消息过期,会被送到DLQ,非持久消息不会送到DLQ可以通过配置文件(activemq.xml)来调整死信发送策略。1. 不使用缺省的死信队列
缺省所有队列的死信消息都被发送到同一个缺省死信队列,不便于管理。可以通过individualDeadLetterStrategy或sharedDeadLetterStrategy策略来进行修改。如下:
<broker...>
<destinationPolicy>
<policyMap>
<policyEntries>
<!— 设置所有队列,使用 '>' ,否则用队列名称 -->
<policyEntry queue=">">
<deadLetterStrategy>
<!--
queuePrefix:设置死信队列前缀
useQueueForQueueMessages: 设置使用队列保存死信,还可以设置useQueueForTopicMessages,使用Topic来保存死信
-->
<individualDeadLetterStrategy queuePrefix="DLQ." useQueueForQueueMessages="true" />
</deadLetterStrategy>
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
...
</broker>2. 非持久消息保存到死信队列
<policyEntry queue=">">
<deadLetterStrategy>
<sharedDeadLetterStrategy processNonPersistent="true" />
</deadLetterStrategy>
</policyEntry>3. 过期消息不保存到死信队列
<policyEntry queue=">">
<deadLetterStrategy>
<sharedDeadLetterStrategy processExpired="false" />
</deadLetterStrategy>
</policyEntry>4. 持久消息不保存到死信队列
对于过期的,可以通过processExpired属性来控制,对于redelivered的失败的消息,需要通过插件来实现如下:
丢弃所有死信
<beans>
<broker ...>
<plugins>
<discardingDLQBrokerPlugin dropAll="true" dropTemporaryTopics="true" dropTemporaryQueues="true" />
</plugins>
</broker>
</beans>
丢弃指定目的死信
<beans>
<broker ...>
<plugins>
<discardingDLQBrokerPlugin dropOnly="MY.EXAMPLE.TOPIC.29 MY.EXAMPLE.QUEUE.87" reportInterval="1000" />
</plugins>
</broker>
</beans>
注意,目的名称使用空格分隔
The reportInterval property is used to denote how frequently do we output how many messages we have dropped - use 0 to disable.
用正则表达式过滤丢弃消息:
<beans>
<broker ...>
<plugins>
<discardingDLQBrokerPlugin dropOnly="MY.EXAMPLE.TOPIC.[0-9]{3} MY.EXAMPLE.QUEUE.[0-9]{3}" reportInterval="3000" />
</plugins>
</broker>
</beans>
Notice that the destination names use regular expressions. These match the number 000..999 at the end of each destination name.5. 死信队列消息的属性死信队列中的消息,会增加几个属性,比如原过期时间(originalExpiration),原originalDeliveryMode等参考:DLQ处理说明:http://activemq.apache.org/message-redelivery-and-dlq-handling.htmlindividualDeadLetterStrategy属性说明:http://fusesource.com/docs/broker/5.3/configref/http.activemq.apache.or/element/individualdeadletterstr.htmlsharedDeadLetterStrategy属性说明:http://fusesource.com/docs/broker/5.3/configref/http.activemq.apache.or/element/shareddeadletterstrateg.htmlredelivery属性说明:http://activemq.apache.org/redelivery-policy.html
相关文章推荐
- ActiveMQ消息队列获取每个队列中的消费者数、剩余消息数、已消费数、队列名等信息 示例
- ActiveMQ消息队列介绍
- Java消息队列-activemq集群与配置
- (十三)RabbitMQ消息队列-VirtualHost与权限管理
- Spring和ActiveMQ集成实现队列消息以及PUB/SUB模型
- ActiveMQ消息队列的使用及应用
- ActiveMQ消息队列和spring进行整合实例
- activemq 支持mysql持久化 消息队列使用
- ActiveMQ消息队列的使用及应用
- ActiveMQ实现延迟消息队列
- 工业物联网或系统集成中应用消息队列(ActiveMQ,C#的demo)的场景全面分析
- ActiveMQ消息队列
- Java消息队列-Spring整合ActiveMq
- activemq 队列消息定时清理
- 深入浅出 消息队列 ActiveMQ
- 下载安装ActiveMQ(消息队列)
- 一、消息队列之ActiveMQ的安装、配置和C#样例代码
- activeMQ的高级特性之messageGroup,一个队列多个消息消费者
- 消息队列开发记录笔记-ActiveMQ
- ActiveMQ消息队列详解