Search in sources :

Example 11 with Channel

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

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

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

use of org.apache.camel.Channel 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 15 with Channel

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

Channel (org.apache.camel.Channel)21 Route (org.apache.camel.Route)17 EventDrivenConsumerRoute (org.apache.camel.impl.EventDrivenConsumerRoute)17 DeadLetterChannel (org.apache.camel.processor.DeadLetterChannel)15 Endpoint (org.apache.camel.Endpoint)13 Processor (org.apache.camel.Processor)12 SendProcessor (org.apache.camel.processor.SendProcessor)10 FilterProcessor (org.apache.camel.processor.FilterProcessor)6 ArrayList (java.util.ArrayList)3 DelegateProcessor (org.apache.camel.DelegateProcessor)3 ChoiceProcessor (org.apache.camel.processor.ChoiceProcessor)3 EvaluateExpressionProcessor (org.apache.camel.processor.EvaluateExpressionProcessor)3 MulticastProcessor (org.apache.camel.processor.MulticastProcessor)3 RedeliveryPolicy (org.apache.camel.processor.RedeliveryPolicy)3 ThreadsProcessor (org.apache.camel.processor.ThreadsProcessor)3 Pipeline (org.apache.camel.processor.Pipeline)2 Consumer (org.apache.camel.Consumer)1 NonManagedService (org.apache.camel.NonManagedService)1 Producer (org.apache.camel.Producer)1 Service (org.apache.camel.Service)1