My project need a split then aggregate operation rather than the integrated split+aggregate but I don't have any clue about how propagate an exception to stop further processing.
In the example below I'll need to be able to not make the last log if an exception was thrown in post aggregation.
@RunWith(SpringJUnit4ClassRunner.class)
public class AggregationExceptionTest extends CamelTestSupport {
private final Logger LOGGER = LoggerFactory.getLogger(AggregationExceptionTest.class);
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start")
.split(body()).streaming().stopOnException().parallelProcessing()
.aggregate(new AggregationStrategy() {
@Override
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
if (newExchange.getException() != null) {
LOGGER.info("exception propagated");
}
return oldExchange==null?newExchange:oldExchange;
}
}).constant(true)
.completionSize(1).completionTimeout(500)
.log(LoggingLevel.INFO, LOGGER, "Aggreg ${body}")
.throwException(Exception.class, "propagate plz")
.end()
.end()
.process(e -> {
LOGGER.info("I don't want to be seen, because of {}", e.getException());
});
}
};
}
@Test
public void test1() throws InterruptedException {
template.sendBody("direct:start", Arrays.asList("A", "B", "C", "D"));
Thread.sleep(5000);
}
}
The exception thrown is never visible in the aggregate method.