在以下三种情况中,ActiveMQ消息会被重发给客户端/消费者:
1.使用一个事务session,并且调用了rollback()方法;
2.一个事务session,关闭之前调用了commit;
3.在session中使用CLIENT_ACKNOWLEDGE签收模式,并且调用了Session.recover()方法。
Broker根据自己的规则,通过BrokerInfo命令包和客户端建立连接,向客户端传送缺省发送策略。但是客户端可以使用ActiveMQConnection.getRedeliveryPolicy()方法覆盖override这个策略设置。
RedeliveryPolicy policy = connection.getRedeliveryPolicy();
policy.setInitialRedeliveryDelay(500);
policy.setBackOffMultiplier(2);
policy.setUseExponentialBackOff(true);
policy.setMaximumRedeliveries(2);
一旦消息重发尝试超过重发策略中配置的maximumRedeliveries(缺省为6次)时,会给broker发送一个"Poison ack",通知它,这个消息被认为是一个毒丸(a poison pill),接着broker会将这个消息发送到DLQ(Dead Letter Queue),以便后续分析处理。
缺省死信队列(Dead Letter Queue)叫做ActiveMQ.DLQ;所有的未送达消息都会被发送到这个队列,以致会非常难于管理。你可以设置activemq.xml文件中的destination policy map的"individualDeadLetterStrategy"属性来修改.
<broker...>
<destinationPolicy>
<policyMap>
<policyEntries>
<!-- Set the following policy on all queues using the '>' wildcard -->
<policyEntry queue=">">
<deadLetterStrategy>
<!--
Use the prefix 'DLQ.' for the destination name, and make
the DLQ a queue rather than a topic
-->
<individualDeadLetterStrategy
queuePrefix="DLQ." useQueueForQueueMessages="true" />
</deadLetterStrategy>
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
...
</broker>
自动丢弃过期消息(Expired Messages)
一些应用可能只是简单的丢弃过期消息,而不想将它们放到DLQ中,完全跳过了DLQ。在dead letter strategy死信策略上配置processExpired属性为false,可以实现这个功能。
<broker...>
<destinationPolicy>
<policyMap>
<policyEntries>
<!-- Set the following policy on all queues using the '>' wildcard -->
<policyEntry queue=">">
<!--
Tell the dead letter strategy not to process expired messages
so that they will just be discarded instead of being sent to
the DLQ
-->
<deadLetterStrategy>
<sharedDeadLetterStrategy processExpired="false" />
</deadLetterStrategy>
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
...
</broker>
将非持久消息(non-persistent messages)放入死信队列
ActiveMQ缺省不会将未发到的非持久消息放入死信队列。如果一个应用程序并不想将消息message设置为持久的,那么记录下来那些未发送到的消息对它来说往往也是没有价值的。不过如果想实现这个功能,可以在dead-letter strategy死信策略上设置processNonPersistent="true"
<broker...>
<destinationPolicy>
<policyMap>
<policyEntries>
<!-- Set the following policy on all queues using the '>' wildcard -->
<policyEntry queue=">">
<!--
Tell the dead letter strategy to also place non-persisted messages
onto the dead-letter queue if they can't be delivered.
-->
<deadLetterStrategy>
<sharedDeadLetterStrategy processNonPersistent="true" />
</deadLetterStrategy>
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
...
</broker>
分享到:
相关推荐
springboot整合 activeMq 消费者 消费接收消息 包含队列模式点对点发 以及 主题模式一对多 这是消费者的demo consumer 。 里面有消息重发机制,手动确认ACK模式。 配合 producer 生产者demo使用。
详细描述了ActiveMQ消息过期-时间设置和自动清除解决方案。
springboot整合activeMq的使用,队列,主题,消息手动确认,重发机制
ActiveMQ队列消息过期时间设置和自动清除解决方案.docx
ActiveMQ消息队列主题订阅Spring整合
activemq消息中间件-视频教程activemq消息中间件-视频教程activemq消息中间件-视频教程activemq消息中间件-视频教程
ActiveMQ 消息队列
用C#实现的ActiveMQ发布/订阅消息传送源程序
SpringBoot+ActiveMq+MQTT实现消息的发送和接收 后台消费者、生产者、消息发送接口、发送消息业务类等相关配置
SpringBoot快速玩转ActiveMQ消息队列,jdk8下的简要版介绍。
可用于调试MSMQ、RabbitMQ、ActiveMQ三种消息队列 其中MSMQ支持Active、Binary、XML格式(要勾选事务) RabbitMQ支持逐条接发、批量接发、RPC回调模式、新建队列、建立持久化队列、连接测试等功能。
activeMQ的测试工具,用于发送和接收activeMQ消息,jar包形式的,安装完jdk之后用java -jar xxx.jar命令运行
主要对ActiveMQ消息中间件的使用,以及面试结合项目问到的问题;
1.ActiveMQ消息队列中间件 1.1.什么是ActiveMQ ActiveMQ 是Apache出品,最流行的,能力强劲的开源消息总线。...CXF和Axis支持,以便ActiveMQ可以轻松地放入这些Web服务堆栈中以提供可靠的消息传递。
ActiveMQ高并发处理方案ActiveMQ高并发处理方案 超级字数补丁超级字数补丁
activemq消息持久化所需Jar包,详情请参见博文:http://blog.csdn.net/l1028386804/article/details/68997105
SpringBoot整合ActiveMQ消息队列和双向队列、点对点与发布订阅,可以参考我的博客文章进行学习https://blog.csdn.net/sujin_/article/details/82956386
activemq消息中间件的使用demo,以及spring集合jms实现消息发送和处理。
springboot集成activemq实现消息接收demo
ActiveMQ(包括消息生成端和andorid消息接受端),实现了点对点的消息推送,和广播消息推送,当然离线推送也实现了。