3 Replies Latest reply on Jul 12, 2004 7:28 PM by iamapony

    JBossMQ, JMS Message in transaction?

    iamapony

      I have a MDB attached to QueueA, in a SessionBean method I write a record to the database and then send a message to QueueA to do something with that database record. The onMessage in the MDB then fails because it can't find the message, showing me that the JMS message is not participating in the transaction and is being sent before the DB commit. What's the process to have JMS Send operation participate in the JTA transaction? I'm using the RMIXAConnectionFactory.

      Thanks,

      Ryan

        • 1. Re: JBossMQ, JMS Message in transaction?

          Show the code that sends the message to QueueA in your session bean.

          It should NOT use JMS transacted session (i.e. pass true when you create your JMS session). If your Session Bean is enlisted to a JTA transaction, sending of the JMS message will also be enlisted automatically.

          Regards,

          Stephane

          • 2. Re: JBossMQ, JMS Message in transaction?
            iamapony

            That's what I thought as well, but it doesn't appear to be happening.. Here's the code.


            QueueSender sender = null;
            QueueSession session = null;
            QueueConnection conn = null;
            try {
            InitialContext iniCtx = new InitialContext();
            Object tmp = iniCtx.lookup("RMIXAConnectionFactory");
            QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
            conn = qcf.createQueueConnection();
            Queue queA = (Queue) iniCtx.lookup("queue/A");
            session = conn.createQueueSession(false,
            QueueSession.AUTO_ACKNOWLEDGE);
            conn.start();
            sender = session.createSender(queA);
            ObjectMessage om = session.createObjectMessage(message);
            sender.send(om);
            } catch (NamingException e) {
            e.printStackTrace();
            } catch (Exception e) {
            e.printStackTrace();
            } finally {
            // Ensure that the Connection always gets closed
            try {
            if (sender != null) {
            sender.close();
            sender = null;
            }
            if (session != null) {
            session.close();
            session = null;
            }
            if (conn != null) {
            conn.close();
            conn = null;
            }

            } catch (JMSException je) {
            je.printStackTrace();
            }
            }

            • 3. Re: JBossMQ, JMS Message in transaction?
              iamapony

              Found the answer, you have to use the java:/JmsXA JMS Provider Resource... More information and sample code in link below.

              http://www.jboss.org/wiki/Wiki.jsp?page=JmsSenderBean