Red Hat AMQ 6
As of February 2025, Red Hat is no longer supporting Red Hat AMQ 6. If you are using AMQ 6, please upgrade: Migrating to AMQ 7.Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 7. Message Redelivery
Overview
- A transacted session is used and
rollback()
is called. - A transacted session is closed before commit is called.
- A session is using
CLIENT_ACKNOWLEDGE
andSession.recover()
is called.
- On the broker, using the broker's redelivery plug-in,
- On the connection factory, using the connection URI,
- On the connection, using the
RedeliveryPolicy
, - On destinations, using the connection's
RedeliveryPolicyMap
.
Redelivery properties
Option | Default | Description |
---|---|---|
collisionAvoidanceFactor | 0.15 | Specifies the percentage of range of collision avoidance. |
maximumRedeliveries | 6 | Specifies the maximum number of times a message will be redelivered before it is considered a poisoned pill and returned to the broker so it can go to a dead letter queue. -1 specifies an infinite number of redeliveries. |
maximumRedeliveryDelay | -1 | Specifies the maximum delivery delay that will be applied if the useExponentialBackOff option is set. -1 specifies that no maximum be applied. |
initialRedeliveryDelay | 1000 | Specifies the initial redelivery delay in milliseconds. |
redeliveryDelay | 1000 | Specifies the delivery delay, in milliseconds, if initialRedeliveryDelay is 0. |
useCollisionAvoidance | false | Specifies if the redelivery policy uses collision avoidance. |
useExponentialBackOff | false | Specifies if the redelivery time out should be increased exponentially. |
backOffMultiplier | 5 | Specifies the back-off multiplier. |
Configuring the broker's redelivery plug-in
maximumRedeliveries
to 0 on the destination).
redeliveryPlugin
element. As shown in Example 7.1, “Configuring the Redelivery Plug-In” this element is a child of the broker's plugins
element and contains a policy map defining the desired behavior.
Example 7.1. Configuring the Redelivery Plug-In
<broker xmlns="http://activemq.apache.org/schema/core" ... > .... <plugins> <redeliveryPlugin ... > <redeliveryPolicyMap> <redeliveryPolicyMap> <redeliveryPolicyEntries> 1 <!-- a destination specific policy --> <redeliveryPolicy queue="SpecialQueue" maximumRedeliveries="3" initialRedeliveryDelay="3000" /> </redeliveryPolicyEntries> <!-- the fallback policy for all other destinations --> <defaultEntry> 2 <redeliveryPolicy maximumRedeliveries="3" initialRedeliveryDelay="3000" /> </defaultEntry> </redeliveryPolicyMap> </redeliveryPolicyMap> </redeliveryPlugin> </plugins> ... </broker>
- 1
- The
redeliveryPolicyEntries
element contains a list ofredeliveryPolicy
elements that configures redelivery policies on a per-destination basis. - 2
- The
defaultEntry
element contains a singleredeliveryPolicy
element that configures the redelivery policy used by all destinations that do not match the one with a specific policy.
Configuring the redelivery using the broker URI
Example 7.2. Setting the Redelivery Policy using a Connection URI
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616?jms.redeliveryPolicy.maximumRedeliveries=4");
Setting the redelivery policy on a connection
ActiveMQConnection
class' getRedeliveryPolicy()
method allows you to configure the redelivery policy for all consumer's using that connection.
getRedeliveryPolicy()
returns a RedeliveryPolicy
object that controls the redelivery policy for the connection. The RedeliveryPolicy
object has setters for each of the properties listed in Table 7.1, “Redelivery Policy Options”.
Example 7.3. Setting the Redelivery Policy for a Connection
ActiveMQConnection connection = connectionFactory.createConnetion(); // Get the redelivery policy RedeliveryPolicy policy = connection.getRedeliveryPolicy(); // Set the policy policy.setMaximumRedeliveries(4);
Setting the redelivery policy on a destination
ActiveMQConnection
class' getRedeliveryPolicyMap()
method returns a RedeliveryPolicyMap
object that is a map of RedeliveryPolicy
objects with destination names as the key.
RedeliveryPolicy
object controls the redelivery policy for all destinations whose name match the destination name specified in the map's key.
FRED.JOE
can only be redelivered 4 times.
Example 7.4. Setting the Redelivery Policy for a Destination
ActiveMQConnection connection = connectionFactory.createConnetion(); // Get the redelivery policy RedeliveryPolicy policy = new RedeliveryPolicy(); policy.setMaximumRedeliveries(4); //Get the policy map RedeliveryPolicyMap map = connection.getRedeliveryPolicyMap(); map.put(new ActiveMQQueue("FRED.JOE"), queuePolicy);