You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Alexis Hassler <al...@gmail.com> on 2016/05/04 11:33:51 UTC

JTA Transaction in a MessageListener

Hi,

Lately, I've sent a PR to the Narayana project in order to support JTA
transactions in JMS MessageListener.

In this PR, I started a JTA transaction in the onMessage method. The PR
will be rejected because starting the transaction in the onMessage is too
late : the message has already been dequeued.

My problem is that the integration test (with artemis) passes, and I don't
understand why.

Can anyone explain me why it works, and how which test I can do to prove
that the solution is not relevant ?

Here is the PR : https://github.com/jbosstm/narayana/pull/1004
And the MessageListener is here :
https://github.com/hasalex/narayana/blob/master/ArjunaJTA/jms/src/main/java/org/jboss/narayana/jta/jms/MessageListenerProxy.java

Thanks for your help,

Alexis
http://www.jtips.info, http://blog.alexis-hassler.com, http://www.mix-it.fr

Re: JTA Transaction in a MessageListener

Posted by Alexis Hassler <al...@gmail.com>.
Thanks for your answer Martyn. Really useful.


Alexis
http://www.jtips.info, http://blog.alexis-hassler.com
<http://www.lyonjug.org>

2016-05-05 16:22 GMT+02:00 Martyn Taylor <mt...@redhat.com>:

> Hi Alexis,
>
> The onMessage() method (when invoked outside of an container) would be
> called outside the boundaries of a transaction.  I see you are using
> XASession in the test you provided.  When onMessage() is called, and a
> message consumed, with an XASession, it would be done so with an ack mode
> equal to XA in the session, but with no XA transaction started. This means
> the consumed message is essentially orphaned (not associated with any
> transaction).  The JMS spec does not state what to do in this case as this
> shouldn't really happen, the XASession should only ever be used within the
> context of a Tx.  If an orphaned message does happen, with Artemis
> XASession, Artemis will associate the message with the next transaction.
> This is a consequence of how we have optimised acking messages.  But would
> likely behave differently with different providers.  As the spec isn't
> specific.
>
> I'm not sure what your use case is, but if you're trying to achieve MDB
> like behaviour outside an application server.  It might be worth looking at
> this:  http://activemq.apache.org/jca-container.html.
>
> I hope this helps.
>
> Regards
> Martyn
>
>
>
> On Wed, May 4, 2016 at 12:33 PM, Alexis Hassler <al...@gmail.com>
> wrote:
>
> > Hi,
> >
> > Lately, I've sent a PR to the Narayana project in order to support JTA
> > transactions in JMS MessageListener.
> >
> > In this PR, I started a JTA transaction in the onMessage method. The PR
> > will be rejected because starting the transaction in the onMessage is too
> > late : the message has already been dequeued.
> >
> > My problem is that the integration test (with artemis) passes, and I
> don't
> > understand why.
> >
> > Can anyone explain me why it works, and how which test I can do to prove
> > that the solution is not relevant ?
> >
> > Here is the PR : https://github.com/jbosstm/narayana/pull/1004
> > And the MessageListener is here :
> >
> >
> https://github.com/hasalex/narayana/blob/master/ArjunaJTA/jms/src/main/java/org/jboss/narayana/jta/jms/MessageListenerProxy.java
> >
> > Thanks for your help,
> >
> > Alexis
> > http://www.jtips.info, http://blog.alexis-hassler.com,
> > http://www.mix-it.fr
> >
>

Re: JTA Transaction in a MessageListener

Posted by Martyn Taylor <mt...@redhat.com>.
Hi Alexis,

The onMessage() method (when invoked outside of an container) would be
called outside the boundaries of a transaction.  I see you are using
XASession in the test you provided.  When onMessage() is called, and a
message consumed, with an XASession, it would be done so with an ack mode
equal to XA in the session, but with no XA transaction started. This means
the consumed message is essentially orphaned (not associated with any
transaction).  The JMS spec does not state what to do in this case as this
shouldn't really happen, the XASession should only ever be used within the
context of a Tx.  If an orphaned message does happen, with Artemis
XASession, Artemis will associate the message with the next transaction.
This is a consequence of how we have optimised acking messages.  But would
likely behave differently with different providers.  As the spec isn't
specific.

I'm not sure what your use case is, but if you're trying to achieve MDB
like behaviour outside an application server.  It might be worth looking at
this:  http://activemq.apache.org/jca-container.html.

I hope this helps.

Regards
Martyn



On Wed, May 4, 2016 at 12:33 PM, Alexis Hassler <al...@gmail.com>
wrote:

> Hi,
>
> Lately, I've sent a PR to the Narayana project in order to support JTA
> transactions in JMS MessageListener.
>
> In this PR, I started a JTA transaction in the onMessage method. The PR
> will be rejected because starting the transaction in the onMessage is too
> late : the message has already been dequeued.
>
> My problem is that the integration test (with artemis) passes, and I don't
> understand why.
>
> Can anyone explain me why it works, and how which test I can do to prove
> that the solution is not relevant ?
>
> Here is the PR : https://github.com/jbosstm/narayana/pull/1004
> And the MessageListener is here :
>
> https://github.com/hasalex/narayana/blob/master/ArjunaJTA/jms/src/main/java/org/jboss/narayana/jta/jms/MessageListenerProxy.java
>
> Thanks for your help,
>
> Alexis
> http://www.jtips.info, http://blog.alexis-hassler.com,
> http://www.mix-it.fr
>