Announcement Announcement Module
No announcement yet.
Spring AMQP Transactions on Send / Template Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring AMQP Transactions on Send / Template


    I am using the 20120213 build of 1.0.1 so that I don't have leaking channels. I want to do something like this (amqpTemplate has channel-transacted="true"):

    public void test() {
      for(int i=0; i < 10; i++) {
        // some database add's are happening here...
        // this allows me to watch the queue in the RabbitMQ admin
        try { Thread.sleep(15000); } catch (InterruptedException e) { ; }
      String test = null;
      if(test.endsWith("test")) { ; }
    As you can see the code loops 10 times and tries to send a message every 15 seconds. I'm expecting not to see the messages in the queue because at the end a NullPointerException is thrown and the transaction should roll back. I see all 10 messages, 1 appearing every 15 seconds, and they don't roll back. Is this the expected behavior or is this a bug?

    Thanks so much,

  • #2
    BTW: this behavior is also observed in the 1.0.0 release with the addition of leaking channels. Can anyone tell me if this is the expected behavior? Rollbacks seem to work flawless on the Listener side.


    • #3
      If you can show the stack trace from your exception we can see if there is actually a transaction in flight. What transaction manager are you using?

      Aside: note that 150sec for a transaction is pretty long and longer than most people or transactional resources would tolerate out of the box. I don't think that's the problem here because you are not seeing a rollback.


      • #4
        Dave, thank you very much for the response. I am having some very strange issues with my transaction annotations where some are working flawless and in the same context some aren't. I have to track it down before I can see if it's working with amqp. I will let you know how it turns out.

        BTW: i'm using org.springframework.orm.hibernate3.HibernateTransa ctionManager....


        • #5
          Dave, this was a false alarm. I have transactions working very well now. I had a non-annotated method call an annotated method in the same class. the outer non-annotated class was catching exceptions. somehow that was causing the transactions to commit.... if i moved the outer method out of the class and into another, then the transactions would roll back.... spring is, somehow, making the outer method transactional when both methods are in the same class. i guess this has to do with the proxies. i was pulling my hair out.