3 Replies Latest reply: Sep 19, 2011 1:53 AM by 546634 RSS

    JMS - UserTransaction - Commit issue

    546634
      Introduction
      --------------------------------------------------------------------------------
      I am moving from WebSphere to Weblogic and have counterd an UserTransaction commit issue.
      The code have not been modified, however the logic in Weblogic and Websphere behaves different.

      The messagingsystem is Websphere MQ, in Weblogic I have QCF, destinations, host and port etc. in a .bindings file, and I have configured JMS server and JMS modules with corresponding jndi names.

      I have verified that this configuration is correct throug a custom develop testtool deployed in WL, message is sent successfully to MQ.

      The problem - description
      --------------------------------------------------------------------------------
      However in my application i'm using UserTransaction and this is not working as expected.
      I have two classes that communicate with MQ (AbcDAO.java and QueueBroker.java) AbcDAO.java creates a UserTransaction and communicates with Queuebroker throug a method called "SendToAutoS" this method retrives the corrilationId (for the message sendt to MQ) from Queuebroker.
      The SendMessage method creates qcf, queueconnection, queue etc and sends the message to MQ. When i debug this steps (line:queueSender.send(theMessage) I can verify in MQ that a message count is registerted in mq on the correct queue, but it's not shown (since its not commited). However when performing finalize in Queuebroker, which close both session and connection, the messagecount is gone in MQ, and when returing to AbcDAO.java to perform ut.commit(); there is not any message on Queue.

      For me it looks like the message is rolledback when session and connection closes.

      Actions tried
      --------------------------------------------------------------------------------
      If I change this line QueueBroker , transacted to false witch i understand sends message without the need to commit:
      boolean transacted = false;
      queueSession = queueConnection.createQueueSession(transacted, QueueSession.AUTO_ACKNOWLEDGE);

      the message is sendt successfully to MQ. However now either commit or rollback on the UserTransaction is working with transacted=false.

      I need the commit and rollback to be done on the UserTransaction for my application.
      Anyone have an idea why this is not working?

      The files - content
      --------------------------------------------------------------------------------

      AbcDAO.java - that creates a usertransaction
      --------------------------------------------------------------------------------
      ut = ServiceLocator.getInstance().getUserTransaction();
      ut.begin();
      msgCorId = sendToAutoS(userVO, messageSend, transactionQeueSend, transactionQeueFactory);
      ut.commit();

      //SendToAutoS - that calls the Queuebroker method - sendMessage
      private String sendToAutoS(UserVO userVO, String message, String transactionQueue, String transactionQueueFactory) throws DaoException {
      try {
      log.debug("..");
      return QueueBroker.getInstance().sendMessage(message, transactionQueue, transactionQueueFactory);
      } catch (BrokerException be) {
      log.error("BrokerException", be);
      ...
      ..
      }
      }



      QueueBroker.java - that sends the message to MQ
      --------------------------------------------------------------------------------
      public String sendMessage(String message, String transactionQueue, String transactionQueueFactory) throws BrokerException {
      try {
      // Get service locator
      ServiceLocator sl = ServiceLocator.getInstance();
      // Create QueueConnectionFactory with help form service locator
      queueConnectionFactory = (QueueConnectionFactory) sl.getQueueConnectionFactory(transactionQueueFactory);
      // Create QueueConnection
      queueConnection = queueConnectionFactory.createQueueConnection();
      // Create QueueSession, transacted - client has to commit !
      boolean transacted = true;
      queueSession = queueConnection.createQueueSession(transacted, QueueSession.AUTO_ACKNOWLEDGE);
      // Create queue with help from service locator
      queue = (Queue) sl.getQueue(transactionQueue);
      // Create QueueSender
      queueSender = queueSession.createSender(queue);
      // Create message and sent it
      Message theMessage = null;
      theMessage = queueSession.createTextMessage(message);
      // Log time
      long time = System.currentTimeMillis();
      // Set log time on message
      theMessage.setJMSTimestamp(time);
      // Send
      queueSender.send(theMessage);
      queueSender.close();
      // Return unique messageID for message just been sent
      return theMessage.getJMSMessageID();
      } catch (JMSException je) {
      BrokerException ex = new BrokerException();
      ex.setMessageKey("requisition.jms.broker.queue");
      Object[] o = {"SEND", "String to Autosys = " + message};
      ex.setMessageArgs(o);
      ex.setRootCause(je);
      throw ex;
      } catch (ServiceLocatorException e) {
      BrokerException ex = new BrokerException();
      ex.setMessageKey(e.getMessageKey());
      ex.setMessageArgs(e.getMessageArgs());
      ex.setRootCause(e.getRootCause());
      throw ex;
      } finally {
      // Clean up - close connection and session if exist
      if (queueConnection != null) {

      finalize();
      }
      }
      }

      /**
      * Finalize queue handling
      *
      * @throws BrokerException e
      */
      protected void finalize() throws BrokerException {
      try {
      // Close connections
      queueSession.close();
      queueConnection.close();
      } catch (JMSException je) {
      BrokerException ex = new BrokerException();
      ex.setMessageKey("requisition.jms.broker.queue");
      Object[] o = {"FINALIZE", "Close connections" };
      ex.setMessageArgs(o);
      ex.setRootCause(je);
      throw ex;
      }
      }

      Edited by: reZer on 14.sep.2011 13:05

      Edited by: reZer on 14.sep.2011 13:06