You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by nathanwray <na...@detroitsci.com> on 2014/10/15 21:36:40 UTC

onException and doTry

Hi all;

I have a global onException defined that I hoped would let me retry an
entire route twice using a setup like the following.  The issue that I see
is that route2 gets called an unlimited number of times until it succeeds.

Is this due to route2 having a doTry block inside?  Or am I missing
something else?

<onException useOriginalMessage="true">
<exception>org.apache.camel.ExchangeTimedOutException</exception>
<redeliveryPolicy maximumRedeliveries="2" redeliveryDelay="0"/>
<continued><constant>true</constant></continued>
<transform>//set an appropriate error result body
</transform>
</onException>

from route1, I call into route2:

<route id="1">
<to uri="direct:route2"/>
</route>

<route id="2" errorHandlerRef="disableErrorHandler">
<doTry>
//call a jetty route
<doCatch>
<exception>java.lang.Exception</exception>
<handled><constant>false</constant></handled>
// log some info into the database
</doCatch>
</doTry>
</route>

I see logging like the following:

2014-10-15 15:00:14,469 [CamelJettyClient(0xf6eec8e)-150] WARN 
jetty.client.HttpExchange EXPIRED JettyContentExchange@50e9cd46=POST// a url
here #SENDING(1ms)->EXPIRED(0ms)sent=1ms

2014-10-15 15:00:14,470 [CamelJettyClient(0xf6eec8e)-150] ERROR
route.vendor-md.doCatch Exception
org.apache.camel.ExchangeTimedOutException: The OUT message was not received
within: 100 millis. Exchange[Message:  a JSON message body here]
        at
org.apache.camel.component.jetty.JettyContentExchange.doTaskCompleted(JettyContentExchange.java:207)
        at
org.apache.camel.component.jetty.JettyContentExchange.onExpire(JettyContentExchange.java:130)
        at
org.eclipse.jetty.client.HttpExchange$Listener.onExpire(HttpExchange.java:1120)
        at
org.eclipse.jetty.client.HttpExchange.setStatusExpired(HttpExchange.java:384)
        at
org.eclipse.jetty.client.HttpExchange.setStatus(HttpExchange.java:267)
        at
org.eclipse.jetty.client.HttpExchange.expire(HttpExchange.java:130)
        at
org.eclipse.jetty.client.HttpExchange$1.expired(HttpExchange.java:1070)
        at org.eclipse.jetty.util.thread.Timeout.tick(Timeout.java:140)
        at org.eclipse.jetty.util.thread.Timeout.tick(Timeout.java:153)
        at org.eclipse.jetty.client.HttpClient$1.run(HttpClient.java:441)
        at
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
        at
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
        at java.lang.Thread.run(Thread.java:745)

2014-10-15 15:00:14,474 [Camel (camel-1) thread #10 -
ErrorHandlerRedeliveryTask] DEBUG route2  a debugging message here from
route2


Any thoughts?






--
View this message in context: http://camel.465427.n5.nabble.com/onException-and-doTry-tp5757602.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: onException and doTry

Posted by nathanwray <na...@detroitsci.com>.
A little further digging.  I added some debugging output to
incrementRedeliveryCounter and found the CamelRedeliveryCounter header is
missing on the redelivery attempt, I see the following:

2014-10-16 09:01:48,976 [CamelJettyClient(0x106898e3)-88] DEBUG
camel.processor.RedeliveryErrorHandler in incrementRedeliveryCounter
2014-10-16 09:01:48,976 [CamelJettyClient(0x106898e3)-88] DEBUG
camel.processor.RedeliveryErrorHandler !!! redelivery counter header was
NULL
2014-10-16 09:01:48,977 [CamelJettyClient(0x106898e3)-88] DEBUG
camel.processor.RedeliveryPolicy in shouldRedeliver, redeliveryCounter = 1
2014-10-16 09:01:48,977 [CamelJettyClient(0x106898e3)-88] DEBUG
camel.processor.RedeliveryPolicy maxRedeliveries is 2, returning true

inside route2, I had a statement that removed the Camel headers before
calling a remote web service (as recommended) so that Jetty doesn't get
tripped up by the old URI, URL settings:

			<removeHeaders pattern="Camel*"/>
			<to uri="jetty:{{vendor.uri}}?httpClient.timeout=100"/>

Apparently this destroys the redelivery count, removing it corrected the
issue.  I would consider this a defect that an inner route (with
useOriginalMessage=true) can destroy the redelivery count.

I changed it to:
			<removeHeaders pattern="Camel*" excludePattern="CamelRedeliveryCounter"/>

And the issue went away, it now redelivers twice and then fails as designed.





--
View this message in context: http://camel.465427.n5.nabble.com/onException-and-doTry-tp5757602p5757629.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: onException and doTry

Posted by nathanwray <na...@detroitsci.com>.
I added some debugging output into RedeliveryPolicy.java and confirmed that
it's not correctly incrementing redeliveryCounter.


2014-10-16 08:29:16,280 [CamelJettyClient(0x533bbc89)-59] DEBUG
camel.processor.RedeliveryPolicy in shouldRedeliver, *redeliveryCounter = 1*
2014-10-16 08:29:16,280 [CamelJettyClient(0x533bbc89)-59] DEBUG
camel.processor.RedeliveryPolicy maxRedeliveries is 2, returning true
...
2014-10-16 08:29:16,491 [CamelJettyClient(0x533bbc89)-59] DEBUG
camel.processor.RedeliveryPolicy in shouldRedeliver, *redeliveryCounter = 1*
2014-10-16 08:29:16,491 [CamelJettyClient(0x533bbc89)-59] DEBUG
camel.processor.RedeliveryPolicy maxRedeliveries is 2, returning true
...
2014-10-16 08:29:16,756 [CamelJettyClient(0x533bbc89)-59] DEBUG
camel.processor.RedeliveryPolicy in shouldRedeliver, *redeliveryCounter = 1*
2014-10-16 08:29:16,757 [CamelJettyClient(0x533bbc89)-59] DEBUG
camel.processor.RedeliveryPolicy maxRedeliveries is 2, returning true
...
and so on






--
View this message in context: http://camel.465427.n5.nabble.com/onException-and-doTry-tp5757602p5757627.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: onException and doTry

Posted by nathanwray <na...@detroitsci.com>.
Thanks Charles.  

I have a doTry inside route2 that has handled=false, and the *onException in
route1 is firing the redelivery*.  The only issue I have is that it
redelivers an infinite number of times until the route succeeds instead of
twice.  It appears to be *forgetting the current retry count*.  I'm not sure
that's related to the inner route's doTry or not.  Is the route count
threadlocal, and the thread is changing?  I'm not sure what the underlying
mechanism is.









--
View this message in context: http://camel.465427.n5.nabble.com/onException-and-doTry-tp5757602p5757626.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: onException and doTry

Posted by Charles Moulliard <ch...@gmail.com>.
Hi Nathan,

When you use the doTry, doCatch processors, they will handle the exceptions
instead of the interceptor (= onException).

Regards,


On Wed, Oct 15, 2014 at 9:36 PM, nathanwray <na...@detroitsci.com> wrote:

> Hi all;
>
> I have a global onException defined that I hoped would let me retry an
> entire route twice using a setup like the following.  The issue that I see
> is that route2 gets called an unlimited number of times until it succeeds.
>
> Is this due to route2 having a doTry block inside?  Or am I missing
> something else?
>
> <onException useOriginalMessage="true">
> <exception>org.apache.camel.ExchangeTimedOutException</exception>
> <redeliveryPolicy maximumRedeliveries="2" redeliveryDelay="0"/>
> <continued><constant>true</constant></continued>
> <transform>//set an appropriate error result body
> </transform>
> </onException>
>
> from route1, I call into route2:
>
> <route id="1">
> <to uri="direct:route2"/>
> </route>
>
> <route id="2" errorHandlerRef="disableErrorHandler">
> <doTry>
> //call a jetty route
> <doCatch>
> <exception>java.lang.Exception</exception>
> <handled><constant>false</constant></handled>
> // log some info into the database
> </doCatch>
> </doTry>
> </route>
>
> I see logging like the following:
>
> 2014-10-15 15:00:14,469 [CamelJettyClient(0xf6eec8e)-150] WARN
> jetty.client.HttpExchange EXPIRED JettyContentExchange@50e9cd46=POST// a
> url
> here #SENDING(1ms)->EXPIRED(0ms)sent=1ms
>
> 2014-10-15 15:00:14,470 [CamelJettyClient(0xf6eec8e)-150] ERROR
> route.vendor-md.doCatch Exception
> org.apache.camel.ExchangeTimedOutException: The OUT message was not
> received
> within: 100 millis. Exchange[Message:  a JSON message body here]
>         at
>
> org.apache.camel.component.jetty.JettyContentExchange.doTaskCompleted(JettyContentExchange.java:207)
>         at
>
> org.apache.camel.component.jetty.JettyContentExchange.onExpire(JettyContentExchange.java:130)
>         at
>
> org.eclipse.jetty.client.HttpExchange$Listener.onExpire(HttpExchange.java:1120)
>         at
>
> org.eclipse.jetty.client.HttpExchange.setStatusExpired(HttpExchange.java:384)
>         at
> org.eclipse.jetty.client.HttpExchange.setStatus(HttpExchange.java:267)
>         at
> org.eclipse.jetty.client.HttpExchange.expire(HttpExchange.java:130)
>         at
> org.eclipse.jetty.client.HttpExchange$1.expired(HttpExchange.java:1070)
>         at org.eclipse.jetty.util.thread.Timeout.tick(Timeout.java:140)
>         at org.eclipse.jetty.util.thread.Timeout.tick(Timeout.java:153)
>         at org.eclipse.jetty.client.HttpClient$1.run(HttpClient.java:441)
>         at
>
> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
>         at
>
> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
>         at java.lang.Thread.run(Thread.java:745)
>
> 2014-10-15 15:00:14,474 [Camel (camel-1) thread #10 -
> ErrorHandlerRedeliveryTask] DEBUG route2  a debugging message here from
> route2
>
>
> Any thoughts?
>
>
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/onException-and-doTry-tp5757602.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Charles Moulliard
Apache Committer / Architect @RedHat
Twitter : @cmoulliard | Blog :  http://cmoulliard.github.io