ActiveMQ(5.10.0) - Message Redelivery and DLQ Handling
When messages expire on the ActiveMQ broker (they exceed their time-to-live, if set) or can’t be redelivered, they’re moved to a dead-letter queue, so they can be consumed or browsed by an administrator at a later point.
Messages are redelivered to a client when any of the following occurs:
- 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.
- A client connection times out (perhaps the code being executed takes longer than the configured time-out period)
A client application usually has a good reason to roll back a transacted session or call recover() —it may not be able to complete the processing of the message(s) because of its inability to negotiate with a third-party resource, for example. But sometimes an application may decide to not accept delivery of a message because the message is poorly formatted. For such a scenario, it doesn’t make sense for the ActiveMQ broker to attempt redelivery forever.
A configurable POJO is associated with the ActiveMQ connection that you can tune to set different policies. You can configure the amount of time the ActiveMQ broker should wait before trying to resend the message, whether that time should increase after every failed attempt (use an exponential back-off and back-off multiplier), and the maximum number of redelivery attempts before the message(s) are moved to a dead-letter queue.
The broker transmits the default delivery policy that he prefers to a client connection in his BrokerInfo command packet. But the client can override the policy settings by using the ActiveMQConnection.getRedeliveryPolicy() method:
RedeliveryPolicy policy = connection.getRedeliveryPolicy();
policy.setInitialRedeliveryDelay(500);
policy.setBackOffMultiplier(2);
policy.setUseExponentialBackOff(true);
policy.setMaximumRedeliveries(2);
Once a message's redelivery attempts exceeds the maximumRedeliveries configured for the Redelivery Policy, a "Poison ack" is sent back to the broker letting him know that the message was considered a poison pill. The Broker then takes the message and sends it to a Dead Letter Queue so that it can be analyzed later on.
By default, there’s one dead-letter queue for all messages, called AcitveMQ.DLQ, which expired messages or messages that have exceeded their redelivery attempts get sent to. You can configure a dead-letter queue for a hierarchy, or an individual 288 CHAPTER 11 ActiveMQ broker features in action destination in the ActiveMQ broker configuration, like in the following example, where we set an IndividualDeadLetterStrategy:
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry queue=">">
<deadLetterStrategy>
<individualDeadLetterStrategy
queuePrefix="DLQ."
useQueueForQueueMessages="true"
processExpired="false"
processNonPersistent="false"/>
</deadLetterStrategy>
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
Broker Redelivery (v5.7)
Typically a consumer handles redelivery so that it can maintain message order while a message appears as inflight on the broker.
This means that redelivery is limited to a single consumer unless that consumer terminates. In this way the broker is unaware of redelivery.
With broker redelivery, it is possible to have the broker redeliver a message after a delay using a resend. This is implemented by a broker plugin that handles dead letter processing by redelivery via the scheduler. This is useful when total message order is not important and where through put and load distribution among consumers is. With broker redelivery, messages that fail delivery to a given consumer can get immediately re-dispatched.
The feature is enabled via xml configuration of the form:
<broker xmlns="http://activemq.apache.org/schema/core" schedulerSupport="true" >
....
<plugins>
<redeliveryPlugin fallbackToDeadLetter="true" sendToDlqIfMaxRetriesExceeded="true">
<redeliveryPolicyMap>
<redeliveryPolicyMap>
<redeliveryPolicyEntries>
<!-- a destination specific policy -->
<redeliveryPolicy queue="SpecialQueue" maximumRedeliveries="4" redeliveryDelay="10000" />
</redeliveryPolicyEntries> <!-- the fallback policy for all other destinations -->
<defaultEntry>
<redeliveryPolicy maximumRedeliveries="4" initialRedeliveryDelay="5000" redeliveryDelay="10000" />
</defaultEntry>
</redeliveryPolicyMap>
</redeliveryPolicyMap>
</redeliveryPlugin>
</plugins>
....
</broker>
The familiar Redelivery Policy has been extended to take a matching destination.
fallbackToDeadLetter controls the action when there is no matching redeliver policy for a destination. Defaults to true so regular DLQ processing ensues.
sendToDlqIfMaxRetriesExceeded controls the action when the retry limit is exceeded. Defaults to true so regular DLQ processing ensues. When false, the message is dropped.
Note: broker schedulerSupport must be enabled for this feature to work.
ActiveMQ(5.10.0) - Message Redelivery and DLQ Handling的更多相关文章
- ActiveMQ(5.10.0) - Spring Support
Maven Dependency: <dependencies> <dependency> <groupId>org.apache.activemq</gro ...
- ActiveMQ 5.10.0 安装与配置
先在官网下载activeMQ,我这里是5.10.0. 然后在解压在一个文件夹下即可. 我这里是:D:\apache-activemq-5.10.0-bin 然后进入bin目录:D:\apache-ac ...
- ActiveMQ(5.10.0) - Configuring the JAAS Authentication Plug-in
JAAS provides pluggable authentication, which means ActiveMQ will use the same authentication API re ...
- ActiveMQ(5.10.0) - Building a custom security plug-in
If none of any built-in security mechanisms works for you, you can always build your own. Though the ...
- ActiveMQ(5.10.0) - Connection Configuration URI
An Apache ActiveMQ connection can be configured by explicitly setting properties on the ActiveMQConn ...
- ActiveMQ(5.10.0) - 删除闲置的队列或主题
方法一 通过 ActiveMQ Web 控制台删除. 方法二 通过 Java 代码删除. ActiveMQConnection.destroyDestination(ActiveMQDestinati ...
- ActiveMQ(5.10.0) - hello world
Sending a JMS message public class MyMessageProducer { ... // 创建连接工厂实例 ConnectionFactory connFactory ...
- ActiveMQ(5.10.0) - Wildcards and composite destinations
In this section we’ll look at two useful features of ActiveMQ: subscribing to multiple destinations ...
- ActiveMQ(5.10.0) - 使用 JDBC 持久化消息
1. 编辑 ACTIVEMQ_HOME/conf/activemq.xml. <beans> <broker brokerName="localhost" per ...
随机推荐
- 关于名称重整(name mangling)、多态性的一些简单介绍
在看GCC源码的时候看到mangles这个单词,于是google了一下. 在面向对象编程语言出现之前,如果你想要打印不同类型的数据,需要写多个方法,例如PrintInteger(int i),Prin ...
- F - Coins
F - Coins Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u Submit St ...
- Educational Codeforces Round 2 B. Queries about less or equal elements 水题
B. Queries about less or equal elements Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforc ...
- Hibernate征途(六)之数量和关系映射
本来如果和关系模型一样,只需要一对一.一对多.多对多映射就够了,但是前面<Hibernate征途(四)之映射 序>中说到,对象模型中关联是有方向的,所以对一对多而言,就会产生一对多还是多对 ...
- 获得临时文件目录(Temp文件夹)
C:\Users\ADMINI~1\AppData\Local\Temp\ //GetTempPath获得临时文件目录(Temp文件夹) function TempPath:String;var ...
- Android-L-Samples
https://github.com/s3xy4ngyc/Android-L-Samples
- ORACLE触发器具体解释
ORACLE PL/SQL编程之八: 把触发器说透 本篇主要内容例如以下: 8.1 触发器类型 8.1.1 DML触发器 8.1.2 替代触发器 8.1.3 系统触发器 8.2 创建触发器 8.2.1 ...
- 解决fedora64下vim不能语法着色问题
初始状态是vim打开任何文件都没有高亮迹象,接不是彩色,也没有下划线,好了,看怎么一步步解决的... 1)#vim ~/.vimrc 竟然没有这个文件,创建之#touch vim ~/.vimrc 添 ...
- UNIX标准化及实现之POSIX标准扩展头文件
POSIX标准定义的XSI(X/Open System Interface)扩展头文件 头文件 说明 <cpio.h> cpio归档值 <dlfcn.h> 动态链接 <f ...
- linux epoll模型
原文:http://yjtjh.blog.51cto.com/1060831/294119 Linux I/O多路复用技术在比较多的TCP网络服务器中有使用,即比较多的用到select函数.Linux ...