Search in sources :

Example 1 with UseLatestAggregationStrategy

use of org.apache.camel.processor.aggregate.UseLatestAggregationStrategy in project camel by apache.

the class SplitterParallelIssueTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").log("Start ${body}").split(body().tokenize("@"), new UseLatestAggregationStrategy()).parallelProcessing().streaming().process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    int num = exchange.getIn().getBody(int.class);
                    final long sleep = num * delay;
                    log.info("Sleep for " + sleep + "ms");
                    Thread.sleep(sleep);
                }
            }).end().log("End ${body}").to("mock:end");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) UseLatestAggregationStrategy(org.apache.camel.processor.aggregate.UseLatestAggregationStrategy) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 2 with UseLatestAggregationStrategy

use of org.apache.camel.processor.aggregate.UseLatestAggregationStrategy in project camel by apache.

the class AggregatorExceptionInPredicateTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            onException(IllegalArgumentException.class).handled(true).to("mock:handled");
            from("direct:start").aggregate(header("id")).completionTimeout(500).aggregationStrategy(new AggregationStrategy() {

                public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
                    Object body = newExchange.getIn().getBody();
                    if ("Damn".equals(body)) {
                        throw new IllegalArgumentException();
                    }
                    return newExchange;
                }
            }).to("mock:result");
            from("direct:predicate").aggregate(new Expression() {

                public <T> T evaluate(Exchange exchange, Class<T> type) {
                    if (exchange.getIn().getBody().equals("Damn")) {
                        throw new IllegalArgumentException();
                    }
                    return ExpressionBuilder.headerExpression("id").evaluate(exchange, type);
                }
            }, new UseLatestAggregationStrategy()).completionTimeout(500).to("mock:result");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) RouteBuilder(org.apache.camel.builder.RouteBuilder) Expression(org.apache.camel.Expression) UseLatestAggregationStrategy(org.apache.camel.processor.aggregate.UseLatestAggregationStrategy) AggregationStrategy(org.apache.camel.processor.aggregate.AggregationStrategy) UseLatestAggregationStrategy(org.apache.camel.processor.aggregate.UseLatestAggregationStrategy)

Example 3 with UseLatestAggregationStrategy

use of org.apache.camel.processor.aggregate.UseLatestAggregationStrategy in project camel by apache.

the class AggregatorTest method createRouteBuilder.

protected RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {

        public void configure() {
            // START SNIPPET: ex
            // in this route we aggregate all from direct:state based on the header id cheese
            from("direct:start").aggregate(header("cheese"), new UseLatestAggregationStrategy()).completionTimeout(1000L).to("mock:result");
            from("seda:header").setHeader("visited", constant(true)).aggregate(header("cheese"), new UseLatestAggregationStrategy()).completionTimeout(1000L).to("mock:result");
            // in this sample we aggregate with a completion predicate
            from("direct:predicate").aggregate(header("cheese"), new UseLatestAggregationStrategy()).completionTimeout(1000L).completionPredicate(header("cheese").isEqualTo(123)).to("mock:result");
        // END SNIPPET: ex
        }
    };
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) UseLatestAggregationStrategy(org.apache.camel.processor.aggregate.UseLatestAggregationStrategy)

Example 4 with UseLatestAggregationStrategy

use of org.apache.camel.processor.aggregate.UseLatestAggregationStrategy in project camel by apache.

the class AsyncEndpointSplitUseLatestAggregationStrategyTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            context.addComponent("async", new MyAsyncComponent());
            from("direct:start").split(body(), new UseLatestAggregationStrategy()).to("mock:before").to("log:before").process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    beforeThreadName = Thread.currentThread().getName();
                }
            }).to("async:bye:camel").process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    afterThreadName = Thread.currentThread().getName();
                }
            }).to("log:after").to("mock:after").end().to("mock:result");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) UseLatestAggregationStrategy(org.apache.camel.processor.aggregate.UseLatestAggregationStrategy)

Example 5 with UseLatestAggregationStrategy

use of org.apache.camel.processor.aggregate.UseLatestAggregationStrategy in project camel by apache.

the class AggregratedJmsRouteTest method createRouteBuilder.

protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        public void configure() throws Exception {
            from(timeOutEndpointUri).to("jms:queue:test.b");
            from("jms:queue:test.b").aggregate(header("cheese"), new AggregationStrategy() {

                public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        LOG.error("aggregration delay sleep inturrepted", e);
                        fail("aggregration delay sleep inturrepted");
                    }
                    return newExchange;
                }
            }).completionTimeout(2000L).to("mock:result");
            from(multicastEndpointUri).to("jms:queue:point1", "jms:queue:point2", "jms:queue:point3");
            from("jms:queue:point1").process(new MyProcessor()).to("jms:queue:reply");
            from("jms:queue:point2").process(new MyProcessor()).to("jms:queue:reply");
            from("jms:queue:point3").process(new MyProcessor()).to("jms:queue:reply");
            from("jms:queue:reply").aggregate(header("cheese"), new UseLatestAggregationStrategy()).completionSize(3).to("mock:reply");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) RouteBuilder(org.apache.camel.builder.RouteBuilder) UseLatestAggregationStrategy(org.apache.camel.processor.aggregate.UseLatestAggregationStrategy) UseLatestAggregationStrategy(org.apache.camel.processor.aggregate.UseLatestAggregationStrategy) AggregationStrategy(org.apache.camel.processor.aggregate.AggregationStrategy)

Aggregations

UseLatestAggregationStrategy (org.apache.camel.processor.aggregate.UseLatestAggregationStrategy)8 RouteBuilder (org.apache.camel.builder.RouteBuilder)6 Exchange (org.apache.camel.Exchange)5 Processor (org.apache.camel.Processor)3 JndiRegistry (org.apache.camel.impl.JndiRegistry)2 AggregationStrategy (org.apache.camel.processor.aggregate.AggregationStrategy)2 Expression (org.apache.camel.Expression)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1