4
votes

I am writing an application using activemq where I am using the redelivery policy to redeliver the messages. I am using the ActiveMQ's ExponentialBackOff concept.

My question is how does this ExponentialBackOff/setBackOffMultiplier work.

For example in my case I want to redeliver the message till the message expiration time, which is 15 minutes.I want to try to redeliver 10 times within 15 minutes.But ExponentialBackOff makes the message to redeliver beyond the 15 minutes expiry time of the message i.e. the message to be redelivered is still in the pending state even after the expiration time which is 15 minutes.

Why is this? I am kind of confused with this behavior. The redelivery policy I am using is as below.

RedeliveryPolicy queuePolicy = new RedeliveryPolicy();
queuePolicy.setInitialRedeliveryDelay(0);
queuePolicy.setBackOffMultiplier(3);
queuePolicy.setUseExponentialBackOff(true);
queuePolicy.setMaximumRedeliveries(10);
1

1 Answers

6
votes

with this RedeliveryPolicy config, the RedeliveryPolicy will make attempts after each time waiting below :

after 1s
after 3s
9s
27s
81s
243s
729s
2187s
6561s
19683s

as you see like this attempts are executed after hours and in the meantime you see messages state is pending. to prevent these long periods maybe you want to set the maximumRedeliveryDelay=300000L (5 minutes). Note that

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.

you need to adapt your RedeliveryPolicy because the message is pending as long as maximumRedeliveries is not exceeded.

http://activemq.apache.org/message-redelivery-and-dlq-handling.html