if (messageReference.isExpired()) {
// there are two uses of sendToDeadLetterQueue, we are only interested in valid messages
super.sendToDeadLetterQueue(context, messageReference, subscription);
} else {
try {
Destination regionDestination = (Destination) messageReference.getRegionDestination();
final RedeliveryPolicy redeliveryPolicy = redeliveryPolicyMap.getEntryFor(regionDestination.getActiveMQDestination());
if (redeliveryPolicy != null) {
int redeliveryCount = messageReference.getRedeliveryCounter();
if (redeliveryCount < redeliveryPolicy.getMaximumRedeliveries()) {
long delay = ( redeliveryCount == 0 ?
redeliveryPolicy.getInitialRedeliveryDelay() :
redeliveryPolicy.getNextRedeliveryDelay(getExistingDelay(messageReference)));
scheduleRedelivery(context, messageReference, delay, ++redeliveryCount);
} else if (isSendToDlqIfMaxRetriesExceeded()) {
super.sendToDeadLetterQueue(context, messageReference, subscription);
} else {
LOG.debug("Discarding message that exceeds max redelivery count, " + messageReference.getMessageId());
}
} else if (isFallbackToDeadLetter()) {
super.sendToDeadLetterQueue(context, messageReference, subscription);
} else {
LOG.debug("Ignoring dlq request for:" + messageReference.getMessageId() + ", RedeliveryPolicy not found (and no fallback) for: " + regionDestination.getActiveMQDestination());
}
} catch (Exception exception) {
// abort the ack, will be effective if client use transactions or individual ack with sync send
RuntimeException toThrow = new RuntimeException("Failed to schedule redelivery for: " + messageReference.getMessageId(), exception);
LOG.error(toThrow.toString(), exception);