Announcement Announcement Module
Collapse
No announcement yet.
JMS from within TransactionSynchronizationAdapter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JMS from within TransactionSynchronizationAdapter

    I am trying to send a JMS message after a database transaction completes; the obvious thing seemed to register a callback with the TransactionSynchronizationManager.

    However, I am unable to send a JMS message from within the TransactionSynchronizationAdapter that I register. There is no exception, but the message is never sent (jconsole shows that the Mbean for my destination has 0 enqueue and dequeue count, although the producer count goes up by 1.

    This does not work
    Code:
    TransactionSynchronizationManager.registerSynchronization(
      new TransactionSynchronizationAdapter() {
        public void afterCommit() {
          jmsTemplate.convertAndSend(destination, message);
        }
      }
    }
    If I use the same JMS template and sending code it works outside of the adapter and it works from an arbitrary thread started from the adapter, but not from the adapter itself.

    This works
    Code:
    TransactionSynchronizationManager.registerSynchronization(
      new TransactionSynchronizationAdapter() {
        public void afterCommit() {
            Thread T = new Thread() {
               public void run() {
                  jmsTemplate.convertAndSend(destination, message);
               }
             }; T.start();
        }
      }
    }
    Could someone identify what I am doing wrong? The TransactionSynchronizationManager seems to apply to JMS as well, but I would rather not setup XA if I could avoid it (since I have never done it and don't really need it).
Working...
X