You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Bernard Ligny <be...@gmail.com> on 2013/04/29 12:18:09 UTC
Conditional route-scoped onException
I am trying to model the following logic for the error handling of one single
specific route.
1. Post a (large) xml document
2. If the post failed, then split original xml into into n smaller
documents, and repost them (step 1) individually.
That kind of recursive process needs of course a stopping condition (size of
batch > 1)
<route id="processBatch">
<from uri="activemq:queue:solr-batches"/>
<choice>
<when>
<simple>${headers.batch_size} > 1</simple>
<onException>
<exception>java.lang.Exception</exception>
<handled><constant>true</constant></handled>
<to uri="direct:splitAndResubmit"/>
</onException>
</when>
</choice>
<to uri="http:..."/>
</route>
According to the my observations, it seems the uri "direct:splitAndResubmit"
is *always* called.
So the question is: is this allowed to have such logic, i mean a
<onException> inside a <choice>
- or should it always directly follow a <from> element ?
Thx,
Bernard.
--
View this message in context: http://camel.465427.n5.nabble.com/Conditional-route-scoped-onException-tp5731725.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Conditional route-scoped onException
Posted by Bernard Ligny <be...@gmail.com>.
Okay, i've just found a fully working solution. It is surely not the most
elegant one (as some code is repeated), but at least it works as expected...
The workaround consists in replacing the doCatch/onWhen (of previous post)
with an outer choice whose one branch contains the try/catch:
<route id="processUpdateBatch" errorHandlerRef="DLQ_solr_batches">
<from uri="activemq:queue:solr-batches"/>
<choice>
<when>
<simple>${headers.batch_size} > 1</simple>
<doTry>
<to uri="http:..."/>
<doCatch>
<exception>java.lang.Exception</exception>
<to uri="direct:splitAndResubmit"/>
</doCatch>
</doTry>
</when>
<otherwise>
<to uri="http:..."/>
</otherwise>
</choice>
</route>
Hoping this post could help someone else...
Regards,
Bernard.
NB: I'm still interested in knowing/understanding why previous attempts did
not work.
--
View this message in context: http://camel.465427.n5.nabble.com/Conditional-route-scoped-onException-tp5731725p5731789.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Conditional route-scoped onException
Posted by Bernard Ligny <be...@gmail.com>.
I finally managed to rewrite my route using a conditional try-catch (ie with
<onWhen>):
<route id="processUpdateBatch" errorHandlerRef="DLQ_solr_batches">
<from uri="activemq:queue:solr-batches"/>
<doTry>
<to uri=""http:..."/>
<doCatch>
<exception>java.lang.Exception</exception>
<onWhen>
<simple>${headers.batch_size} > 1</simple>
</onWhen>
<to uri="direct:splitAndResubmit"/>
</doCatch>
</doTry>
</route>
The only remaining (and serious) problem I am facing, is that the exchange
is *NOT* put in my DQL when the onWhen predicate is not satisfied (I guess
the handled flag is set by default to true in a try-catch ?)
But how can I model the following behaviour:
a) if (exception) AND (batch_size>1) : do a specific process (here:
splitAndResubmit) and silently ignore error
b) if (exception) AND (batch_size=1) : use the error handler specified on
the route level (in my case a DeadLetterChannel with a redeliveryPolicy) ?
In my solution, a) is working fine, but not b)
--
View this message in context: http://camel.465427.n5.nabble.com/Conditional-route-scoped-onException-tp5731725p5731779.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Conditional route-scoped onException
Posted by Bernard Ligny <be...@gmail.com>.
I aslo tried to rewrite the route as:
<route id="processBatch" errorHandlerRef="DLQ_solr_batches">
<from uri="activemq:queue:solr-batches"/>
<onException>
<exception>java.lang.Exception</exception>
<choice>
<when>
<simple>${headers.batch_size} > 1</simple>
<handled><constant>true</constant></handled>
<to uri="direct:splitAndResubmit"/>
</when>
<otherwise>
<handled><constant>false</constant></handled>
</otherwise>
</choice>
</onException>
<to uri="http:..."/>
</route>
But this is not conform to xml schema :-(
--
View this message in context: http://camel.465427.n5.nabble.com/Conditional-route-scoped-onException-tp5731725p5731728.html
Sent from the Camel - Users mailing list archive at Nabble.com.