You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by dnn <Da...@ngc.com> on 2010/04/08 21:07:42 UTC
onException handling
I am trying to use global onException handling with a transacted route.
According to the everything I've read, the following should print the "HEY I
GOT AN EXCEPTION" message:
<camelContext errorHandlerRef="myErrorHandler">
<onException>
<exception>java.lang.Exception</exception>
<log loggingLevel="ERROR" message="HEY I GOT AN EXCEPTION" />
</onException>
<route>
<from uri="jms:test" />
<transacted />
<to uri="someProcessorThatThrowsAnException" />
</route>
</camelContext>
<bean id="myErrorHandler"
class="org.apache.camel.spring.spi.TransactionErrorHandlerBuilder">
<property name="transactionTemplate"
ref="PROPAGATION_REQUIRES_NEW_TEMPLATE" />
</bean>
<bean id="PROPAGATION_REQUIRES_NEW_TEMPLATE"
class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager" ref="transactionManager" />
<property name="propagationBehaviorName" value="PROPAGATION_REQUIRES_NEW"
/>
</bean>
I would imagine that when "someProcessorThatThrowsAnException" is executed,
it will throw an exception that is handled by the global onException
handler. However, it doesn't work and my log message is never printed out.
I have found a workaround by moving the onException handling INSIDE the
<transacted></transacted> block as such:
<camelContext errorHandlerRef="myErrorHandler">
<route>
<from uri="jms:test" />
<transacted>
<onException>
<exception>java.lang.Exception</exception>
<log loggingLevel="ERROR" message="HEY I GOT AN EXCEPTION" />
</onException>
<to uri="someProcessorThatThrowsAnException" />
</transacted>
</route>
</camelContext>
It appears that the <transacted></transacted> block is creating its own
try/catch block that is ignorant of the global onException handler. Is this
the expected behavior? Is there any way to make it act like my first
example? I would prefer using the global onException route to share it
among several routes.
I am using Camel 2.2.0.
Thanks,
Dan Nawrocki
--
View this message in context: http://old.nabble.com/onException-handling-tp28183226p28183226.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: onException handling
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
Thanks for taking your time to write back with such a detailed
information about your solution and thoughts.
On Fri, Apr 16, 2010 at 4:13 PM, dnn <Da...@ngc.com> wrote:
>
> After a lot more digging, I've found what's really going on. I'm using
> Spring 2.5.6, Camel 2.2.0, ActiveMQ 5.3.1, Hibernate 3.4.0.GA, and Bitronix
> 1.3.3. The latest problem I was having (commit() call fails) was because
> Hibernate flushes itself to the DB as a pre-commit synchronization listener.
> If I manually called em.flush() the PK violation would be thrown in my
> application code and the Camel onException handlers would perform as
> expected. However, I decided that would not be a good way to go forward
> (what if the commit failed for some other reason?) and was left still
> searching for a solution.
>
> Since almost all of my routes start with a JMS queue, I decided to actually
> use the XA functionality in the software I'm using and let any exception
> cause a rollback all the way to ActiveMQ. After a certain number of
> rollbacks, ActiveMQ will move the message to a DLQ. I've added a route that
> reads from the DLQ and does more or less the exact same actions my previous
> onException error handler did, but surrounded with a try/catch to prevent
> any errors in the DLQ route from causing an infinite loop. This seems more
> like an "enterprise" solution, and I probably should have used it from the
> beginning.
>
> Thanks for all your help Claus!
>
>
>
> Claus Ibsen-2 wrote:
>>
>> On Wed, Apr 14, 2010 at 6:51 PM, dnn <Da...@ngc.com> wrote:
>>>
>>> This one just won't die :)
>>>
>>> I've got the same issue, but caused in a slightly different way. The
>>> problem is when the DB commit fails (in my case, a unique constraint
>>> violation to an Oracle DB), the commit happens outside of the
>>> TransactionErrorHandler.super.process(exchange) block, and won't trigger
>>> the
>>> global onException handlers.
>>>
>>
>> That is painful, the Oracle JDBC drivers is really bad.
>> You can try with XA to have both JMS + JDBC in the same orchestrated TM.
>>
>>> I've tried to create a unit test to show the issue, but I cannot figure
>>> out
>>> how to make HSQL throw an exception at commit time. If anyone has any
>>> tips
>>> I'd be happy to create a unit test.
>>>
>>
>> Maybe some mock frameworks can do this.
>>
>>
>
> --
> View this message in context: http://old.nabble.com/onException-handling-tp28183226p28267409.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Re: onException handling
Posted by dnn <Da...@ngc.com>.
After a lot more digging, I've found what's really going on. I'm using
Spring 2.5.6, Camel 2.2.0, ActiveMQ 5.3.1, Hibernate 3.4.0.GA, and Bitronix
1.3.3. The latest problem I was having (commit() call fails) was because
Hibernate flushes itself to the DB as a pre-commit synchronization listener.
If I manually called em.flush() the PK violation would be thrown in my
application code and the Camel onException handlers would perform as
expected. However, I decided that would not be a good way to go forward
(what if the commit failed for some other reason?) and was left still
searching for a solution.
Since almost all of my routes start with a JMS queue, I decided to actually
use the XA functionality in the software I'm using and let any exception
cause a rollback all the way to ActiveMQ. After a certain number of
rollbacks, ActiveMQ will move the message to a DLQ. I've added a route that
reads from the DLQ and does more or less the exact same actions my previous
onException error handler did, but surrounded with a try/catch to prevent
any errors in the DLQ route from causing an infinite loop. This seems more
like an "enterprise" solution, and I probably should have used it from the
beginning.
Thanks for all your help Claus!
Claus Ibsen-2 wrote:
>
> On Wed, Apr 14, 2010 at 6:51 PM, dnn <Da...@ngc.com> wrote:
>>
>> This one just won't die :)
>>
>> I've got the same issue, but caused in a slightly different way. The
>> problem is when the DB commit fails (in my case, a unique constraint
>> violation to an Oracle DB), the commit happens outside of the
>> TransactionErrorHandler.super.process(exchange) block, and won't trigger
>> the
>> global onException handlers.
>>
>
> That is painful, the Oracle JDBC drivers is really bad.
> You can try with XA to have both JMS + JDBC in the same orchestrated TM.
>
>> I've tried to create a unit test to show the issue, but I cannot figure
>> out
>> how to make HSQL throw an exception at commit time. If anyone has any
>> tips
>> I'd be happy to create a unit test.
>>
>
> Maybe some mock frameworks can do this.
>
>
--
View this message in context: http://old.nabble.com/onException-handling-tp28183226p28267409.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: onException handling
Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Apr 14, 2010 at 6:51 PM, dnn <Da...@ngc.com> wrote:
>
> This one just won't die :)
>
> I've got the same issue, but caused in a slightly different way. The
> problem is when the DB commit fails (in my case, a unique constraint
> violation to an Oracle DB), the commit happens outside of the
> TransactionErrorHandler.super.process(exchange) block, and won't trigger the
> global onException handlers.
>
That is painful, the Oracle JDBC drivers is really bad.
You can try with XA to have both JMS + JDBC in the same orchestrated TM.
> I've tried to create a unit test to show the issue, but I cannot figure out
> how to make HSQL throw an exception at commit time. If anyone has any tips
> I'd be happy to create a unit test.
>
Maybe some mock frameworks can do this.
> Thanks,
> Dan Nawrocki
>
>
> Claus Ibsen-2 wrote:
>>
>> On Fri, Apr 9, 2010 at 8:46 PM, dnn <Da...@ngc.com> wrote:
>>>
>>> Works for me too using trunk. It looks like an automated build pulls the
>>> trunk at midnight and deploys it to 2.3-SNAPSHOT in maven, so I should be
>>> able to start using it from mvn tomorrow. When is 2.3.0 slated for
>>> release?
>>>
>>
>> There are still a couple of must work to be done. (restore camel-http
>> using http client 3.1 as http client 4.0.1 lacks some features in 3.1,
>> and those features have only been added to http client 4.1, which goes
>> on a long release path with alpha releases currently :( :(
>>
>> I think we can have it released in end of this or start of next month.
>>
> --
> View this message in context: http://old.nabble.com/onException-handling-tp28183226p28245275.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Re: onException handling
Posted by dnn <Da...@ngc.com>.
This one just won't die :)
I've got the same issue, but caused in a slightly different way. The
problem is when the DB commit fails (in my case, a unique constraint
violation to an Oracle DB), the commit happens outside of the
TransactionErrorHandler.super.process(exchange) block, and won't trigger the
global onException handlers.
I've tried to create a unit test to show the issue, but I cannot figure out
how to make HSQL throw an exception at commit time. If anyone has any tips
I'd be happy to create a unit test.
Thanks,
Dan Nawrocki
Claus Ibsen-2 wrote:
>
> On Fri, Apr 9, 2010 at 8:46 PM, dnn <Da...@ngc.com> wrote:
>>
>> Works for me too using trunk. It looks like an automated build pulls the
>> trunk at midnight and deploys it to 2.3-SNAPSHOT in maven, so I should be
>> able to start using it from mvn tomorrow. When is 2.3.0 slated for
>> release?
>>
>
> There are still a couple of must work to be done. (restore camel-http
> using http client 3.1 as http client 4.0.1 lacks some features in 3.1,
> and those features have only been added to http client 4.1, which goes
> on a long release path with alpha releases currently :( :(
>
> I think we can have it released in end of this or start of next month.
>
--
View this message in context: http://old.nabble.com/onException-handling-tp28183226p28245275.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: onException handling
Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Apr 9, 2010 at 8:46 PM, dnn <Da...@ngc.com> wrote:
>
> Works for me too using trunk. It looks like an automated build pulls the
> trunk at midnight and deploys it to 2.3-SNAPSHOT in maven, so I should be
> able to start using it from mvn tomorrow. When is 2.3.0 slated for release?
>
There are still a couple of must work to be done. (restore camel-http
using http client 3.1 as http client 4.0.1 lacks some features in 3.1,
and those features have only been added to http client 4.1, which goes
on a long release path with alpha releases currently :( :(
I think we can have it released in end of this or start of next month.
> Thanks for all the hard work. You guys make a great product!
>
>
> Claus Ibsen-2 wrote:
>>
>> Hi
>>
>> I have created an unit test on Camel trunk based on your route. And it
>> works for me.
>> http://svn.apache.org/viewvc?rev=932470&view=rev
>>
>
> --
> View this message in context: http://old.nabble.com/onException-handling-tp28183226p28196117.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Re: onException handling
Posted by dnn <Da...@ngc.com>.
Works for me too using trunk. It looks like an automated build pulls the
trunk at midnight and deploys it to 2.3-SNAPSHOT in maven, so I should be
able to start using it from mvn tomorrow. When is 2.3.0 slated for release?
Thanks for all the hard work. You guys make a great product!
Claus Ibsen-2 wrote:
>
> Hi
>
> I have created an unit test on Camel trunk based on your route. And it
> works for me.
> http://svn.apache.org/viewvc?rev=932470&view=rev
>
--
View this message in context: http://old.nabble.com/onException-handling-tp28183226p28196117.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: onException handling
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
I also think there was an issue in a Camel release with setting a
errorHandlerRef on <camelContext>. So set it on <route> instead to see
if it works then.
It should be fixed in 2.3-SNAPSHOT. or maybe in 2.2 also (cant remember)
On Fri, Apr 9, 2010 at 5:51 PM, Claus Ibsen <cl...@gmail.com> wrote:
> Hi
>
> I have created an unit test on Camel trunk based on your route. And it
> works for me.
> http://svn.apache.org/viewvc?rev=932470&view=rev
>
>
>
> On Fri, Apr 9, 2010 at 4:15 PM, dnn <Da...@ngc.com> wrote:
>>
>> Thanks for the quick replies!
>>
>> Willem--
>>
>> This is a rather trivial test case - in my "real" routes I definitely
>> require the <transacted/> tags. It does appear that using transacted IS
>> setting up a new TransactionErrorHandler; it's just not grabbing the global
>> onException handlers as I expected...
>>
>> Claus--
>>
>> Camel 2.3-SNAPSHOT performed in the exact same way. I'll try converting my
>> test case to DSL to try it out, but we've got a lot of routes already
>> written in XML that I would really prefer to not redo.
>>
>> Thanks,
>> Dan Nawrocki
>>
>> --
>> View this message in context: http://old.nabble.com/onException-handling-tp28183226p28191045.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Re: onException handling
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
I have created an unit test on Camel trunk based on your route. And it
works for me.
http://svn.apache.org/viewvc?rev=932470&view=rev
On Fri, Apr 9, 2010 at 4:15 PM, dnn <Da...@ngc.com> wrote:
>
> Thanks for the quick replies!
>
> Willem--
>
> This is a rather trivial test case - in my "real" routes I definitely
> require the <transacted/> tags. It does appear that using transacted IS
> setting up a new TransactionErrorHandler; it's just not grabbing the global
> onException handlers as I expected...
>
> Claus--
>
> Camel 2.3-SNAPSHOT performed in the exact same way. I'll try converting my
> test case to DSL to try it out, but we've got a lot of routes already
> written in XML that I would really prefer to not redo.
>
> Thanks,
> Dan Nawrocki
>
> --
> View this message in context: http://old.nabble.com/onException-handling-tp28183226p28191045.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Re: onException handling
Posted by dnn <Da...@ngc.com>.
Thanks for the quick replies!
Willem--
This is a rather trivial test case - in my "real" routes I definitely
require the <transacted/> tags. It does appear that using transacted IS
setting up a new TransactionErrorHandler; it's just not grabbing the global
onException handlers as I expected...
Claus--
Camel 2.3-SNAPSHOT performed in the exact same way. I'll try converting my
test case to DSL to try it out, but we've got a lot of routes already
written in XML that I would really prefer to not redo.
Thanks,
Dan Nawrocki
--
View this message in context: http://old.nabble.com/onException-handling-tp28183226p28191045.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: onException handling
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
Try with 2.3-SNAPSHOT. I recall some issue with the Spring XML and
<transacted/> with <onException> at route scope.
The Java DSL should work afair.
On Thu, Apr 8, 2010 at 9:07 PM, dnn <Da...@ngc.com> wrote:
>
> I am trying to use global onException handling with a transacted route.
> According to the everything I've read, the following should print the "HEY I
> GOT AN EXCEPTION" message:
>
> <camelContext errorHandlerRef="myErrorHandler">
> <onException>
> <exception>java.lang.Exception</exception>
> <log loggingLevel="ERROR" message="HEY I GOT AN EXCEPTION" />
> </onException>
> <route>
> <from uri="jms:test" />
> <transacted />
> <to uri="someProcessorThatThrowsAnException" />
> </route>
> </camelContext>
> <bean id="myErrorHandler"
> class="org.apache.camel.spring.spi.TransactionErrorHandlerBuilder">
> <property name="transactionTemplate"
> ref="PROPAGATION_REQUIRES_NEW_TEMPLATE" />
> </bean>
> <bean id="PROPAGATION_REQUIRES_NEW_TEMPLATE"
> class="org.springframework.transaction.support.TransactionTemplate">
> <property name="transactionManager" ref="transactionManager" />
> <property name="propagationBehaviorName" value="PROPAGATION_REQUIRES_NEW"
> />
> </bean>
>
> I would imagine that when "someProcessorThatThrowsAnException" is executed,
> it will throw an exception that is handled by the global onException
> handler. However, it doesn't work and my log message is never printed out.
>
> I have found a workaround by moving the onException handling INSIDE the
> <transacted></transacted> block as such:
>
> <camelContext errorHandlerRef="myErrorHandler">
> <route>
> <from uri="jms:test" />
> <transacted>
> <onException>
> <exception>java.lang.Exception</exception>
> <log loggingLevel="ERROR" message="HEY I GOT AN EXCEPTION" />
> </onException>
> <to uri="someProcessorThatThrowsAnException" />
> </transacted>
> </route>
> </camelContext>
>
> It appears that the <transacted></transacted> block is creating its own
> try/catch block that is ignorant of the global onException handler. Is this
> the expected behavior? Is there any way to make it act like my first
> example? I would prefer using the global onException route to share it
> among several routes.
>
> I am using Camel 2.2.0.
>
> Thanks,
> Dan Nawrocki
>
> --
> View this message in context: http://old.nabble.com/onException-handling-tp28183226p28183226.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Re: onException handling
Posted by Willem Jiang <wi...@gmail.com>.
Hi,
Can you just remove the <transacted/> tag to see if message is printed out ?
<transacted> will set up a new TransactionErrorHandler if I remember right.
Willem
dnn wrote:
> I am trying to use global onException handling with a transacted route.
> According to the everything I've read, the following should print the "HEY I
> GOT AN EXCEPTION" message:
>
> <camelContext errorHandlerRef="myErrorHandler">
> <onException>
> <exception>java.lang.Exception</exception>
> <log loggingLevel="ERROR" message="HEY I GOT AN EXCEPTION" />
> </onException>
> <route>
> <from uri="jms:test" />
> <transacted />
> <to uri="someProcessorThatThrowsAnException" />
> </route>
> </camelContext>
> <bean id="myErrorHandler"
> class="org.apache.camel.spring.spi.TransactionErrorHandlerBuilder">
> <property name="transactionTemplate"
> ref="PROPAGATION_REQUIRES_NEW_TEMPLATE" />
> </bean>
> <bean id="PROPAGATION_REQUIRES_NEW_TEMPLATE"
> class="org.springframework.transaction.support.TransactionTemplate">
> <property name="transactionManager" ref="transactionManager" />
> <property name="propagationBehaviorName" value="PROPAGATION_REQUIRES_NEW"
> />
> </bean>
>
> I would imagine that when "someProcessorThatThrowsAnException" is executed,
> it will throw an exception that is handled by the global onException
> handler. However, it doesn't work and my log message is never printed out.
>
> I have found a workaround by moving the onException handling INSIDE the
> <transacted></transacted> block as such:
>
> <camelContext errorHandlerRef="myErrorHandler">
> <route>
> <from uri="jms:test" />
> <transacted>
> <onException>
> <exception>java.lang.Exception</exception>
> <log loggingLevel="ERROR" message="HEY I GOT AN EXCEPTION" />
> </onException>
> <to uri="someProcessorThatThrowsAnException" />
> </transacted>
> </route>
> </camelContext>
>
> It appears that the <transacted></transacted> block is creating its own
> try/catch block that is ignorant of the global onException handler. Is this
> the expected behavior? Is there any way to make it act like my first
> example? I would prefer using the global onException route to share it
> among several routes.
>
> I am using Camel 2.2.0.
>
> Thanks,
> Dan Nawrocki
>