You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by oc <ol...@gmail.com> on 2009/01/16 15:42:34 UTC

Problem with JMSTemplate and Transaction

Hi,

I want to receive several JMS message on a java client and I use JMSTemplate
class from Spring to do this.
I want also use transaction with annotation to validate the integrity of the
process.

In the scenario I send 5 JMS messages on the JMS queue.

http://www.nabble.com/file/p21500936/Etape1.gif 

To simulate a rollback on the transaction I read 2 JMS messages before throw
a Exception:

@Transactional(propagation=Propagation.REQUIRED,rollbackFor=JMSException.class)
    public Mail receiveMail() throws JMSException {
           
      int i=0;
      while(i<2){
        Object m = (Object) getJmsTemplate().receive();
        System.out.println("mail:"+m);      
        i++;
      }
      throw new JMSException("coucou");     
        
    }
	
In the log we can see that a transaction is created and rollBack after the
Exception (see the log.txt file)	
We can see in the ActiveMQ console that the Redelivered attribut value is
true for All JMS Message.

http://www.nabble.com/file/p21500936/Etape2.gif 

I don't understand why all JMS attribut have bean update because only 2 JMS
message have been received?

After that I execute this code to receive all JMS message on the queue:


@Transactional(propagation=Propagation.REQUIRED,rollbackFor=JMSException.class)
    public Mail receiveMail() throws JMSException {
           
      Object m = null;
      while(( m = (Object) getJmsTemplate().receive() )!=null){
        System.out.println("mail:"+m); 
      }
      return null;    
        
    }
	
I receive only 3 JMS messages, not 5. In the ActiveMQ console I can see 2
JMS message are in the queue, this is the 2 JMS messages which was received
just before throw en Exception and rollBack the transaction.

http://www.nabble.com/file/p21500936/Etape3.gif 

I can't receive again this 2 messages , so I lost them?
What I'm doing wrong?

Thank's a lot for your help.

o.c

-- 
View this message in context: http://www.nabble.com/Problem-with-JMSTemplate-and-Transaction-tp21500936p21500936.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.