1 Reply Latest reply on Jan 11, 2007 9:43 AM by Tim Fox

    MDB Redelivery bizarre behaviour

    mskonda Apprentice

      I created a simple durable MDB.

      In my onMessage(), I create an Exception and throw it so that during try-catch, I'll rollback the Tx by calling mdbContext.setRollbackOnly().

      I pump in messages to the destination where this MDB is listening to.

      First message is redelivered as expected. The second time, it won't. Thirdtime again it does. Fourth time no.. So, the redelivery occurs for every alternate process..!!

      Either I must be missing fundamentally something or something is wrong with MBD redelivery mechanism.
      My onMessage looks like this:

      public void onMessage(Message message)
       {
       counter++;
       try
       {
       logger.info("---> onMessage" + this.hashCode() + ": message "
       + message.getJMSMessageID());
      
       if(message.getJMSRedelivered())
       {
       logger.info(" ---> MESSAGE IS REDELIVERED ");
       }
       logger.info(" ---> Throwing ex");
      
       throw new Exception("ex");
      
       } catch (Exception e)
       {
       logger
       .info(" ---> Exception occured. Rolling back Tx (must retry)-"
       + mdbContext);
       getMessageDrivenContext().setRollbackOnly();
       }
       }
      


      My deployment descriptors:

      JBOSS.xml
      <message-driven>
       <configuration-name>Standard Message Driven Bean</configuration-name>
       <ejb-name>testMDB</ejb-name>
       <local-jndi-name>testMDB</local-jndi-name>
       <mdb-client-id>testMDB</mdb-client-id>
       <mdb-subscription-id>testMDB</mdb-subscription-id>
       <destination-jndi-name>/topic/testTopic</destination-jndi-name>
       </message-driven>
      
      EJB-JAR.xml
      
       <enterprise-beans>
       <message-driven>
       <ejb-name>testMDB</ejb-name>
       <ejb-class>test.com.cmi2.jms.TestMDB</ejb-class>
       <transaction-type>Container</transaction-type>
       <message-driven-destination>
       <destination-type>javax.jms.Topic</destination-type>
       <subscription-durability>Durable</subscription-durability>
       </message-driven-destination>
       </message-driven>
       </enterprise-beans>
      


      My console log when a message is first sent:

      14:31:32,723 INFO [TestMDB] ---> onMessage34695986: message ID:JBM-4567040
      14:31:32,723 INFO [TestMDB] ---> Throwing ex
      14:31:32,723 INFO [TestMDB] ---> Exception occured. Rolling back Tx (must retry)
      
      14:31:32,727 INFO [TestMDB] ---> onMessage34695986: message ID:JBM-4567040
      14:31:32,727 INFO [TestMDB] ---> MESSAGE IS REDELIVERED
      14:31:32,727 INFO [TestMDB] ---> Throwing ex
      14:31:32,727 INFO [TestMDB] ---> Exception occured. Rolling back Tx (must retry)
      
      14:31:32,730 INFO [TestMDB] ---> onMessage34695986: message ID:JBM-4567040
      14:31:32,730 INFO [TestMDB] ---> MESSAGE IS REDELIVERED
      14:31:32,730 INFO [TestMDB] ---> Throwing ex
      14:31:32,731 INFO [TestMDB] ---> Exception occured. Rolling back Tx (must retry)
      
      14:31:32,733 INFO [TestMDB] ---> onMessage34695986: message ID:JBM-4567040
      14:31:32,734 INFO [TestMDB] ---> MESSAGE IS REDELIVERED
      14:31:32,734 INFO [TestMDB] ---> Throwing ex
      14:31:32,734 INFO [TestMDB] ---> Exception occured. Rolling back Tx (must retry)
      14:31:32,736 WARN [DLQHandler] Message resent too many times; sending it to DLQ; message id=ID:JBM-4567040
      


      When a message is sent second time:
      
      14:31:50,791 INFO [TestMDB] ---> onMessage34695986: message ID:JBM-4567296
      14:31:50,791 INFO [TestMDB] ---> Throwing ex
      14:31:50,791 INFO [TestMDB] ---> Exception occured. Rolling back Tx (must retry)
      
      


      I am a bit confused - so any pointers are higly appreciated!

      Thanks
      Madhu