Search code examples
javajmsweblogicmessage-queue

JMS performance


I'm having a bit of trouble with understanding JMS from a performance perspective. We have this very straightforward code in our application:

QueueConnection connection = null;
QueueSession session = null;
QueueSender sender = null;
TextMessage msg = null;

try {
  // The JNDIHelper uses InitialContext to look up things
  QueueConnectionFactory qcf = JNDIHelper.lookupFactory();
  Queue destQueue = JNDIHelper.lookupQueue();

  // These objects are created for every message, which is quite slow
  connection = qcf.createQueueConnection();
  session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
  sender = session.createSender(destQueue);

  // This is the actual message
  msg = session.createTextMessage(xmlMsg);
  sender.setTimeToLive(0);
  sender.send(msg);
} 
finally {

  // Close all objects again
  JMSUtilities.safeClose(sender);
  JMSUtilities.safeClose(session);
  JMSUtilities.safeClose(connection);
}

The code is correct, but probably some of the above artefacts could be reused for several messages. These are our configurations:

  • We use Oracle Weblogic 10.3.3
  • Weblogic connects to IBM MQ 7.0 (Problem also appears with 6.0) for JMS
  • The above logic is executed by a single thread on a backend server. It would be simple to keep some objects (QueueConnection, QueueSession, QueueSender) in memory as there is no concurrency involved.

My questions

  • Which types of objects can be shared among several messages? (of course we'd include error recovery, restoring those shared objects)
  • What are best practices to improve performance?

Solution

  • The only thing you need to create again and again is the msg itself - if you are sending to the same queue.

    So yes, you can remember the Connection, Session and Sender.