Search in sources :

Example 1 with DeadLetterChannel

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;
}
Also used : DeadLetterChannel(org.apache.camel.processor.DeadLetterChannel)

Example 2 with DeadLetterChannel

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());
    }
}
Also used : Endpoint(org.apache.camel.Endpoint) Channel(org.apache.camel.Channel) DeadLetterChannel(org.apache.camel.processor.DeadLetterChannel) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Example 3 with DeadLetterChannel

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());
    }
}
Also used : Processor(org.apache.camel.Processor) SendProcessor(org.apache.camel.processor.SendProcessor) DeadLetterChannel(org.apache.camel.processor.DeadLetterChannel) Channel(org.apache.camel.Channel) DeadLetterChannel(org.apache.camel.processor.DeadLetterChannel) RedeliveryPolicy(org.apache.camel.processor.RedeliveryPolicy) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Example 4 with DeadLetterChannel

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());
    }
}
Also used : DeadLetterChannel(org.apache.camel.processor.DeadLetterChannel) Channel(org.apache.camel.Channel) DeadLetterChannel(org.apache.camel.processor.DeadLetterChannel) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) RedeliveryPolicy(org.apache.camel.processor.RedeliveryPolicy) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Example 5 with DeadLetterChannel

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());
    }
}
Also used : Processor(org.apache.camel.Processor) FilterProcessor(org.apache.camel.processor.FilterProcessor) SendProcessor(org.apache.camel.processor.SendProcessor) Endpoint(org.apache.camel.Endpoint) DeadLetterChannel(org.apache.camel.processor.DeadLetterChannel) Channel(org.apache.camel.Channel) DeadLetterChannel(org.apache.camel.processor.DeadLetterChannel) RedeliveryPolicy(org.apache.camel.processor.RedeliveryPolicy) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Aggregations

DeadLetterChannel (org.apache.camel.processor.DeadLetterChannel)5 Channel (org.apache.camel.Channel)4 Route (org.apache.camel.Route)4 EventDrivenConsumerRoute (org.apache.camel.impl.EventDrivenConsumerRoute)4 RedeliveryPolicy (org.apache.camel.processor.RedeliveryPolicy)3 Endpoint (org.apache.camel.Endpoint)2 Processor (org.apache.camel.Processor)2 SendProcessor (org.apache.camel.processor.SendProcessor)2 FilterProcessor (org.apache.camel.processor.FilterProcessor)1 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)1