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

  • Spring JMS Transaction

    Currently we are in the process of refactoring our traditional JMS code to spring JMS. In the current process we are retaining the message in Q if there are any business exception. We are not using XA transactions in app but instead we are using qSession.rollback() and qSession.commit().
    How can we achieve the same using spring DefaultMessageListenerContainer.

    Current code:
    -------------

    qs = qc.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);

    public void onMessage(Message message) {
    if (message instanceof TextMessage) {
    ...
    }

    processMessage(strMessage);
    }

    public void processMessage(String message) {
    try {
    .....
    .....
    qSession.commit();
    } catch (Exception e) {
    // in case of exception we want message to remain in Q
    qSession.rollback();
    }
    }

    New Code:
    ----------

    spring context xml entries
    ---------------------------
    ....
    ....
    <bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMes sageListenerContainer">
    <property name="concurrentConsumers" value="1" />
    <property name="connectionFactory" ref="connectionFactory" />
    <property name="destination" ref="invoiceQueue" />
    <property name="messageListener" ref="messageListener" />
    </bean>

    public void onMessage(Message message) {
    if (message instanceof TextMessage) {
    ...
    }

    processMessage(strMessage);
    }

    public void processMessage(String message) {
    try {
    .....
    .....
    //qSession.commit(); // how can it be implemented in spring ???
    } catch (Exception e) {
    // in case of exception we want message to remain in Q
    // qSession.rollback(); // how can it be implemented in spring ???
    }
    }

    I really appreciate your help.

    Thanks

  • #2
    Container does that for you...

    Simple set the sessionTransacted property to true and presto.

    Comment


    • #3
      Spring JMS Transaction

      Thanks Marten.. I will try with sessionTransacted property..

      Thanks

      Comment


      • #4
        but not in 2.5.1 :-)

        due to the bug http://jira.springframework.org/browse/SPR-4445 this wont work in 2.5.1 (works fine again in 2.5.2)

        Comment


        • #5
          Spring JMS Transaction

          Martin,

          Thanks a lot for updating. I really appreciate it.

          -Prem

          Comment

          Working...
          X