use of org.mule.runtime.core.privileged.exception.MessageRedeliveredException in project mule by mulesoft.
the class IdempotentRedeliveryPolicy method process.
@Override
public CoreEvent process(CoreEvent event) throws MuleException {
Optional<Exception> exceptionSeen = empty();
String messageId = null;
try {
messageId = getIdForEvent(event);
} catch (ExpressionRuntimeException e) {
logger.warn("The message cannot be processed because the digest could not be generated. Either make the payload serializable or use an expression.");
return null;
} catch (Exception ex) {
exceptionSeen = of(ex);
}
Lock lock = lockFactory.createLock(idrId + "-" + messageId);
lock.lock();
try {
RedeliveryCounter counter = findCounter(messageId);
if (exceptionSeen.isPresent()) {
throw new MessageRedeliveredException(messageId, counter.counter.get(), maxRedeliveryCount, exceptionSeen.get());
} else if (counter != null && counter.counter.get() > maxRedeliveryCount) {
throw new MessageRedeliveredException(messageId, counter.errors, counter.counter.get(), maxRedeliveryCount);
}
try {
CoreEvent returnEvent = processNext(CoreEvent.builder(DefaultEventContext.child((BaseEventContext) event.getContext(), empty()), event).build());
counter = findCounter(messageId);
if (counter != null) {
resetCounter(messageId);
}
return returnEvent;
} catch (Exception ex) {
if (ex instanceof MessagingException) {
incrementCounter(messageId, (MessagingException) ex);
throw ex;
} else {
MessagingException me = createMessagingException(event, ex, this);
incrementCounter(messageId, me);
throw ex;
}
}
} finally {
lock.unlock();
}
}
Aggregations