My Oracle Support Banner

Reading JMS Messages from Multiple Queues Using Async and Sync API Does not Commit the Messages (Doc ID 2513207.1)

Last updated on DECEMBER 16, 2023

Applies to:

Oracle WebLogic Server - Version 10.3.6 and later
Information in this document applies to any platform.

Symptoms

WebLogic JMS client - reading multiple queues using async and sync API does not commit all messages.

Problem when reading messages from multiple JMS Queues in a single transaction using WebLogic JMS client (wlthin3client.jar) from WebLogic 11g (WebLogic Server 10.3.6.0).


Try to read first one message from queue Q1 and then, if this message satisfy some requirements, read other message (if available at that time) from queue Q2.

Expectation is that after committing the transaction both messages should disappear from Q1 and Q2. In case of rollback - messages should remain in both Q1 and Q2.

Initial approach was to use an asynchronous queue receiver to read from Q1 and then synchronously read from Q2 when it is needed:

void run() throws JMSException, NamingException {
  QueueConnectionFactory cf = (QueueConnectionFactory) ctx.lookup(connectionFactory);

  // create connection and session
  conn = cf.createQueueConnection();
  session = conn.createQueueSession(true, Session.SESSION_TRANSACTED);
  Queue q1 = (Queue) ctx.lookup(queue1);

  // setup async receiver for Q1
  QueueReceiver q1Receiver = session.createReceiver(q1 );
  q1Receiver.setMessageListener(this);

  conn.start();

  // ...
  // after messages are processed
  conn.close();
}

@Override
public void onMessage(Message q1msg) {
  try {
  QueueReceiver q2receiver = session.createReceiver(queue2);
  if(shouldReadFromQ2(q1msg)){
  // synchronous receive from Q2
  Message q2msg = q2receiver.receiveNoWait();
  process(q2msg);
  }
  session.commit();
  } catch (JMSException e) {
  e.printStackTrace();
  } finally {
  q2receiver.close();
  }
}

Even though when a session.commit() is executed, the message from Q1 remains uncommitted.

It is in receive state until the connection or receiver is closed. Then it seems to be rolled back as it gets delayed state.

Changes

 

Cause

To view full details, sign in with your My Oracle Support account.

Don't have a My Oracle Support account? Click to get started!


In this Document
Symptoms
Changes
Cause
Solution
References


My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.