Camel's DoFinally block doesn't handle pipeline processing
Environment
- JBoss Fuse 6.0
Issue
If exception handling is enabled in Camel XML DSL, only the first processor from the
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/blueprint"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<bean id="myException" class="java.lang.RuntimeException">
<argument value="Booom" />
</bean>
<camelContext id="firstContext" trace="false" xmlns="http://camel.apache.org/schema/blueprint">
<route id="firstRoute">
<from uri="direct:start"/>
<doTry>
<to uri="direct-vm:generateException"/>
<doFinally>
<to uri="log:FIRST_FINALLY"/>
<to uri="log:SECOND_FINALLY"/>
</doFinally>
</doTry>
<to uri="mock:result"/>
</route>
</camelContext>
<camelContext id="secondContext" trace="false" xmlns="http://camel.apache.org/schema/blueprint">
<onException>
<exception>java.lang.Exception</exception>
<handled>
<constant>true</constant>
</handled>
</onException>
<route id="secondRoute">
<from uri="direct-vm:generateException"/>
<throwException ref="myException"/>
</route>
</camelContext>
</blueprint>
If you execute the Blueprint snippet above with Camel in version lower than 2.12.0, you will see only entry for FIRST_FINALLY logger and not for SECOND_FINALLY logger. Upgrading version of the Camel to 2.12.0 will result in both messages being printed.
Resolution
This bug has been fixed in Camel 2.12.0. If upgrade for the Camel 2.12.0 or above is not possible, the following workaround for the discussed issue could be considered - using multicast [1] instead of pipeline processing.
It is not always possible to replace pipeline processing with multicast pattern, however for some cases (in particular if messages in
<doFinally>
<multicast>
<to uri="log:FIRST_FINALLY"/>
<to uri="log:SECOND_FINALLY"/>
</multicast>
</doFinally>
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
