Search in sources :

Example 16 with SendProcessor

use of org.apache.camel.processor.SendProcessor in project camel by apache.

the class RouteBuilderTest method testIdempotentConsumer.

public void testIdempotentConsumer() throws Exception {
    List<Route> routes = buildIdempotentConsumer();
    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());
        IdempotentConsumer idempotentConsumer = assertIsInstanceOf(IdempotentConsumer.class, channel.getNextProcessor());
        assertEquals("messageIdExpression", "header(myMessageId)", idempotentConsumer.getMessageIdExpression().toString());
        assertIsInstanceOf(MemoryIdempotentRepository.class, idempotentConsumer.getIdempotentRepository());
        SendProcessor sendProcessor = assertIsInstanceOf(SendProcessor.class, unwrapChannel(idempotentConsumer.getProcessor()).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) IdempotentConsumer(org.apache.camel.processor.idempotent.IdempotentConsumer) SendProcessor(org.apache.camel.processor.SendProcessor) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Example 17 with SendProcessor

use of org.apache.camel.processor.SendProcessor in project camel by apache.

the class ContextErrorHandlerTest method testOverloadingTheDefaultErrorHandler.

public void testOverloadingTheDefaultErrorHandler() throws Exception {
    RouteBuilder builder = new RouteBuilder() {

        public void configure() {
            errorHandler(loggingErrorHandler("FOO.BAR"));
            from("seda:a").to("seda:b");
        }
    };
    List<Route> list = getRouteListWithCurrentContext(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);
        assertIsInstanceOf(LoggingErrorHandler.class, channel.getErrorHandler());
        SendProcessor sendProcessor = assertIsInstanceOf(SendProcessor.class, channel.getNextProcessor());
        log.debug("Found sendProcessor: " + sendProcessor);
    }
}
Also used : Processor(org.apache.camel.Processor) 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) SendProcessor(org.apache.camel.processor.SendProcessor) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Example 18 with SendProcessor

use of org.apache.camel.processor.SendProcessor in project camel by apache.

the class AggregateProcessorTest method testAggregateUseBatchSizeFromConsumer.

public void testAggregateUseBatchSizeFromConsumer() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("A+B", "C+D+E");
    mock.expectedPropertyReceived(Exchange.AGGREGATED_COMPLETED_BY, "consumer");
    Processor done = new SendProcessor(context.getEndpoint("mock:result"));
    Expression corr = header("id");
    AggregationStrategy as = new BodyInAggregatingStrategy();
    AggregateProcessor ap = new AggregateProcessor(context, done, corr, as, executorService, true);
    ap.setCompletionSize(100);
    ap.setCompletionFromBatchConsumer(true);
    ap.start();
    Exchange e1 = new DefaultExchange(context);
    e1.getIn().setBody("A");
    e1.getIn().setHeader("id", 123);
    e1.setProperty(Exchange.BATCH_INDEX, 0);
    e1.setProperty(Exchange.BATCH_SIZE, 2);
    e1.setProperty(Exchange.BATCH_COMPLETE, false);
    Exchange e2 = new DefaultExchange(context);
    e2.getIn().setBody("B");
    e2.getIn().setHeader("id", 123);
    e2.setProperty(Exchange.BATCH_INDEX, 1);
    e2.setProperty(Exchange.BATCH_SIZE, 2);
    e2.setProperty(Exchange.BATCH_COMPLETE, true);
    Exchange e3 = new DefaultExchange(context);
    e3.getIn().setBody("C");
    e3.getIn().setHeader("id", 123);
    e3.setProperty(Exchange.BATCH_INDEX, 0);
    e3.setProperty(Exchange.BATCH_SIZE, 3);
    e3.setProperty(Exchange.BATCH_COMPLETE, false);
    Exchange e4 = new DefaultExchange(context);
    e4.getIn().setBody("D");
    e4.getIn().setHeader("id", 123);
    e4.setProperty(Exchange.BATCH_INDEX, 1);
    e4.setProperty(Exchange.BATCH_SIZE, 3);
    e4.setProperty(Exchange.BATCH_COMPLETE, false);
    Exchange e5 = new DefaultExchange(context);
    e5.getIn().setBody("E");
    e5.getIn().setHeader("id", 123);
    e5.setProperty(Exchange.BATCH_INDEX, 2);
    e5.setProperty(Exchange.BATCH_SIZE, 3);
    e5.setProperty(Exchange.BATCH_COMPLETE, true);
    ap.process(e1);
    ap.process(e2);
    ap.process(e3);
    ap.process(e4);
    ap.process(e5);
    assertMockEndpointsSatisfied();
    ap.stop();
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) SendProcessor(org.apache.camel.processor.SendProcessor) Processor(org.apache.camel.Processor) AggregateProcessor(org.apache.camel.processor.aggregate.AggregateProcessor) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Expression(org.apache.camel.Expression) BodyInAggregatingStrategy(org.apache.camel.processor.BodyInAggregatingStrategy) SendProcessor(org.apache.camel.processor.SendProcessor) AggregationStrategy(org.apache.camel.processor.aggregate.AggregationStrategy) AggregateProcessor(org.apache.camel.processor.aggregate.AggregateProcessor)

Example 19 with SendProcessor

use of org.apache.camel.processor.SendProcessor in project camel by apache.

the class AggregateProcessorTest method doTestAggregateLogFailedExchange.

private void doTestAggregateLogFailedExchange(ExceptionHandler handler) throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("A+END");
    Processor done = new Processor() {

        public void process(Exchange exchange) throws Exception {
            if (exchange.getIn().getBody(String.class).contains("Kaboom")) {
                throw new IllegalArgumentException("Damn");
            }
            // else send it further along
            SendProcessor send = new SendProcessor(context.getEndpoint("mock:result"));
            send.start();
            send.process(exchange);
        }
    };
    Expression corr = header("id");
    AggregationStrategy as = new BodyInAggregatingStrategy();
    AggregateProcessor ap = new AggregateProcessor(context, done, corr, as, executorService, true);
    ap.setEagerCheckCompletion(true);
    ap.setCompletionPredicate(body().isEqualTo("END"));
    if (handler != null) {
        ap.setExceptionHandler(handler);
    }
    ap.start();
    Exchange e1 = new DefaultExchange(context);
    e1.getIn().setBody("A");
    e1.getIn().setHeader("id", 123);
    Exchange e2 = new DefaultExchange(context);
    e2.getIn().setBody("B");
    e2.getIn().setHeader("id", 456);
    Exchange e3 = new DefaultExchange(context);
    e3.getIn().setBody("Kaboom");
    e3.getIn().setHeader("id", 456);
    Exchange e4 = new DefaultExchange(context);
    e4.getIn().setBody("END");
    e4.getIn().setHeader("id", 456);
    Exchange e5 = new DefaultExchange(context);
    e5.getIn().setBody("END");
    e5.getIn().setHeader("id", 123);
    ap.process(e1);
    ap.process(e2);
    ap.process(e3);
    ap.process(e4);
    ap.process(e5);
    assertMockEndpointsSatisfied();
    ap.stop();
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) SendProcessor(org.apache.camel.processor.SendProcessor) Processor(org.apache.camel.Processor) AggregateProcessor(org.apache.camel.processor.aggregate.AggregateProcessor) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Expression(org.apache.camel.Expression) BodyInAggregatingStrategy(org.apache.camel.processor.BodyInAggregatingStrategy) SendProcessor(org.apache.camel.processor.SendProcessor) AggregationStrategy(org.apache.camel.processor.aggregate.AggregationStrategy) AggregateProcessor(org.apache.camel.processor.aggregate.AggregateProcessor)

Example 20 with SendProcessor

use of org.apache.camel.processor.SendProcessor in project camel by apache.

the class AggregateProcessorTest method testAggregateIgnoreInvalidCorrelationKey.

public void testAggregateIgnoreInvalidCorrelationKey() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("A+C+END");
    Processor done = new SendProcessor(context.getEndpoint("mock:result"));
    Expression corr = header("id");
    AggregationStrategy as = new BodyInAggregatingStrategy();
    Predicate complete = body().contains("END");
    AggregateProcessor ap = new AggregateProcessor(context, done, corr, as, executorService, true);
    ap.setCompletionPredicate(complete);
    ap.setIgnoreInvalidCorrelationKeys(true);
    ap.start();
    Exchange e1 = new DefaultExchange(context);
    e1.getIn().setBody("A");
    e1.getIn().setHeader("id", 123);
    Exchange e2 = new DefaultExchange(context);
    e2.getIn().setBody("B");
    Exchange e3 = new DefaultExchange(context);
    e3.getIn().setBody("C");
    e3.getIn().setHeader("id", 123);
    Exchange e4 = new DefaultExchange(context);
    e4.getIn().setBody("END");
    e4.getIn().setHeader("id", 123);
    ap.process(e1);
    ap.process(e2);
    ap.process(e3);
    ap.process(e4);
    assertMockEndpointsSatisfied();
    ap.stop();
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) SendProcessor(org.apache.camel.processor.SendProcessor) Processor(org.apache.camel.Processor) AggregateProcessor(org.apache.camel.processor.aggregate.AggregateProcessor) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Expression(org.apache.camel.Expression) BodyInAggregatingStrategy(org.apache.camel.processor.BodyInAggregatingStrategy) SendProcessor(org.apache.camel.processor.SendProcessor) AggregationStrategy(org.apache.camel.processor.aggregate.AggregationStrategy) Predicate(org.apache.camel.Predicate) AggregateProcessor(org.apache.camel.processor.aggregate.AggregateProcessor)

Aggregations

SendProcessor (org.apache.camel.processor.SendProcessor)27 Processor (org.apache.camel.Processor)17 AggregateProcessor (org.apache.camel.processor.aggregate.AggregateProcessor)15 Exchange (org.apache.camel.Exchange)14 Expression (org.apache.camel.Expression)14 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)14 DefaultExchange (org.apache.camel.impl.DefaultExchange)14 BodyInAggregatingStrategy (org.apache.camel.processor.BodyInAggregatingStrategy)14 AggregationStrategy (org.apache.camel.processor.aggregate.AggregationStrategy)14 Endpoint (org.apache.camel.Endpoint)7 Predicate (org.apache.camel.Predicate)5 Channel (org.apache.camel.Channel)4 Route (org.apache.camel.Route)4 EventDrivenConsumerRoute (org.apache.camel.impl.EventDrivenConsumerRoute)4 DeadLetterChannel (org.apache.camel.processor.DeadLetterChannel)4 ProcessorTransformer (org.apache.camel.impl.transformer.ProcessorTransformer)2 Field (java.lang.reflect.Field)1 Iterator (java.util.Iterator)1 ExecutorService (java.util.concurrent.ExecutorService)1 CamelContext (org.apache.camel.CamelContext)1