3 Replies Latest reply on Jul 25, 2007 5:31 PM by karl.martens

    Unexpected redelivery of messages

    karl.martens

      I'm trying to JBossMQ on JBoss AS 4.2.1 to participate in a JTA transaction. The client is an EJB 3.0 stateless session bean and I'm using and EJB 3.0 message driven bean to accept the messages. It appears that the messages are participating in the JTA transaction and being delivered properly (at the right time), however upon restart of JBoss the messages are being redelivered.

      I've completed the steps documented in the JBoss wiki [http://wiki.jboss.org/wiki/Wiki.jsp?page=ConfigJBossMQDB] for changing the underlying JMS database to MySQL and I'm using the @Resource(mappedName="java:/JmsXA") connection factory in the client to generate the message.

      The behaviours I'm witnessing are as follows:
      1) The client client initiates the message and nothing appears in the database until the outermost Stateless session bean commits (Expected)
      2) Once committed the message appears in the database with TXOP of 'A' (Expected)
      3) The message driven bean receives the message after the client has committed (Expected)
      4) The message has a TXOP value of 'A' and it remains 'A' until the end of the OnMessage call. Upon completion of the onMessage method the TXOP value is changed to 'D' (Expected)
      5) I stop and restart JBoss, all the messages in the database are being delivered even though they have TXOP value of 'D' (Unexpected)

      Some other details that may be useful, I'm sending the messages to a queue and the acknowledge mode is Auto-Acknowledge.

      Any ideas where I'm going wrong? How do I prevent the message from being delivered a second time, unless there was a problem with the first delivery?

      Thanks,
      Karl Martens

        • 1. Re: Unexpected redelivery of messages

          TXOP="D" means the transaction was prepared but not committed.

          Besides that, EJB3 questions are answered in the EJB3 forum.
          ConfigJBossMDB is useless for EJB3 its a whole different implementation.

          Nag the EJB3 developers to create a ConfigJBossMDBEJB3 like I've been
          trying to do for a while now. ;-)

          • 2. Re: Unexpected redelivery of messages

            You probably also want to configure this:
            http://jira.jboss.com/jira/browse/JBAS-1341 + related links
            since it isn't enabled by default
            (it is still considered "experimental" - i.e. not enough users have tried it out yet - no bugs have been reported with it, yet.... :-).

            • 3. Re: Unexpected redelivery of messages
              karl.martens

              Adrian,

              Thanks for your reply, I attempted to get the suggested XARecovery configuration operational. I did run into an error. Admittedly I'm new to reading the Jira but as I read it; the patch should be included in my version of the Application Server 4.2.1 and all that I should have to do is the configuration entries in jboss-4.2.1.GA/server/default/deploy/jms/mysql-jdbc2-service.xml

              The exception
              ===========
              org.jboss.mq.SpyJMSException: Could not restore messages to destination : QUEUE.xefex-eventQueue; - nested throwable: (java.sql.SQLException: Column Index out of range, 3 > 1. )
              at org.jboss.mq.pm.jdbc2.PersistenceManager.internalRestoreQueue(PersistenceManager.java:714)
              at org.jboss.mq.pm.jdbc2.PersistenceManager.restoreQueue(PersistenceManager.java:565)
              at org.jboss.mq.server.JMSQueue.(JMSQueue.java:66)
              at org.jboss.mq.server.jmx.Queue.startService(Queue.java:85)
              ...
              Caused by: java.sql.SQLException: Column Index out of range, 3 > 1.
              at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
              at com.mysql.jdbc.ResultSet.checkColumnBounds(ResultSet.java:662)

              Problem
              =======
              I've downloaded the JBoss AS source and I think the problem resides in line 620 of org.jboss.mq.pm.jdbc2.PersistenceManager

              stmt = c.prepareStatement(SELECT_MESSAGE_KEYS_IN_DEST);
              should read
              stmt = c.prepareStatement(selectMessagesInDest);

              Work around
              ===========
              In the file jboss-4.2.1.GA/server/default/deploy/jms/mysql-jdbc2-service.xml alter the line for the entry SELECT_MESSAGE_KEYS_IN_DEST to SELECT_MESSAGE_KEYS_IN_DEST = SELECT MESSAGEID, MESSAGEBLOB, TXID, TXOP FROM JMS_MESSAGES WHERE DESTINATION=?

              This should work in both the XA and non XA configuration as the columns are additive. Unfortunately after the fix XA recovery appears to be operational but it didn't solve my original problem. I'll bug the EJB3 guys to see if they can direct me into proper configuration for JBossMQ persistence with EJB3

              Thanks,
              Karl Martens