You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by fordm <fo...@gmail.com> on 2013/07/24 14:42:14 UTC

Rethrowing an exception using the Dead Letter Error Handler

Hi,

I've got a camel route that consumes from an activemq endpoint and persists
the message to a database via jpa.

If, for example, the connection to the database is lost I want to retry a
message a few times and if it still fails put it on a Dead Letter Queue.
This bit is fine:

<camelContext>
    <errorHandler deadLetterUri="myDLQ" type="DeadLetterChannel"
id="myDLErrorHandler">
        <redeliveryPolicy maximumRedeliveries="3" />
    </errorHandler>

    <route errorHandlerRef="myDLErrorHandler">
        <from uri="activemq:myFromQueue" />

        <onException>
           
<exception>org.apache.openjpa.persistence.PersistenceException</exception>
            <redeliveryPolicy maximumRedeliveries="2" />
            <handled>
                <constant>true</constant>
            </handled>
        </onException>

        <to uri="jpa://foo" />
    </route>
</camelContext>

But as well as retrying and putting a failed message on the DLQ I want to
throw my own exception (it'll have some 'special' stuff that gets put into
the log). It's this bit I'm having problems with, I had hoped a simple
<throwException ref="mySpecialException" /> after the <handled>...</handled>
would work but it doesn't.

Any suggestions?

Many thanks



--
View this message in context: http://camel.465427.n5.nabble.com/Rethrowing-an-exception-using-the-Dead-Letter-Error-Handler-tp5736211.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Rethrowing an exception using the Dead Letter Error Handler

Posted by fordm <fo...@gmail.com>.
Isn't it always the way. I've found the answer:

<camelContext>
    <errorHandler deadLetterUri="myDLQ" type="DeadLetterChannel"
id="myDLErrorHandler">
        <redeliveryPolicy maximumRedeliveries="3" />
    </errorHandler>

    <route errorHandlerRef="myDLErrorHandler">
        <from uri="activemq:myFromQueue" />

        <onException>
           
<exception>org.apache.openjpa.persistence.PersistenceException</exception>
            <redeliveryPolicy maximumRedeliveries="2" />
            <handled>
                <constant>true</constant>
            </handled>
            <to uri="myDLQ" />
            <throwException ref="mySpecialException" />
        </onException>

        <to uri="jpa://foo" />
    </route>
</camelContext>

Who knows what I was trying to do before!



--
View this message in context: http://camel.465427.n5.nabble.com/Rethrowing-an-exception-using-the-Dead-Letter-Error-Handler-tp5736211p5736213.html
Sent from the Camel - Users mailing list archive at Nabble.com.