Skip to content

Commit

Permalink
CAMEL-8256: Include deadLetterUri in ExchangeFailureHandledEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
davsclaus committed Jan 18, 2015
1 parent 77851e1 commit 37d4914
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
Expand Up @@ -93,13 +93,14 @@ public EventObject createExchangeFailedEvent(Exchange exchange) {
return new ExchangeFailedEvent(exchange);
}

public EventObject createExchangeFailureHandledEvent(Exchange exchange, Processor failureHandler, boolean deadLetterChannel) {
public EventObject createExchangeFailureHandledEvent(Exchange exchange, Processor failureHandler,
boolean deadLetterChannel, String deadLetterUri) {
// unwrap delegate processor
Processor handler = failureHandler;
if (handler instanceof DelegateProcessor) {
handler = ((DelegateProcessor) handler).getProcessor();
}
return new ExchangeFailureHandledEvent(exchange, handler, deadLetterChannel);
return new ExchangeFailureHandledEvent(exchange, handler, deadLetterChannel, deadLetterUri);
}

public EventObject createExchangeRedeliveryEvent(Exchange exchange, int attempt) {
Expand Down
Expand Up @@ -18,21 +18,24 @@

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.util.URISupport;

/**
* @version
*/
public class ExchangeFailureHandledEvent extends AbstractExchangeEvent {
private static final long serialVersionUID = -7554809462006009547L;
private static final long serialVersionUID = -7554809462006009548L;

private final Processor failureHandler;
private final transient Processor failureHandler;
private final boolean deadLetterChannel;
private final String deadLetterUri;
private final boolean handled;

public ExchangeFailureHandledEvent(Exchange source, Processor failureHandler, boolean deadLetterChannel) {
public ExchangeFailureHandledEvent(Exchange source, Processor failureHandler, boolean deadLetterChannel, String deadLetterUri) {
super(source);
this.failureHandler = failureHandler;
this.deadLetterChannel = deadLetterChannel;
this.deadLetterUri = deadLetterUri;
this.handled = source.getProperty(Exchange.ERRORHANDLER_HANDLED, false, Boolean.class);
}

Expand All @@ -44,16 +47,21 @@ public boolean isDeadLetterChannel() {
return deadLetterChannel;
}

public String getDeadLetterUri() {
return deadLetterUri;
}

public boolean isHandled() {
return handled;
}

@Override
public String toString() {
if (isDeadLetterChannel()) {
return getExchange().getExchangeId() + " exchange failed: " + getExchange() + " but was handled by dead letter channel: " + failureHandler;
String uri = URISupport.sanitizeUri(deadLetterUri);
return getExchange().getExchangeId() + " exchange failed: " + getExchange() + " but was handled by dead letter channel: " + uri;
} else {
return getExchange().getExchangeId() + " exchange failed: " + getExchange() + " but was processed by: " + failureHandler;
return getExchange().getExchangeId() + " exchange failed: " + getExchange() + " but was processed by failure processor: " + failureHandler;
}
}
}
Expand Up @@ -896,7 +896,7 @@ public void done(boolean sync) {
prepareExchangeAfterFailure(exchange, data, isDeadLetterChannel, shouldHandle, shouldContinue);
// fire event as we had a failure processor to handle it, which there is a event for
boolean deadLetterChannel = processor == data.deadLetterProcessor;
EventHelper.notifyExchangeFailureHandled(exchange.getContext(), exchange, processor, deadLetterChannel);
EventHelper.notifyExchangeFailureHandled(exchange.getContext(), exchange, processor, deadLetterChannel, deadLetterUri);
} finally {
// if the fault was handled asynchronously, this should be reflected in the callback as well
data.sync &= sync;
Expand Down
Expand Up @@ -166,9 +166,11 @@ public interface EventFactory {
* @param exchange the exchange
* @param failureHandler the failure handler such as moving the message to a dead letter queue
* @param deadLetterChannel whether it was a dead letter channel or not handling the failure
* @param deadLetterUri the dead letter uri, if its a dead letter channel
* @return the created event
*/
EventObject createExchangeFailureHandledEvent(Exchange exchange, Processor failureHandler, boolean deadLetterChannel);
EventObject createExchangeFailureHandledEvent(Exchange exchange, Processor failureHandler,
boolean deadLetterChannel, String deadLetterUri);

/**
* Creates an {@link EventObject} when an {@link org.apache.camel.Exchange} is about to be redelivered
Expand Down
Expand Up @@ -479,7 +479,7 @@ public static void notifyExchangeFailed(CamelContext context, Exchange exchange)
}

public static void notifyExchangeFailureHandled(CamelContext context, Exchange exchange, Processor failureHandler,
boolean deadLetterChannel) {
boolean deadLetterChannel, String deadLetterUri) {
if (exchange.getProperty(Exchange.NOTIFY_EVENT, false, Boolean.class)) {
// do not generate events for an notify event
return;
Expand All @@ -504,7 +504,7 @@ public static void notifyExchangeFailureHandled(CamelContext context, Exchange e
if (factory == null) {
return;
}
EventObject event = factory.createExchangeFailureHandledEvent(exchange, failureHandler, deadLetterChannel);
EventObject event = factory.createExchangeFailureHandledEvent(exchange, failureHandler, deadLetterChannel, deadLetterUri);
if (event == null) {
return;
}
Expand Down
Expand Up @@ -106,6 +106,7 @@ public void configure() throws Exception {
assertEquals("should be DLC", true, e.isDeadLetterChannel());
SendProcessor send = assertIsInstanceOf(SendProcessor.class, e.getFailureHandler());
assertEquals("mock://dead", send.getDestination().getEndpointUri());
assertEquals("mock://dead", e.getDeadLetterUri());

// dead letter channel will mark the exchange as completed
assertIsInstanceOf(ExchangeCompletedEvent.class, events.get(9));
Expand Down

0 comments on commit 37d4914

Please sign in to comment.