Forum Stats

  • 3,757,793 Users
  • 2,251,267 Discussions
  • 7,869,917 Comments

Discussions

JMS - UserTransaction - Commit issue

546634
546634 Member Posts: 23
edited Sep 19, 2011 2:53AM in Java Message Service (JMS)
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

Answers

  • gimbal2
    gimbal2 Member Posts: 11,949 Gold Trophy
    I know you are trying to send a JMS message, but just because this is true the generic JMS forum is not automatically the place you should ask questions like this. Your real beef is with the container you are using (Weblogic), UserTransaction and persistent JMS messages in combination with the specific JMS provider you are using.

    You will have far more chance to get help with this problem if you ask it in the Weblogic forum which you can also find on this very website. If you make a new post, be sure to create a link to it here so people can follow it.

    https://forums.oracle.com/forums/category.jspa?categoryID=193

    And perhaps more specific:

    3833
  • ramp
    ramp Member Posts: 2,358
    Are your JMS connections XA?
This discussion has been closed.