OverviewMessages are redelivered to a client when any of the following occurs:
The broker transmits the default delivery policy that he prefers to a client connection in his RedeliveryPolicy policy = connection.getRedeliveryPolicy(); policy.setInitialRedeliveryDelay(500); policy.setBackOffMultiplier(2); policy.setUseExponentialBackOff(true); policy.setMaximumRedeliveries(2); Once a message's redelivery attempts exceeds the The default Dead Letter Queue in ActiveMQ is called <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> See the Redelivery Policy section for some more detail on the policy options. Automatically Discard Expired MessagesSome folks simply need expired messages to be discarded instead of sent to the DLQ i.e., skip the DLQ entirely. This simplifies the management of the DLQ so that you're not sifting through loads of expired messages to find messages with real problems. To tell ActiveMQ to just discard expired messages, configure the <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> Place Non-Persistent Messages Onto The Dead-Letter QueueBy default, ActiveMQ will not place undeliverable non-persistent messages on the dead-letter queue. The rationale for this behavior is that if the application doesn't care enough to make the message persistent, then there is little or no value in recording that the message was undeliverable. If you do want to place non-persistent messages on the dead-letter queue, then you should set <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> Setting Expiration on Messages in the DLQBy default, ActiveMQ will never expire messages sent to the DLQ. However, from ActiveMQ 5.12 the Be selective in how this is applied. In particular do not apply expiration to your DLQ destinations by setting expiration on a default or inclusive wildcard policy entry. If a DLQ entry expires and forwards to the same or another DLQ with expiry, you will introduce a loop that can be problematic if the strategy audit is disabled or it's sliding window is exceeded. <broker> <destinationPolicy> <policyMap> <policyEntries> <policyEntry queue="QueueWhereItIsOkToExpireDLQEntries"> <deadLetterStrategy> <.... expiration="300000"/> </deadLetterStrategy> </policyEntry> </policyEntries> </policyMap> </destinationPolicy> </broker> Message auditThe dead letter strategy has an message audit that is enabled by default. This prevents duplicate messages from being added to the configured DLQ. From 5.15.0, the limits of the audit can configured via the maxProducersToAudit and maxAuditDepth attributes. The audit can be disabled using enableAudit="false"
The Discarding DLQ Plugin
From ActiveMQ 5.9 - a destination <deadLetterStrategy> <discarding/> </deadLetterStrategy> This does the same thing as the plugin but on a per destination basis. The matching based on regular expressions of the plugin is a bit more powerful than destination matching so the plugin may still be useful in some cases.
A very simple yet very useful plugin to the broker. This plugin allows the configuration of queues and topics, all or matched based on Java SE regular expressions, to drop messages that have been sent to the DLQ. This is extremely useful when using constant pending message limit strategy or the other eviction rules, but you don't want to incur the overhead of yet another consumer to clear the DLQ. Below is an example of a basic configuration to drop everything: <beans> <broker> <plugins> <discardingDLQBrokerPlugin dropAll="true" dropTemporaryTopics="true" dropTemporaryQueues="true"/> </plugins> </broker> </beans> Below is a slightly more complex example: <beans> <broker> <plugins> <discardingDLQBrokerPlugin dropOnly="MY.EXAMPLE.TOPIC.29 MY.EXAMPLE.QUEUE.87" reportInterval="1000"/> </plugins> </broker> </beans>
Below is an even more complex example: <beans> <broker> <plugins> <discardingDLQBrokerPlugin dropOnly="MY.EXAMPLE.TOPIC.[0-9]{3} MY.EXAMPLE.QUEUE.[0-9]{3}" reportInterval="3000"/> </plugins> </broker> </beans>
For more information, see the source code for the DiscardingDLQBrokerPlugin and the DiscardingDLQBroker 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.
<broker schedulerSupport="true"> <plugins> <redeliveryPlugin fallbackToDeadLetter="true" sendToDlqIfMaxRetriesExceeded="true"> <redeliveryPolicyMap> <redeliveryPolicyMap> <redeliveryPolicyEntries> <!-- a destination specific policy --> <redeliveryPolicy queue="SpecialQueue" maximumRedeliveries="4" redeliveryDelay="10000"/> </redeliveryPolicyEntries> <defaultEntry> <!-- the fallback policy for all other destinations --> <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. ActiveMQ's schedulerSupport must be enabled for this feature to work. |