Search in sources :

Example 56 with Route

use of org.apache.camel.Route 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 57 with Route

use of org.apache.camel.Route 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 58 with Route

use of org.apache.camel.Route 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 59 with Route

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

Example 60 with Route

use of org.apache.camel.Route in project camel by apache.

the class RouteBuilderTest method testWireTap.

public void testWireTap() throws Exception {
    List<Route> routes = buildWireTap();
    log.debug("Created routes: " + routes);
    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());
        MulticastProcessor multicastProcessor = assertIsInstanceOf(MulticastProcessor.class, channel.getNextProcessor());
        List<Processor> endpoints = new ArrayList<Processor>(multicastProcessor.getProcessors());
        assertEquals("Should have 2 endpoints", 2, endpoints.size());
        assertSendToProcessor(unwrapChannel(endpoints.get(0)).getNextProcessor(), "direct://tap");
        assertSendToProcessor(unwrapChannel(endpoints.get(1)).getNextProcessor(), "direct://b");
    }
}
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) Endpoint(org.apache.camel.Endpoint) Channel(org.apache.camel.Channel) DeadLetterChannel(org.apache.camel.processor.DeadLetterChannel) ArrayList(java.util.ArrayList) MulticastProcessor(org.apache.camel.processor.MulticastProcessor) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Aggregations

Route (org.apache.camel.Route)90 EventDrivenConsumerRoute (org.apache.camel.impl.EventDrivenConsumerRoute)27 Endpoint (org.apache.camel.Endpoint)24 Channel (org.apache.camel.Channel)17 DeadLetterChannel (org.apache.camel.processor.DeadLetterChannel)15 Processor (org.apache.camel.Processor)13 ArrayList (java.util.ArrayList)12 SendProcessor (org.apache.camel.processor.SendProcessor)11 CamelContext (org.apache.camel.CamelContext)10 ShutdownRoute (org.apache.camel.ShutdownRoute)8 FilterProcessor (org.apache.camel.processor.FilterProcessor)7 RoutePolicy (org.apache.camel.spi.RoutePolicy)6 HashMap (java.util.HashMap)5 Service (org.apache.camel.Service)5 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 DelegateProcessor (org.apache.camel.DelegateProcessor)4 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)4 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)4