-
Apr 2nd, 2008, 09:55 PM
#1
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
-
Apr 3rd, 2008, 04:23 AM
#2
Container does that for you...
Simple set the sessionTransacted property to true and presto.
-
Apr 5th, 2008, 09:36 AM
#3
Spring JMS Transaction
Thanks Marten.. I will try with sessionTransacted property..
Thanks
-
May 13th, 2008, 09:24 AM
#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)
-
May 15th, 2008, 08:58 PM
#5
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
-
Forum Rules