You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "kraythe ." <kr...@gmail.com> on 2014/05/01 19:00:46 UTC

JMS as Dead Letter Channel in Transaction?

Anyone know how to configure JMS as a dead letter channel but in a
transaction? Should be a simple issue I would think but its not working.

    final String fromURI =
String.format("activemq:queue:%s?concurrentConsumers=%d",
config.basicRouteInboxQueue(),
        config.concurrentConsumers());

errorHandler(deadLetterChannel("activemq:queue:ea.automation.dead").maximumRedeliveries(0));
    // The comments on the end of route steps help in reading code and
force the code formatter to behave.
    from(fromURI).routeId(ROUTE_ID_BASIC_ROUTE) // read from the inbox in
ActiveMQ
        .transacted(KEY_TXNPOLICY_REQUIRED) // make the route transacted.
        .setHeader(HDR_REQUESTOR, constant(config.requestor())) // we will
use the context name as the the requester
        .to("activemq:queue:" + config.basicRouteOutboxQueue()).id("end")
        .process(new Processor() {
          @Override
          public void process(final Exchange exchange) throws Exception {
            throw new RuntimeException("Forced exception");
          }
        });

This causes the resulting message to end up in BOTH the dead letter channel
and the outbox, which is of course not desired.

Thanks in advance.

*Robert Simmons Jr. MSc. - Lead Java Architect @ EA*
*Author of: Hardcore Java (2003) and Maintainable Java (2012)*
*LinkedIn: **http://www.linkedin.com/pub/robert-simmons/40/852/a39
<http://www.linkedin.com/pub/robert-simmons/40/852/a39>*

Re: JMS as Dead Letter Channel in Transaction?

Posted by "kraythe ." <kr...@gmail.com>.
Thanks Claus I will give that a lash.

*Robert Simmons Jr. MSc. - Lead Java Architect @ EA*
*Author of: Hardcore Java (2003) and Maintainable Java (2012)*
*LinkedIn: **http://www.linkedin.com/pub/robert-simmons/40/852/a39
<http://www.linkedin.com/pub/robert-simmons/40/852/a39>*


On Fri, May 2, 2014 at 12:28 AM, Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> You may want to use the DLQ built-in by AMQ instead. You can configure
> AMQ to do X number of redeliveries and if that fails move the message
> to a DLQ (either a shared or per destination DLQ).
>
> Then all that is done by AMQ, and you dont need to setup a DLQ error
> handler in Camel.
>
> What you want to do with AMQ, TX and Camel's DLC error handler is hard
> to do. As you need to make it look like a "commit" from AMQ point of
> view so the consumed message is ACKed. But the messages you have sent,
> should not be sent, and so they must look like a "rollback" - and you
> cannot do both.
>
> So what you try to do is not possible.
>
> Let AMQ do the DLQ handling, then there is no problems.
>
>
>
> On Thu, May 1, 2014 at 7:00 PM, kraythe . <kr...@gmail.com> wrote:
> > Anyone know how to configure JMS as a dead letter channel but in a
> > transaction? Should be a simple issue I would think but its not working.
> >
> >     final String fromURI =
> > String.format("activemq:queue:%s?concurrentConsumers=%d",
> > config.basicRouteInboxQueue(),
> >         config.concurrentConsumers());
> >
> >
> errorHandler(deadLetterChannel("activemq:queue:ea.automation.dead").maximumRedeliveries(0));
> >     // The comments on the end of route steps help in reading code and
> > force the code formatter to behave.
> >     from(fromURI).routeId(ROUTE_ID_BASIC_ROUTE) // read from the inbox in
> > ActiveMQ
> >         .transacted(KEY_TXNPOLICY_REQUIRED) // make the route transacted.
> >         .setHeader(HDR_REQUESTOR, constant(config.requestor())) // we
> will
> > use the context name as the the requester
> >         .to("activemq:queue:" + config.basicRouteOutboxQueue()).id("end")
> >         .process(new Processor() {
> >           @Override
> >           public void process(final Exchange exchange) throws Exception {
> >             throw new RuntimeException("Forced exception");
> >           }
> >         });
> >
> > This causes the resulting message to end up in BOTH the dead letter
> channel
> > and the outbox, which is of course not desired.
> >
> > Thanks in advance.
> >
> > *Robert Simmons Jr. MSc. - Lead Java Architect @ EA*
> > *Author of: Hardcore Java (2003) and Maintainable Java (2012)*
> > *LinkedIn: **http://www.linkedin.com/pub/robert-simmons/40/852/a39
> > <http://www.linkedin.com/pub/robert-simmons/40/852/a39>*
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: cibsen@redhat.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
> hawtio: http://hawt.io/
> fabric8: http://fabric8.io/
>

Re: JMS as Dead Letter Channel in Transaction?

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You may want to use the DLQ built-in by AMQ instead. You can configure
AMQ to do X number of redeliveries and if that fails move the message
to a DLQ (either a shared or per destination DLQ).

Then all that is done by AMQ, and you dont need to setup a DLQ error
handler in Camel.

What you want to do with AMQ, TX and Camel's DLC error handler is hard
to do. As you need to make it look like a "commit" from AMQ point of
view so the consumed message is ACKed. But the messages you have sent,
should not be sent, and so they must look like a "rollback" - and you
cannot do both.

So what you try to do is not possible.

Let AMQ do the DLQ handling, then there is no problems.



On Thu, May 1, 2014 at 7:00 PM, kraythe . <kr...@gmail.com> wrote:
> Anyone know how to configure JMS as a dead letter channel but in a
> transaction? Should be a simple issue I would think but its not working.
>
>     final String fromURI =
> String.format("activemq:queue:%s?concurrentConsumers=%d",
> config.basicRouteInboxQueue(),
>         config.concurrentConsumers());
>
> errorHandler(deadLetterChannel("activemq:queue:ea.automation.dead").maximumRedeliveries(0));
>     // The comments on the end of route steps help in reading code and
> force the code formatter to behave.
>     from(fromURI).routeId(ROUTE_ID_BASIC_ROUTE) // read from the inbox in
> ActiveMQ
>         .transacted(KEY_TXNPOLICY_REQUIRED) // make the route transacted.
>         .setHeader(HDR_REQUESTOR, constant(config.requestor())) // we will
> use the context name as the the requester
>         .to("activemq:queue:" + config.basicRouteOutboxQueue()).id("end")
>         .process(new Processor() {
>           @Override
>           public void process(final Exchange exchange) throws Exception {
>             throw new RuntimeException("Forced exception");
>           }
>         });
>
> This causes the resulting message to end up in BOTH the dead letter channel
> and the outbox, which is of course not desired.
>
> Thanks in advance.
>
> *Robert Simmons Jr. MSc. - Lead Java Architect @ EA*
> *Author of: Hardcore Java (2003) and Maintainable Java (2012)*
> *LinkedIn: **http://www.linkedin.com/pub/robert-simmons/40/852/a39
> <http://www.linkedin.com/pub/robert-simmons/40/852/a39>*



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/