use of org.apache.camel.processor.DeadLetterChannel in project camel by apache.
the class DeadLetterChannelBuilder method createErrorHandler.
public Processor createErrorHandler(RouteContext routeContext, Processor processor) throws Exception {
validateDeadLetterUri(routeContext);
DeadLetterChannel answer = new DeadLetterChannel(routeContext.getCamelContext(), processor, getLogger(), getOnRedelivery(), getRedeliveryPolicy(), getExceptionPolicyStrategy(), getFailureProcessor(), getDeadLetterUri(), isDeadLetterHandleNewException(), isUseOriginalMessage(), getRetryWhilePolicy(routeContext.getCamelContext()), getExecutorService(routeContext.getCamelContext()), getOnPrepareFailure(), getOnExceptionOccurred());
// configure error handler before we can use it
configure(routeContext, answer);
return answer;
}
use of org.apache.camel.processor.DeadLetterChannel in project camel by apache.
the class ErrorHandlerTest method testConfigureDeadLetterChannel.
public void testConfigureDeadLetterChannel() throws Exception {
// START SNIPPET: e3
RouteBuilder builder = new RouteBuilder() {
public void configure() {
// using dead letter channel with a seda queue for errors
errorHandler(deadLetterChannel("seda:errors"));
// here is our route
from("seda:a").to("seda:b");
}
};
// END SNIPPET: e3
List<Route> list = getRouteList(builder);
assertEquals("Number routes created" + list, 1, list.size());
for (Route route : list) {
Endpoint key = route.getEndpoint();
assertEquals("From endpoint", "seda://a", key.getEndpointUri());
EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
Channel channel = unwrapChannel(consumerRoute.getProcessor());
assertIsInstanceOf(SendProcessor.class, channel.getNextProcessor());
}
}
use of org.apache.camel.processor.DeadLetterChannel in project camel by apache.
the class ContextErrorHandlerTest method testGetTheDefaultErrorHandlerFromContext.
public void testGetTheDefaultErrorHandlerFromContext() throws Exception {
RouteBuilder builder = new RouteBuilder() {
public void configure() {
from("seda:a").to("seda:b");
from("direct:c").to("direct:d");
}
};
List<Route> list = getRouteListWithCurrentContext(builder);
assertEquals("Number routes created" + list, 2, list.size());
for (Route route : list) {
EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
Processor processor = consumerRoute.getProcessor();
Channel channel = unwrapChannel(processor);
DeadLetterChannel deadLetterChannel = assertIsInstanceOf(DeadLetterChannel.class, channel.getErrorHandler());
RedeliveryPolicy redeliveryPolicy = deadLetterChannel.getRedeliveryPolicy();
assertEquals("getMaximumRedeliveries()", 1, redeliveryPolicy.getMaximumRedeliveries());
assertEquals("isUseExponentialBackOff()", true, redeliveryPolicy.isUseExponentialBackOff());
}
}
use of org.apache.camel.processor.DeadLetterChannel in project camel by apache.
the class ErrorHandlerTest method testEndpointConfiguration.
public void testEndpointConfiguration() throws Exception {
SpringCamelContext context = applicationContext.getBeansOfType(SpringCamelContext.class).values().iterator().next();
List<Route> list = context.getRoutes();
assertEquals("Number routes created" + list, 2, list.size());
for (Route route : list) {
EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
Channel channel = unwrapChannel(consumerRoute.getProcessor());
DeadLetterChannel deadLetterChannel = assertIsInstanceOf(DeadLetterChannel.class, channel.getErrorHandler());
RedeliveryPolicy redeliveryPolicy = deadLetterChannel.getRedeliveryPolicy();
assertEquals("getMaximumRedeliveries()", 1, redeliveryPolicy.getMaximumRedeliveries());
assertEquals("isUseExponentialBackOff()", true, redeliveryPolicy.isUseExponentialBackOff());
}
}
use of org.apache.camel.processor.DeadLetterChannel in project camel by apache.
the class ErrorHandlerTest method testConfigureDeadLetterChannelWithCustomRedeliveryPolicy.
public void testConfigureDeadLetterChannelWithCustomRedeliveryPolicy() throws Exception {
// START SNIPPET: e4
RouteBuilder builder = new RouteBuilder() {
public void configure() {
// configures dead letter channel to use seda queue for errors and use at most 2 redelveries
// and exponential backoff
errorHandler(deadLetterChannel("seda:errors").maximumRedeliveries(2).useExponentialBackOff());
// here is our route
from("seda:a").to("seda:b");
}
};
// END SNIPPET: e4
List<Route> list = getRouteList(builder);
assertEquals("Number routes created" + list, 1, list.size());
for (Route route : list) {
Endpoint key = route.getEndpoint();
assertEquals("From endpoint", "seda://a", key.getEndpointUri());
EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
Processor processor = consumerRoute.getProcessor();
Channel channel = unwrapChannel(processor);
DeadLetterChannel deadLetterChannel = assertIsInstanceOf(DeadLetterChannel.class, channel.getErrorHandler());
RedeliveryPolicy redeliveryPolicy = deadLetterChannel.getRedeliveryPolicy();
assertEquals("getMaximumRedeliveries()", 2, redeliveryPolicy.getMaximumRedeliveries());
assertEquals("isUseExponentialBackOff()", true, redeliveryPolicy.isUseExponentialBackOff());
}
}
Aggregations