How to stop getting messages deleted without acknowledgement in Oracle AQ?

泪湿孤枕 提交于 2020-03-25 12:32:16

问题


I have set up a single customer Oracle AQ. I observe messages from this queue in a Java web application with CLIENT_ACKNOWLEDGE mode. But as soon as I receive the messages in the onMessage method, the messages seems to be getting deleted from the Oracle Queue. My assumption is, the message should not get deleted unless I acknowledge them in the client. How do I stop this?

Oracle Queue schema looks like this:

BEGIN DBMS_AQADM.CREATE_QUEUE_TABLE(
  Queue_table => '"TESTUSER"."myqueuetable"', 
  Queue_payload_type => 'TESTUSER.messageobject', 
  multiple_consumers => false
);
END;
/

BEGIN DBMS_AQADM.CREATE_QUEUE(
  Queue_name => 'TESTUSER.myqueue', 
  Queue_table => 'TESTUSER.myqueuetable', 
  Queue_type => 0, Max_retries => 5, Retry_delay => 0
);
END;
/

BEGIN dbms_aqadm.start_queue (
  queue_name => 'testuser.myqueue'
);
END;

I observer for the messages in my Java application like this

 //somewhere in my app
session = queueConnection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
queueReceiver = ((AQjmsSession) databaseConnectionManager.getSession())
 .createReceiver(databaseConnectionManager.getQueue(), Messageobject.getORADataFactory());
queueReceiver.setMessageListener(this);


//in my listener class
@Override
public void onMessage(Message message) {
 AdtMessage msg = (AdtMessage) message;

 try {
  Messageobject message = (Messageobject) msg.getAdtPayload();

  if (isUserConnected(message.userId)) {
   logger.debug("Message acknowledged");
   msg.acknowledge();
   //handle the message. the message should be deleted now.
  } else {
   //i don't want the message to be deleted
  }

 } catch (JMSException | IllegalArgumentException | SQLException e) {
  logger.error("An error occurred while sending an outgoing blob", e);
 }
}

来源:https://stackoverflow.com/questions/60372579/how-to-stop-getting-messages-deleted-without-acknowledgement-in-oracle-aq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!