Search in sources :

Example 11 with EventDrivenConsumerRoute

use of org.apache.camel.impl.EventDrivenConsumerRoute in project camel by apache.

the class ErrorHandlerTest method testLoggingErrorHandler.

public void testLoggingErrorHandler() throws Exception {
    // START SNIPPET: e5
    RouteBuilder builder = new RouteBuilder() {

        public void configure() {
            from("seda:a").errorHandler(loggingErrorHandler("FOO.BAR")).filter(body().isInstanceOf(String.class)).to("seda:b");
        }
    };
    // END SNIPPET: e5
    List<Route> routes = getRouteList(builder);
    assertEquals("Number routes created", 1, routes.size());
    for (Route route : routes) {
        Endpoint key = route.getEndpoint();
        assertEquals("From endpoint", "seda://a", key.getEndpointUri());
        EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
        Channel channel = unwrapChannel(consumerRoute.getProcessor());
        assertIsInstanceOf(LoggingErrorHandler.class, channel.getErrorHandler());
        assertIsInstanceOf(FilterProcessor.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 12 with EventDrivenConsumerRoute

use of org.apache.camel.impl.EventDrivenConsumerRoute 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)

Example 13 with EventDrivenConsumerRoute

use of org.apache.camel.impl.EventDrivenConsumerRoute in project camel by apache.

the class ErrorHandlerTest method testOverloadingTheDefaultErrorHandler.

public void testOverloadingTheDefaultErrorHandler() throws Exception {
    // START SNIPPET: e1
    RouteBuilder builder = new RouteBuilder() {

        public void configure() {
            // use logging error handler
            errorHandler(loggingErrorHandler("com.mycompany.foo"));
            // here is our regular route
            from("seda:a").to("seda:b");
        }
    };
    // END SNIPPET: e1
    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(LoggingErrorHandler.class, channel.getErrorHandler());
        Processor processor = unwrap(channel.getNextProcessor());
        assertIsInstanceOf(SendProcessor.class, processor);
    }
}
Also used : Processor(org.apache.camel.Processor) FilterProcessor(org.apache.camel.processor.FilterProcessor) SendProcessor(org.apache.camel.processor.SendProcessor) 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 14 with EventDrivenConsumerRoute

use of org.apache.camel.impl.EventDrivenConsumerRoute in project camel by apache.

the class RouteBuilderTest method getProcessorWithoutErrorHandler.

/**
     * By default routes should be wrapped in the {@link DeadLetterChannel} so
     * lets unwrap that and return the actual processor
     */
protected Processor getProcessorWithoutErrorHandler(Route route) {
    EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
    Processor processor = unwrap(consumerRoute.getProcessor());
    return unwrapErrorHandler(processor);
}
Also used : DelegateProcessor(org.apache.camel.DelegateProcessor) Processor(org.apache.camel.Processor) MulticastProcessor(org.apache.camel.processor.MulticastProcessor) FilterProcessor(org.apache.camel.processor.FilterProcessor) EvaluateExpressionProcessor(org.apache.camel.processor.EvaluateExpressionProcessor) ThreadsProcessor(org.apache.camel.processor.ThreadsProcessor) SendProcessor(org.apache.camel.processor.SendProcessor) ChoiceProcessor(org.apache.camel.processor.ChoiceProcessor) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Example 15 with EventDrivenConsumerRoute

use of org.apache.camel.impl.EventDrivenConsumerRoute in project camel by apache.

the class RouteBuilderTest method testSimpleRoute.

public void testSimpleRoute() throws Exception {
    List<Route> routes = buildSimpleRoute();
    assertEquals("Number routes created", 1, routes.size());
    for (Route route : routes) {
        Endpoint key = route.getEndpoint();
        assertEquals("From endpoint", "direct://a", key.getEndpointUri());
        EventDrivenConsumerRoute consumer = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
        Channel channel = unwrapChannel(consumer.getProcessor());
        SendProcessor sendProcessor = assertIsInstanceOf(SendProcessor.class, channel.getNextProcessor());
        assertEquals("Endpoint URI", "direct://b", sendProcessor.getDestination().getEndpointUri());
    }
}
Also used : Endpoint(org.apache.camel.Endpoint) Channel(org.apache.camel.Channel) DeadLetterChannel(org.apache.camel.processor.DeadLetterChannel) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) SendProcessor(org.apache.camel.processor.SendProcessor) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Aggregations

EventDrivenConsumerRoute (org.apache.camel.impl.EventDrivenConsumerRoute)23 Route (org.apache.camel.Route)21 Channel (org.apache.camel.Channel)17 Endpoint (org.apache.camel.Endpoint)15 DeadLetterChannel (org.apache.camel.processor.DeadLetterChannel)15 Processor (org.apache.camel.Processor)13 SendProcessor (org.apache.camel.processor.SendProcessor)12 FilterProcessor (org.apache.camel.processor.FilterProcessor)8 DelegateProcessor (org.apache.camel.DelegateProcessor)6 ChoiceProcessor (org.apache.camel.processor.ChoiceProcessor)5 EvaluateExpressionProcessor (org.apache.camel.processor.EvaluateExpressionProcessor)5 MulticastProcessor (org.apache.camel.processor.MulticastProcessor)5 ThreadsProcessor (org.apache.camel.processor.ThreadsProcessor)5 Pipeline (org.apache.camel.processor.Pipeline)3 RedeliveryPolicy (org.apache.camel.processor.RedeliveryPolicy)3 ArrayList (java.util.ArrayList)2 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)2 JMException (javax.management.JMException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 CamelContext (org.apache.camel.CamelContext)1