如何停止删除未经甲骨文AQ确认的消息? [英] How to stop getting messages deleted without acknowledgement in Oracle AQ?

查看:118
本文介绍了如何停止删除未经甲骨文AQ确认的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了一个客户Oracle AQ.我在CLIENT_ACKNOWLEDGE模式的Java Web应用程序中观察到了来自此队列的消息.但是,一旦我收到onMessage方法中的消息,这些消息似乎就会从Oracle队列中删除.我的假设是,除非我在客户端中将它们acknowledge删除,否则不应删除该消息.如何停止呢?

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模式如下:

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;

我这样观察我的Java应用程序中的消息

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);
 }
}

推荐答案

您正在创建一个使用者队列,该消息将在消息被成功使用后立即被删除.

You are creating a single consumer queue, for which message gets deleted as soon as it is consumed successfully.

要保留消息,请在创建队列时将tention_time设置为大于零的值.

To retain the message, set retention_time to a value greater than zero when creating a queue.

BEGIN 
  DBMS_AQADM.CREATE_QUEUE(
    Queue_name => 'TESTUSER.myqueue', 
    Queue_table => 'TESTUSER.myqueuetable', 
    Queue_type => 0, Max_retries => 5, Retry_delay => 0,
    retention_time => 300    -- retain for next 5 minutes
  );
END;
/

请参考 https://docs.oracle.com/database /121/ARPLS/d_aqadm.htm#ARPLS109

这篇关于如何停止删除未经甲骨文AQ确认的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆