https://issues.apache.org/jira/browse/AMQ-5674 - revisit change - use single redelivey delay attribute for both initial and subsequent delays - resolves regression in BrokerRedeliveryTest

This commit is contained in:
gtully 2015-04-03 14:18:55 +01:00 committed by Daniel Kulp
parent f1f171d4a5
commit 6c384c9b79
5 changed files with 10 additions and 18 deletions

View File

@ -140,9 +140,10 @@ public class RedeliveryPlugin extends BrokerPluginSupport {
int redeliveryCount = messageReference.getRedeliveryCounter(); int redeliveryCount = messageReference.getRedeliveryCounter();
if (RedeliveryPolicy.NO_MAXIMUM_REDELIVERIES == maximumRedeliveries || redeliveryCount < maximumRedeliveries) { if (RedeliveryPolicy.NO_MAXIMUM_REDELIVERIES == maximumRedeliveries || redeliveryCount < maximumRedeliveries) {
long delay = ( redeliveryCount == 0 ? long delay = redeliveryPolicy.getInitialRedeliveryDelay();
redeliveryPolicy.getInitialRedeliveryDelay() : for (int i = 0; i < redeliveryCount; i++) {
redeliveryPolicy.getNextRedeliveryDelay(getExistingDelay(messageReference))); delay = redeliveryPolicy.getNextRedeliveryDelay(delay);
}
scheduleRedelivery(context, messageReference, delay, ++redeliveryCount); scheduleRedelivery(context, messageReference, delay, ++redeliveryCount);
} else if (isSendToDlqIfMaxRetriesExceeded()) { } else if (isSendToDlqIfMaxRetriesExceeded()) {
@ -199,11 +200,4 @@ public class RedeliveryPlugin extends BrokerPluginSupport {
} }
} }
private int getExistingDelay(MessageReference messageReference) throws IOException {
Object val = messageReference.getMessage().getProperty(REDELIVERY_DELAY);
if (val instanceof Long) {
return ((Long)val).intValue();
}
return 0;
}
} }

View File

@ -98,10 +98,7 @@ public class RedeliveryPolicy extends DestinationMapEntry implements Cloneable,
} }
public long getNextRedeliveryDelay(long previousDelay) { public long getNextRedeliveryDelay(long previousDelay) {
long nextDelay = initialRedeliveryDelay; long nextDelay = redeliveryDelay;
if (nextDelay == 0) {
nextDelay = redeliveryDelay;
}
if (previousDelay > 0 && useExponentialBackOff && backOffMultiplier > 1) { if (previousDelay > 0 && useExponentialBackOff && backOffMultiplier > 1) {
nextDelay = (long) (previousDelay * backOffMultiplier); nextDelay = (long) (previousDelay * backOffMultiplier);

View File

@ -639,6 +639,7 @@ public class ActiveMQActivationSpec implements MessageActivationSpec, Serializab
*/ */
public void setInitialRedeliveryDelay(long initialRedeliveryDelay) { public void setInitialRedeliveryDelay(long initialRedeliveryDelay) {
lazyCreateRedeliveryPolicy().setInitialRedeliveryDelay(initialRedeliveryDelay); lazyCreateRedeliveryPolicy().setInitialRedeliveryDelay(initialRedeliveryDelay);
redeliveryPolicy.setRedeliveryDelay(initialRedeliveryDelay);
} }
/** /**

View File

@ -75,11 +75,11 @@ public class RedeliveryPolicyTest extends JmsTestSupport {
policy.setInitialRedeliveryDelay(500); policy.setInitialRedeliveryDelay(500);
long delay = policy.getNextRedeliveryDelay(500); long delay = policy.getNextRedeliveryDelay(500);
assertEquals(500, delay); assertEquals(1000, delay);
delay = policy.getNextRedeliveryDelay(delay); delay = policy.getNextRedeliveryDelay(delay);
assertEquals(500, delay); assertEquals(1000, delay);
delay = policy.getNextRedeliveryDelay(delay); delay = policy.getNextRedeliveryDelay(delay);
assertEquals(500, delay); assertEquals(1000, delay);
} }

View File

@ -81,7 +81,7 @@ public class BrokerRedeliveryTest extends org.apache.activemq.TestSupport {
LOG.info("got: " + brokerRedeliveryMessage); LOG.info("got: " + brokerRedeliveryMessage);
assertNotNull("got message via broker redelivery after delay", brokerRedeliveryMessage); assertNotNull("got message via broker redelivery after delay", brokerRedeliveryMessage);
assertEquals("message matches", message.getStringProperty("data"), brokerRedeliveryMessage.getStringProperty("data")); assertEquals("message matches", message.getStringProperty("data"), brokerRedeliveryMessage.getStringProperty("data"));
assertEquals("has expiryDelay specified", i == 0 ? initialRedeliveryDelayMillis : redeliveryDelayMillis, brokerRedeliveryMessage.getLongProperty(RedeliveryPlugin.REDELIVERY_DELAY)); assertEquals("has expiryDelay specified - iteration:" + i, i == 0 ? initialRedeliveryDelayMillis : redeliveryDelayMillis, brokerRedeliveryMessage.getLongProperty(RedeliveryPlugin.REDELIVERY_DELAY));
consumerSession.rollback(); consumerSession.rollback();
} }