You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by DanD <DD...@UP.COM> on 2010/03/10 16:37:39 UTC

Help with Error Handling

Hi everyone.  I'm hoping you guys can help me understand camel error handling
a bit more.  The current documentation seems incredibly confusing to me with
a lot of different ways to accomplish a goal.  Here is my particular
problem.  I need to write a smart bridge between two JMS queues.  I'm using
camel 2.2 with the spring dsl.

Here is the layout:  everything is in the same context for simplicity. 
There is an inbound queue and an outbound queue and some EIP code in the
middle.  The EIP code in the middle stores the inbound message in a database
and writes a copy to the outbound queue.

Here are the rules:
1.  If the database write fails, write the message to the dead-letter queue
and stop further processing.
2.  If the outbound queue write fails, rollback the transaction to the DB
and write the message to the dead-letter queue and stop further processing.
3.  If the dead-letter write fails, roll the original message back on the
inbound queue.

I think the code below achieves that, but I'm not sure if I need stuff like
<transacted/> in every route.  I'm also not sure what happens if the
dead-letter queue is down cause I haven't gotten around to testing that yet. 
When an exception is thrown in the body of processing, everything seems to
work fine.  In other words it rolls the transaction back, writes to the
dead-letter and stops.  It is case 2 and 3 above that I'm wondering about.


<bean id="deadLetterErrorHandler"
class="org.apache.camel.builder.DeadLetterChannelBuilder">
   <property name="deadLetterUri" value="direct:dead-letter" />
   <property name="redeliveryPolicy" ref="redeliveryPolicyConfig" />
</bean>

<bean id="redeliveryPolicyConfig"
class="org.apache.camel.processor.RedeliveryPolicy">
   <property name="maximumRedeliveries" value="0" />
</bean>

<camelContext id="some-bridge" errorHandlerRef="deadLetterErrorHandler">
    <camel:onException>
	<camel:exception>java.lang.Throwable</camel:exception>
	<camel:bean ref="errorHandler" />
	<camel:to uri="direct:dead-letter" />
   </camel:onException>
   <route id="from-some-jms-queue">
      <from uri="injms:queue:some-inbound-queue"/>
       <transacted/>
       <to uri="direct:smart-bridge"/>
   </route>
   <route id="some-smart-bridge-code">
       <from uri="direct:smart-bridge"/>
       <transacted/>
        <!-- do some EIP stuff here including storing the message in a DB
-->
        <!-- recipient list to destination JMS -->
   </route>
   <route id="to-some-jms-queue">
      <from uri="direct:some-outbound-jms-queue"/>
       <transacted/>
      <to uri="outjms:queue:some-outbound-jms"/>
   </route>
   <route id="dead-letter">
      <from uri="direct:dead-letter"/>
      <to uri="dljms:queue:dead-letter"/>
    </route>
</camelContext>

-- 
View this message in context: http://old.nabble.com/Help-with-Error-Handling-tp27851439p27851439.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Help with Error Handling

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Mar 10, 2010 at 5:54 PM, DanD <DD...@up.com> wrote:
>
> Thanks for the response Claus.  I don't mind buying the book but since 2.2
> has just been released and 2.3 is on the horizon, will the book be
> up-to-date with respect to error handling (and other stuff)?
> --

Yeah the book is up to date. In fact a few days ago I updated chapter
5 with new options added in 2.3.
The current MEAP is based on 2.2 and is about 3-4 weeks old.

Will be a new MEAP updated at end of this month/early next month.

> View this message in context: http://old.nabble.com/Help-with-Error-Handling-tp27851439p27852592.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: Help with Error Handling

Posted by DanD <DD...@UP.COM>.
Thanks for the response Claus.  I don't mind buying the book but since 2.2
has just been released and 2.3 is on the horizon, will the book be
up-to-date with respect to error handling (and other stuff)?
-- 
View this message in context: http://old.nabble.com/Help-with-Error-Handling-tp27851439p27852592.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Help with Error Handling

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Mar 10, 2010 at 4:37 PM, DanD <DD...@up.com> wrote:
>
> Hi everyone.  I'm hoping you guys can help me understand camel error handling
> a bit more.  The current documentation seems incredibly confusing to me with
> a lot of different ways to accomplish a goal.  Here is my particular
> problem.  I need to write a smart bridge between two JMS queues.  I'm using
> camel 2.2 with the spring dsl.
>

I would recommend picking up the Camel in Action book and read chapter
5 which covers error handling.
There is 30+ pages on this topic.

Its well structured and serves the topic for you on a silver platter
and guides you through this hard topic.
There is many features and options in Camel for error handling.

And yes the current wiki pages is full of details, but not well
structured to introduce you and guide you through it.

And yes I am one of the authors of that book, who wrote that chapter.
And it has been copy edited which means its *final* like quality.


> Here is the layout:  everything is in the same context for simplicity.
> There is an inbound queue and an outbound queue and some EIP code in the
> middle.  The EIP code in the middle stores the inbound message in a database
> and writes a copy to the outbound queue.
>
> Here are the rules:
> 1.  If the database write fails, write the message to the dead-letter queue
> and stop further processing.
> 2.  If the outbound queue write fails, rollback the transaction to the DB
> and write the message to the dead-letter queue and stop further processing.
> 3.  If the dead-letter write fails, roll the original message back on the
> inbound queue.
>

You can use the redelivery / DLQ from the JMS Broker to handle most of this.
ActiveMQ has redelivery support and DLQ.

Also the book in chapter 9 covers transactions which has a similar
example as this. Leveraging AMQ and a DB.


> I think the code below achieves that, but I'm not sure if I need stuff like
> <transacted/> in every route.  I'm also not sure what happens if the
> dead-letter queue is down cause I haven't gotten around to testing that yet.
> When an exception is thrown in the body of processing, everything seems to
> work fine.  In other words it rolls the transaction back, writes to the
> dead-letter and stops.  It is case 2 and 3 above that I'm wondering about.
>
>
> <bean id="deadLetterErrorHandler"
> class="org.apache.camel.builder.DeadLetterChannelBuilder">
>   <property name="deadLetterUri" value="direct:dead-letter" />
>   <property name="redeliveryPolicy" ref="redeliveryPolicyConfig" />
> </bean>
>
> <bean id="redeliveryPolicyConfig"
> class="org.apache.camel.processor.RedeliveryPolicy">
>   <property name="maximumRedeliveries" value="0" />
> </bean>
>
> <camelContext id="some-bridge" errorHandlerRef="deadLetterErrorHandler">
>    <camel:onException>
>        <camel:exception>java.lang.Throwable</camel:exception>
>        <camel:bean ref="errorHandler" />
>        <camel:to uri="direct:dead-letter" />
>   </camel:onException>
>   <route id="from-some-jms-queue">
>      <from uri="injms:queue:some-inbound-queue"/>
>       <transacted/>
>       <to uri="direct:smart-bridge"/>
>   </route>
>   <route id="some-smart-bridge-code">
>       <from uri="direct:smart-bridge"/>
>       <transacted/>
>        <!-- do some EIP stuff here including storing the message in a DB
> -->
>        <!-- recipient list to destination JMS -->
>   </route>
>   <route id="to-some-jms-queue">
>      <from uri="direct:some-outbound-jms-queue"/>
>       <transacted/>
>      <to uri="outjms:queue:some-outbound-jms"/>
>   </route>
>   <route id="dead-letter">
>      <from uri="direct:dead-letter"/>
>      <to uri="dljms:queue:dead-letter"/>
>    </route>
> </camelContext>
>
> --
> View this message in context: http://old.nabble.com/Help-with-Error-Handling-tp27851439p27851439.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