Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-16270

Topic messages are not sent when using transacted JmsTemplate in 'TransactionSynchronization.afterCommit' phase

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 4.3.11
    • Fix Version/s: General Backlog
    • Component/s: JMS, Transaction
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      On the following scenario, an attempt to send message to a TOPIC using JmsTemplate is not effective (the message is never sent and there is no error):
      1. Open Transaction using spring framework
      2. Register TransactionSynchronization to the active Transaction
      3. On the TransactionSynchronization, implement the 'afterCommit' as below:

      • create JmsTemplate and set it to be 'transacted'
      • send a message to a topic
        4. commit the Transaction

      The expectation is that the message would be send and the subscriber would handle it.
      On real, the message is never handled by the subscriber. The reason is that the message wasn't truly send.

      Other observations:
      The expectation is fulfilled and the subscriber gets the message if:
      a) Using 'afterCompletion' instead of 'afterCommit',
      b) Using none transacted JmsTemplate (on the 'afterCommit')

      It appears that Spring determines the existence of an ongoing transaction by checking state

      _TransactionSynchronizationManager
      public static boolean isSynchronizationActive()

      { return synchronizations.get() != null; }

      _

      Since the 'synchronizations' thread local is not cleared when executing the 'afterCommit' callback, Spring mistakenly assumes that there is ongoing transaction and hence bounds the JMS operation to the ongoing transaction (instead of commiting it immediately) and since there is no ongoing transaction the JMS operation would never be committed.
      (When using 'afterCompletion' it works since the 'synchronizations' thread local was cleared)

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              ofer.baranes ofer baranes
              Last updater:
              Spring Issues Spring Issues
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Days since last comment:
                3 years, 23 weeks, 5 days ago