Stop processing in case of exception

Talend ESB Mediation Developer Guide

EnrichVersion
6.2
EnrichProdName
Talend ESB
task
Design and Development
Installation and Upgrade
EnrichPlatform
Talend ESB

The Multicast will by default continue to process the entire Exchange even in case one of the multicasted messages will throw an exception during routing. For example if you want to multicast to 3 destinations and the second destination fails by an exception. What Camel does by default is to process the remainder destinations. You have the chance to remedy or handle this in the AggregationStrategy.

But sometimes you just want Camel to stop and let the exception be propagated back, and let the Camel error handler handle it. You can do this by specifying that it should stop in case of an exception occurred. This is done by the stopOnException option as shown below:

from("direct:start")
   .multicast()
      .stopOnException().to("direct:foo", "direct:bar", "direct:baz")
   .end()
   .to("mock:result");
   from("direct:foo").to("mock:foo");
   from("direct:bar").process(new MyProcessor()).to("mock:bar");
   from("direct:baz").to("mock:baz");

And using XML DSL you specify it as follows:

<route>
    <from uri="direct:start"/>
    <multicast stopOnException="true">
        <to uri="direct:foo"/>
        <to uri="direct:bar"/>
        <to uri="direct:baz"/>
    </multicast>
    <to uri="mock:result"/>
</route>

<route>
    <from uri="direct:foo"/>
    <to uri="mock:foo"/>
</route>

<route>
    <from uri="direct:bar"/>
    <process ref="myProcessor"/>
    <to uri="mock:bar"/>
</route>

<route>
    <from uri="direct:baz"/>
    <to uri="mock:baz"/>
</route>