Results 1 to 5 of 5

Thread: Spring JMS Transaction

  1. #1
    Join Date
    Oct 2006
    Posts
    6

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Container does that for you...

    Simple set the sessionTransacted property to true and presto.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Oct 2006
    Posts
    6

    Default Spring JMS Transaction

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

    Thanks

  4. #4
    Join Date
    May 2008
    Posts
    1

    Default 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)

  5. #5
    Join Date
    Oct 2006
    Posts
    6

    Default Spring JMS Transaction

    Martin,

    Thanks a lot for updating. I really appreciate it.

    -Prem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •