You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Sven Bauhan <sv...@ast.dfs.de> on 2013/04/22 12:14:05 UTC
Error propagation in route
Hi,
I try to understand how to handle with errors in messages within a camel
route.
I have the following route in a Camel context component:
FailureReceiveProcessor fails = new FailureReceiveProcessor();
onException(MessageReceiveException.class).handled(false).process(fails);
onException(MessageAggregateException.class).handled(true).process(fails);
onException(NumberFormatException.class).handled(true).process(fails);
onException(UnmarshalException.class).handled(true).process(fails);
onException(ClosedCorrelationKeyException.class).handled(true).process(fails);
from(Endpoints.SEGMENT_IN.seda())
.process(first_check)
.unmarshal(usedFormat)
.process(bean2msg)
.choice()
.when(header(HeaderKeys.TYPE.key()).isEqualTo(MSG.UserMessageType.RESP.toString()))
.process(send_controller)
.otherwise()
.aggregate(header(HeaderKeys.MID.key()),
aggregation).completionPredicate(aggregation)
.closeCorrelationKeyOnCompletion(CLOSED_CORRELATION_KEY_CACHE_SIZE)
.completionTimeout(getT_seg()).discardOnCompletionTimeout()
.to(Endpoints.MESSAGE_OUT.seda());
In the process bean2msg I check the unmarshalled message and put the
meta data into headers of the camel message and the payload in the body.
When the message is incorrect I throw a MessageReceiveException.
The pitfall is that the aggregator has be informed of the incorrect
message; cause if one segment of a message is incorrect, the previous
segments shall be withdrawn and the sender sends all segments again.
The exception handling onException(MessageReceiveException) can be set
to false, but this means the exception is propagated to the application.
If it is set handled(true), the exception will not be propagated, but
also the message is not routed further to the aggregator.
Another way could be to set the fault flag on the Message; but I did not
understand the concept completely yet.
If I set msg.setFault() in the bean2msg Processor, is the message routed
to the aggregator? Can I ask msg.isFault() then and throw the
MessageAggregatorException there?
Another idea is to set a property on the Exchange or a special header
field on the Message. But I think this would be a misuse of the Camel
error handling strategy.
Thanks for advices,
Sven