Re: JMS Acknowledge mode

2017-12-20 Thread Quinn Stevenson
I’m not sure I’m following you, but I can tell you what I normally do.

My JMS Consumers use “transacted=true”, which will use a JMS Session 
transaction.  You don’t need the acknowledgementModeName, and I don’t think you 
need ‘.transacted()’ (I believe this is for XA).

I then setup exception policies for the different types of exceptions, with 
appropriate redelivery handling.

For the case where I don’t have an exception policy for an exception, Camel 
will rollback the message.  I also use ActiveMQ, so the message will get moved 
to a DLQ after being rolled-back 6 times.

HTH

Quinn Stevenson
qu...@pronoia-solutions.com
(801) 244-7758



> On Sep 4, 2017, at 5:21 AM, Andreas Bergmann  wrote:
> 
> Hi all,
> 
> I have the scenario where I need to manipulate the acknowledgement of JMS
> messages, depending on exceptions.
> 
> The setup so far:
> I configured the JMS endpoint with
> '&transacted=true&acknowledgementModeName=SESSION_TRANSACTED' and I
> added .transacted() to the route definition.
> 
> As soon as I have an Exception the messages will not be acknowledged and
> 'redelivered' from the JMS - so far so good.
> 
> But I have several steps in the route, some of them have recoverable, some
> unrecoverable reasons.
> I first parse the incoming message and in case of an exception I do not
> want the JMS to be acknowledged, since this is an unrecoverable error.
> Then I consume the message, which includes a validation and an own 'retry
> handling' in case of an exception - in this case the JMS message should be
> acknowledged.
> In case of other Exceptions (i.e. na db connection) I do not want the
> message to be acknowledged.
> 
> I tried several options with 'doCatch', 'onException', 'setFault in the
> Consumer','.handled(true)', '.stop()'  - but found no way to solve this
> problem. I can either switch to 'always acknowledge in case of an
> exception' or 'never acknowledge on exception'.
> 
> Any ideas or examples?
> 
> Best regards,
> Andreas



JMS Acknowledge mode

2017-09-04 Thread Andreas Bergmann
Hi all,

I have the scenario where I need to manipulate the acknowledgement of JMS
messages, depending on exceptions.

The setup so far:
I configured the JMS endpoint with
'&transacted=true&acknowledgementModeName=SESSION_TRANSACTED' and I
added .transacted() to the route definition.

As soon as I have an Exception the messages will not be acknowledged and
'redelivered' from the JMS - so far so good.

But I have several steps in the route, some of them have recoverable, some
unrecoverable reasons.
I first parse the incoming message and in case of an exception I do not
want the JMS to be acknowledged, since this is an unrecoverable error.
Then I consume the message, which includes a validation and an own 'retry
handling' in case of an exception - in this case the JMS message should be
acknowledged.
In case of other Exceptions (i.e. na db connection) I do not want the
message to be acknowledged.

I tried several options with 'doCatch', 'onException', 'setFault in the
Consumer','.handled(true)', '.stop()'  - but found no way to solve this
problem. I can either switch to 'always acknowledge in case of an
exception' or 'never acknowledge on exception'.

Any ideas or examples?

Best regards,
Andreas


Transaction handling with JMS acknowledge mode SESSION_TRANSACTED

2017-08-28 Thread Andreas Bergmann
Hi,

I'm receiving messages from a JMS provider and need to control the
'acknowledgement' of the JMS messages depending on Exceptions I get from
the message processing Java bean.

On technical Exceptions (i.e. database currently not available) I don't
want to acknowledge the JMS message, so that it will be retrieved again and
again until the database connection is available again. This is handled by
setting the acknowledge mode 'SESSION_TRANSATED'. As soon as I have an
exception the JMS message will not be acknowledged and be available for the
'next try'.

But - on specific exceptions, I want to bypass the acknowledgement so that
the JMS message will be acknowledged, even though the transaction will be
rolled back.
As an example: I do want to acknowledge the message on validation
exceptions.

I thought that setting the exception to 'handled = true' might solve the
issue.

@Component
public class JmsEndpointRoute extends RouteBuilder {

@Override
public void configure() throws Exception {

from("jms:myTopic?transacted=true&acknowledgementModeName=SESSION_TRANSACTED")
.to("direct:importMessage");
}
}


@Component
public class ImportMessageRoute extends RouteBuilder {

@Override
public void configure() throws Exception {

onException(MyException.class).to("direct:processFailedMessage")

.log("Import failed").handled(true);

onException(Throwable.class).log("EXCEPTION -> rollback -> no
acknowledgement");

from("direct:importMessage").transacted()
.to("messageConsumer")
   .log("Message imported");
}
}


This does not work, the 'handled(true)' will be ignored in this scenario
and the message will not be acknowledged.

Is there another solution to handle this scenario?


Best regards, Andreas