mirror of https://github.com/apache/activemq.git
Adds an optional maximumRedeliveryDelay that defaults to -1 to indicate no max so behavior is unchanged from previous versions. When the backoff multiplier is enabled and the maximumReliveryDelay is set > -1 then the delay returned by getNextReliveryDealy is capped by the max of either maximumReliveryDelay or redeliveryDelay preventing delays smaller than the configured redelivery delay. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1078189 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
69f56058f2
commit
f29c8011d0
|
@ -34,6 +34,7 @@ public class RedeliveryPolicy implements Cloneable, Serializable {
|
|||
// +/-15% for a 30% spread -cgs
|
||||
private double collisionAvoidanceFactor = 0.15d;
|
||||
private int maximumRedeliveries = 6;
|
||||
private long maximumRedeliveryDelay = -1;
|
||||
private long initialRedeliveryDelay = 1000L;
|
||||
private boolean useCollisionAvoidance;
|
||||
private boolean useExponentialBackOff;
|
||||
|
@ -75,6 +76,14 @@ public class RedeliveryPolicy implements Cloneable, Serializable {
|
|||
this.initialRedeliveryDelay = initialRedeliveryDelay;
|
||||
}
|
||||
|
||||
public long getMaximumRedeliveryDelay() {
|
||||
return maximumRedeliveryDelay;
|
||||
}
|
||||
|
||||
public void setMaximumRedeliveryDelay(long maximumRedeliveryDelay) {
|
||||
this.maximumRedeliveryDelay = maximumRedeliveryDelay;
|
||||
}
|
||||
|
||||
public int getMaximumRedeliveries() {
|
||||
return maximumRedeliveries;
|
||||
}
|
||||
|
@ -90,6 +99,10 @@ public class RedeliveryPolicy implements Cloneable, Serializable {
|
|||
nextDelay = redeliveryDelay;
|
||||
} else if (useExponentialBackOff && backOffMultiplier > 1) {
|
||||
nextDelay = (long) (previousDelay * backOffMultiplier);
|
||||
if(maximumRedeliveryDelay != -1 && nextDelay > maximumRedeliveryDelay) {
|
||||
// in case the user made max redelivery delay less than redelivery delay for some reason.
|
||||
nextDelay = Math.max(maximumRedeliveryDelay, redeliveryDelay);
|
||||
}
|
||||
} else {
|
||||
nextDelay = previousDelay;
|
||||
}
|
||||
|
|
|
@ -267,6 +267,56 @@ public class RedeliveryPolicyTest extends JmsTestSupport {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testMaximumRedeliveryDelay() throws Exception {
|
||||
|
||||
// Receive a message with the JMS API
|
||||
RedeliveryPolicy policy = connection.getRedeliveryPolicy();
|
||||
policy.setInitialRedeliveryDelay(10);
|
||||
policy.setUseExponentialBackOff(true);
|
||||
policy.setMaximumRedeliveries(-1);
|
||||
policy.setRedeliveryDelay(50);
|
||||
policy.setMaximumRedeliveryDelay(1000);
|
||||
policy.setBackOffMultiplier((short) 2);
|
||||
policy.setUseExponentialBackOff(true);
|
||||
|
||||
connection.start();
|
||||
Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
|
||||
ActiveMQQueue destination = new ActiveMQQueue("TEST");
|
||||
MessageProducer producer = session.createProducer(destination);
|
||||
|
||||
MessageConsumer consumer = session.createConsumer(destination);
|
||||
|
||||
// Send the messages
|
||||
producer.send(session.createTextMessage("1st"));
|
||||
producer.send(session.createTextMessage("2nd"));
|
||||
session.commit();
|
||||
|
||||
TextMessage m;
|
||||
|
||||
for(int i = 0; i < 10; ++i) {
|
||||
// we should be able to get the 1st message redelivered until a session.commit is called
|
||||
m = (TextMessage)consumer.receive(2000);
|
||||
assertNotNull(m);
|
||||
assertEquals("1st", m.getText());
|
||||
session.rollback();
|
||||
}
|
||||
|
||||
m = (TextMessage)consumer.receive(2000);
|
||||
assertNotNull(m);
|
||||
assertEquals("1st", m.getText());
|
||||
session.commit();
|
||||
|
||||
m = (TextMessage)consumer.receive(2000);
|
||||
assertNotNull(m);
|
||||
assertEquals("2nd", m.getText());
|
||||
session.commit();
|
||||
|
||||
assertTrue(policy.getNextRedeliveryDelay(Long.MAX_VALUE) == 1000 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue