Announcement Announcement Module
No announcement yet.
jms programmatic transaction Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • jms programmatic transaction

    I need to send/receive jms messages without transaction autocommit in one part of the application and commit/rollback transaction later in other part of application. So, I am trying to figure out how to use transaction manager to control transaction. My problem is as soon as jms template sends a message it autocommited to the queue. I don't want this message get auto commited. I want to be able to control transaction using transaction manager. How do I do that? What am I missing in my code below that always commits message to the queue? Could you please provide small example of sending a message using transaction manager without auto commit?

    final JmsTemplate102 jmsTemplate = (JmsTemplate102)factory.getBean("jmsQueueTemplate" );
    JmsTransactionManager102 jmsTranMan =
    (JmsTransactionManager102)factory.getBean("jmsTran sactionManager");

    TransactionTemplate tt = new TransactionTemplate(jmsTranMan);

    TransactionStatus s = tt.execute(new TransactionCallback() {

    public Object doInTransaction(TransactionStatus status) {
    jmsTemplate.send(new MessageCreator() {
    public Message createMessage(Session session) throws JMSException {
    Message m = session.createTextMessage("hello queue world1");
    return m;

    return status;

    jmsTranMan.rollback(s); //This line does not have affect since sent message has been autocommited to the queue


  • #2
    What is executed inside the TransactionTemplate is transactional and will be committed afterwards. So what you are trying here is pretty much useless (as it already has been committed NOT autocommitted but simply by the TransactionTemplate).

    ANd please next time use [ code][/code ] tags when posting code that way it remains readable.