Announcement Announcement Module
Collapse
No announcement yet.
Can JTA and JMS work together ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can JTA and JMS work together ?

    Hello.

    I'm trying to understand how JmsTemplate bean can take part in JTA Global transaction. In JmsTemplate.java from org.springframework.org.jms.core package I found two places with session.commit() :

    at line 608 (in doSend() code):
    Code:
    if (session.getTransacted() && !TransactionSynchronizationManager.hasResource(getConnectionFactory())) {
        // transacted session created by this template -> commit
        session.commit();
    }
    and at line 727 (in doReceive() code):
    Code:
    if (session.getTransacted()) {
         if (conHolder == null) {
            // transacted session created by this template -> commit
            session.commit();
        }
    }
    For session created in JTA transaction session.getTransacted() returns true, at least for JORAM and ActiveMQ implementation of XASession.

    For second condition in first snippet TransactionSynchronizationManager.bindResource() should be called somewhere, but JtaTransactionManager have no such call.

    As a result when I'm trying to use JMS XA-aware ConnectionFactory/Connection/Session (slightly modified JONAS JConnectionFactory/JConnection/JSession) with JtaTransactionManager, i'm getting exception
    Code:
    "XASession: commit not allowed"
    from JSession.

    I'm tried to make call to TransactionSynchronizationManager.bindResource(myC onnectionFactory, null) before starting JMS&JTA - it works for doSend(), but does not prevent commit in doReceive().
    On the other hand TransactionSynchronizationManager.bindResource(myC onnectionFactory, new ConnectionHolder(null, null)) - can work with doReceive(), but not with doSend().

    Can someone show the solution for this issue ?

    Regards, Igor
Working...
X