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)来调整死信发送策略。
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.html
individualDeadLetterStrategy属性说明:
http://fusesource.com/docs/broker/5.3/configref/http.activemq.apache.or/element/individualdeadletterstr.html
sharedDeadLetterStrategy属性说明:
http://fusesource.com/docs/broker/5.3/configref/http.activemq.apache.or/element/shareddeadletterstrateg.html
redelivery属性说明:
http://activemq.apache.org/redelivery-policy.html
分享到:
相关推荐
springboot整合 activeMq 消费者 消费接收消息 包含队列模式点对点发 以及 主题模式一对多 这是消费者的demo consumer 。 里面有消息重发机制,手动确认ACK模式。 配合 producer 生产者demo使用。
ActiveMQ队列消息过期时间设置和自动清除解决方案.docx
springboot整合activeMq的使用,队列,主题,消息手动确认,重发机制
详细描述了ActiveMQ消息过期-时间设置和自动清除解决方案。
activemq消息中间件-视频教程activemq消息中间件-视频教程activemq消息中间件-视频教程activemq消息中间件-视频教程
ActiveMQ 消息队列
ActiveMQ消息队列主题订阅Spring整合
SpringBoot快速玩转ActiveMQ消息队列,jdk8下的简要版介绍。
可用于调试MSMQ、RabbitMQ、ActiveMQ三种消息队列 其中MSMQ支持Active、Binary、XML格式(要勾选事务) RabbitMQ支持逐条接发、批量接发、RPC回调模式、新建队列、建立持久化队列、连接测试等功能。
用C#实现的ActiveMQ发布/订阅消息传送源程序
1.什么是 ActiveMQ 2. ActiveMQ 服务器宕机怎么办 3. 丢消息怎么办 4. 持久化消息非常慢 5. 消息的不均匀消费 6. 死信队列 7.
主要对ActiveMQ消息中间件的使用,以及面试结合项目问到的问题;
activemq消息持久化所需Jar包,详情请参见博文:http://blog.csdn.net/l1028386804/article/details/68997105
activeMQ的测试工具,用于发送和接收activeMQ消息,jar包形式的,安装完jdk之后用java -jar xxx.jar命令运行
"ActiveMQ5.13 安装与配置" ActiveMQ 是 Apache 软件基金会提供的一个开源message broker,能够实现点对点(Point-to-Point)和发布/订阅(Publish/Subscribe)模式的消息传递。ActiveMQ 5.13 是 ActiveMQ 的一个...
1.ActiveMQ消息队列中间件 1.1.什么是ActiveMQ ActiveMQ 是Apache出品,最流行的,能力强劲的开源消息总线。ActiveMQ 是一个完全支持JMS1.1和J2EE 1.4规范的 JMS Provider实现,尽管JMS规范出台已经是很久的事情了,...
SpringBoot+ActiveMq+MQTT实现消息的发送和接收 后台消费者、生产者、消息发送接口、发送消息业务类等相关配置
springboot集成activemq实现消息接收demo
ActiveMQ消息中间件面试专题
SpringBoot整合ActiveMQ消息队列和双向队列、点对点与发布订阅,可以参考我的博客文章进行学习https://blog.csdn.net/sujin_/article/details/82956386