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");
}
};
}
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");
}
};
}
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
}
};
}
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");
}
};
}
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");
}
};
}
Aggregations