You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by dunnlow <du...@yahoo.com> on 2012/12/10 23:25:26 UTC

Using Dead letter channel with ActiveMQ?

I'm using camel 10.0 and activemq 5.5.

I currently have a redelivery policy currently configured on my
ConnectionFactory that is being used by my ActiveMQ component (using
org.apache.activemq.RedeliveryPolicy).  However, what I really want to do is
set up redelivery in camel so that after the msg cannot be delivered for
several tries, it gets dumped out to a file (via xstream) and pulled off the
queue.

I was reading about the org.apache.camel.builder.DeadLetterChannelBuilder,
and it sounds like what I want.  I see how to configure the bean (passing,
in a dead letter uri and redelivery policy).  Also, I see how to configure
the Camel redelivery policy, but I'm not sure how to integrate it into my
route consuming from activemq.

Should  I just remove the redelivery policy from my ConnectionFactory
configuration and set the errorHandlerRef on my route that consumes from
ActiveMQ to my Camel DeadLetterChannelBuilder bean?

Thanks for any insight,
-J




--
View this message in context: http://camel.465427.n5.nabble.com/Using-Dead-letter-channel-with-ActiveMQ-tp5723865.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using Dead letter channel with ActiveMQ?

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Feb 13, 2013 at 6:45 PM, dunnlow <du...@yahoo.com> wrote:
> I have a solution that seems to be working.  I have assigned a context
> errorHandler and have a deliverypolicy that has a dead letter uri (a route
> that dumps to a file), like:
>
>     <camelContext.... errorhandlerRef="errorHandler"/>
>
>     <errorHandler id="errorHandler" type="DeadLetterChannel"
> deadLetterUri="direct:dumpToFile" useOriginalMessage="true">
>         <redeliveryPolicy maximumRedeliveries="5"....... />
>     </errorHandler>
>
>     <route>
>        <from:jms:testQueue>
>        <transacted>
>        <bean:ref="myBean" method="sendToWebService"/>
>     </route>
>
>
> When a message fails 5 times (to test I am shutting down the web service, so
> there is a connection exception thrown), it is routed to my "dumpToFile"
> route.
>
> I'm still using the Spring JmsTransactionManager in my JMS config for the
> connection factory because if I don't and camel shuts down during the
> retries, the message is lost (pulled off the queue).
>
> A few questions:
>
> 1) My ActiveMQ redeliveryPolicy seems to be getting ignored.  I believe that
> the camel error handler is intercepting so that spring/activemq does not see
> the rollback.  Does this seem correct?
>

Yes the Camel error handler kick-in first. And only the AMQ afterwards.
But because you use a DeadLetterChannel in Camel, then Camel will
remove any traces of error/exception.
So the AMQ seems the message as "commit" and not "rollback".



> 2) Does anyone see any issues with this approach?
>
> Claus, meant to mention, I never found a JMSRedeliveryCounter.
>
> Thanks again,
> -J
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Using-Dead-letter-channel-with-ActiveMQ-tp5723865p5727544.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Using Dead letter channel with ActiveMQ?

Posted by dunnlow <du...@yahoo.com>.
I have a solution that seems to be working.  I have assigned a context
errorHandler and have a deliverypolicy that has a dead letter uri (a route
that dumps to a file), like:

    <camelContext.... errorhandlerRef="errorHandler"/>

    <errorHandler id="errorHandler" type="DeadLetterChannel"
deadLetterUri="direct:dumpToFile" useOriginalMessage="true">
        <redeliveryPolicy maximumRedeliveries="5"....... />
    </errorHandler>

    <route>
       <from:jms:testQueue>
       <transacted>
       <bean:ref=&quot;myBean&quot; method=&quot;sendToWebService&quot;/>
    </route>


When a message fails 5 times (to test I am shutting down the web service, so
there is a connection exception thrown), it is routed to my "dumpToFile"
route.

I'm still using the Spring JmsTransactionManager in my JMS config for the
connection factory because if I don't and camel shuts down during the
retries, the message is lost (pulled off the queue).  

A few questions:

1) My ActiveMQ redeliveryPolicy seems to be getting ignored.  I believe that
the camel error handler is intercepting so that spring/activemq does not see
the rollback.  Does this seem correct?

2) Does anyone see any issues with this approach?

Claus, meant to mention, I never found a JMSRedeliveryCounter.

Thanks again,
-J



--
View this message in context: http://camel.465427.n5.nabble.com/Using-Dead-letter-channel-with-ActiveMQ-tp5723865p5727544.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using Dead letter channel with ActiveMQ?

Posted by dunnlow <du...@yahoo.com>.
Claus, I've tried to avoid this issue, but it is back upon me.  

Basically, I'm using camel 2.10.3 now, Spring 3.1.2 and activemq 5.7) I am
consuming from an activemq broker which I do not control, and which does not
allow use of a DLQ - it is clustered, robust, etc, etc.  I want to make sure
that my route is successful before it is permanently removed from the queue. 
Currently, I use the Spring JmsTransactionManager with an activemq
RedeliveryPolicy.   However, this requests the creation of a DLQ after the
maximum delivery tries (which make the broker owners surly because they see
errors).

I am looking for the best strategy to handle this.  I've considered putting
a camel redelivery policy on top with one less retry (so that it sent the
msg to a dead letter channel before the last Spring retry).  I also
considered pulling the message off the queue and stuffing it somewhere
locally - but this is adding another point of failure.

Any other thoughts about how to take over the the dead letter channel so
that the message stays on the queue until either the route succeeds OR the
max retries is reached (and then stored locally to a file)?

Thanks for any thoughts,
-J



--
View this message in context: http://camel.465427.n5.nabble.com/Using-Dead-letter-channel-with-ActiveMQ-tp5723865p5727531.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using Dead letter channel with ActiveMQ?

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Dec 12, 2012 at 7:01 PM, dunnlow <du...@yahoo.com> wrote:
> Willem, thank you for your response - although I'm sorry, I don't fully
> understand it.
>
> I have a transacted route that pulls a msg from activemq and sends it to
> another route that multicasts that message to a variety of services.  If any
> of those services throw an exception I want to leave the msg on the queue
> and try again for 5 times.  After that I want to reroute the message to a
> file.
>
> In the case above, does the org.apache.activemq.RedeliveryPolicy I have set
> up (shown below) on my connection factory to activemq see that as a retry or
> is that totally independent?  (I thought this would be considered one retry)
>
> <bean id="jmsRedeliverPolicy" class="org.apache.activemq.RedeliveryPolicy">
>     <property name="maximumRedeliveries" value="5"/>
>     <property name="initialRedeliveryDelay" value="1000"/>
>     <property name="maximumRedeliveryDelay" value="256000"/>
>     <property name="useExponentialBackoff" value="true"/>
>     <property name="backOffMuliplier" value="2"/>
> </bean>
>
> In other words, could the camel redelivery policy roll back the transaction
> 20 times and the above redelivery policy not kick in?
>

If you use transacted acknowledgement and using the AMQ broker's
redelivery policy.
Then you let the broker handle all the redelivery, and moving to its
DLQ when all redelivery attempts fails.

Then you should not let Camel do any error handling, as you rely on
the AMQ broker doing it.
Though AMQ can only move the exhausted message to its DLQ (which is a
message queue) and not save to a file.
What you can do is to have a Camel route that reads from the DLQ and
routes to a file.

Another alternative would be to let Camel read the
"JMSRedeliveryCounter" I think there is such a counter.
And if its > max, then you can use a Camel filter / content based
router etc to route the message to a file.


And mind Camel's redelivery / error handling is happening at where the
"problem" is. And not "all over again".
Where as AMQ will redeliver the message to the route again (= "all
over again".).  And Camel's is pure in memory based.



> Thanks
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Using-Dead-letter-channel-with-ActiveMQ-tp5723865p5723962.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Using Dead letter channel with ActiveMQ?

Posted by dunnlow <du...@yahoo.com>.
Willem, thank you for your response - although I'm sorry, I don't fully
understand it.  

I have a transacted route that pulls a msg from activemq and sends it to
another route that multicasts that message to a variety of services.  If any
of those services throw an exception I want to leave the msg on the queue
and try again for 5 times.  After that I want to reroute the message to a
file.

In the case above, does the org.apache.activemq.RedeliveryPolicy I have set
up (shown below) on my connection factory to activemq see that as a retry or
is that totally independent?  (I thought this would be considered one retry)

<bean id="jmsRedeliverPolicy" class="org.apache.activemq.RedeliveryPolicy">
    <property name="maximumRedeliveries" value="5"/>
    <property name="initialRedeliveryDelay" value="1000"/>
    <property name="maximumRedeliveryDelay" value="256000"/>
    <property name="useExponentialBackoff" value="true"/>
    <property name="backOffMuliplier" value="2"/>
</bean>

In other words, could the camel redelivery policy roll back the transaction
20 times and the above redelivery policy not kick in?

Thanks



--
View this message in context: http://camel.465427.n5.nabble.com/Using-Dead-letter-channel-with-ActiveMQ-tp5723865p5723962.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Using Dead letter channel with ActiveMQ?

Posted by Willem jiang <wi...@gmail.com>.
You may treat the camel redeliver as a logic level configuration and ActiveMQ redeliver as transport level configuration.
They should not affect each other. But if you want to dump the file, you need to consider to setup the camel redelivery policy of it.


--  
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.iteye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem





On Tuesday, December 11, 2012 at 6:25 AM, dunnlow wrote:

> I'm using camel 10.0 and activemq 5.5.
>  
> I currently have a redelivery policy currently configured on my
> ConnectionFactory that is being used by my ActiveMQ component (using
> org.apache.activemq.RedeliveryPolicy). However, what I really want to do is
> set up redelivery in camel so that after the msg cannot be delivered for
> several tries, it gets dumped out to a file (via xstream) and pulled off the
> queue.
>  
> I was reading about the org.apache.camel.builder.DeadLetterChannelBuilder,
> and it sounds like what I want. I see how to configure the bean (passing,
> in a dead letter uri and redelivery policy). Also, I see how to configure
> the Camel redelivery policy, but I'm not sure how to integrate it into my
> route consuming from activemq.
>  
> Should I just remove the redelivery policy from my ConnectionFactory
> configuration and set the errorHandlerRef on my route that consumes from
> ActiveMQ to my Camel DeadLetterChannelBuilder bean?
>  
> Thanks for any insight,
> -J
>  
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Using-Dead-letter-channel-with-ActiveMQ-tp5723865.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).