Reputation: 3783
I'm developing a project which involves Camel (version 2.15.3) dealing with files. I have some folders where messages come under the form of files that must be consumed, sent to a bean that performs some actions and then moved to the proper output folder.
In my camel-context.xml
file I assumed that the deadLetterErrorHandler
will be the strategy to deal with exceptions:
<bean id="deadLetterErrorHandler" class="org.apache.camel.builder.DeadLetterChannelBuilder" >
<property name="deadLetterUri" value="${deadLetterUri}"/>
</bean>
where deadLetterUri
resolves to a folder as well.
I also configured a route like this:
<route id="lpcMillenniumRoute">
<from uri="lpcMillenniumInputFolder"/>
<to uri="log:testLog" />
<to uri="bean:fileManagerService?method=manageXmlFile(${body.absoluteFilePath})"></to>
<to uri="lpcMillenniumOutputFolder"/>
</route>
The error route is configured as follows:
<route id="errorRoute">
<from ref="deadLetterUri" />
<log message="header.CamelFailureEndpoint = ${header.CamelFailureEndpoint}" loggingLevel="ERROR" />
<choice>
<when>
<simple>${header.CamelFailureEndpoint} == 'lpcMillenniumRoute'</simple>
<log message="Writing ${in.header[camelFileName]} to ${properties:lpcMillenniumErrorFolderUri}" loggingLevel="ERROR" />
<to uri="lpcMillenniumErrorFolder"/>
</when>
.....
The problem is that as soon as the bean throws an exception I would have expected the header.CamelFailureEndpoint
variable to be gracefully set to the value of which endpoint failed, as reported in the Camel dead letter channel documentation.
This kind of information is useful to me in order to correctly dispatch the message to the proper error folder.
Unfortunately the log I set always returns nothing.
Am I missing something?
Upvotes: 1
Views: 865
Reputation: 146
You mention that your deadLetterErrorHandler
saves the message on the filesystem. Then afterwards its picked up by the errorRoute
from the filesystem. This is a different exchange, so the failure and exception headers from the exchange that caused the error not available.
You can try to join the lpcMillenniumRoute
and the errorRoute
in the same camelcontext (if not already), and set up the deadLetterUri
with direct:dlc
and the Errorroute with <from uri="direct:dlc"/>
. Then the errorRoute
processes the same exchange that caused the error, and the camel failure and exception headers will be available.
Upvotes: 1