使用Oracle Multi Consumer Queue,消息在出列后仍保留在队列表中。保留设置为0.
创建队列表:
BEGIN DBMS_AQADM.CREATE_QUEUE_TABLE(
Queue_table => '"ZEE_EXEC"."ZEE_SYNC"',
Queue_payload_type => 'ZEE_EXEC.T_SYNC',
storage_clause => 'PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 TABLESPACE ZEE_GENERAL',
Sort_list => 'ENQ_TIME',
Multiple_consumers => TRUE,
Compatible => '10.0.0');
END;
创建队列:
BEGIN DBMS_AQADM.CREATE_QUEUE(
Queue_name => 'ZEE_EXEC.SYNCQUEUE',
Queue_table => 'ZEE_EXEC.ZEE_SYNC',
Queue_type => 0,
Max_retries => 5,
Retry_delay => 0,
dependency_tracking => FALSE);
END;
使用PLSQL出队:
DECLARE
dequeue_options DBMS_AQ.dequeue_options_t;
message_properties DBMS_AQ.message_properties_t;
message_handle RAW(16);
message T_SYNC;
BEGIN
dequeue_options.navigation := DBMS_AQ.FIRST_MESSAGE;
dequeue_options.consumer_name := 'ZEE_TOPIC';
DBMS_AQ.DEQUEUE(
queue_name => 'ZEESYNCQUEUE',
dequeue_options => dequeue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
COMMIT;
END;
使用JAVA(样本)出列队列:
q_sess = q_conn.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
topic = ((AQjmsSession) q_sess).getTopic("ZEE_EXEC", "SYNCQUEUE");
ORADataFactory orad = TSync.getORADataFactory();
receiver = ((AQjmsSession) q_sess).createTopicReceiver(topic, "ZEE_TOPIC", null, orad);
我尝试过使用不同的实现。 我可以显式地将会话事务设置为true或false,对AUTO_ACKNOWLEDGEMENT,CLIENT_ACKNOWLEDGEMENT,SESSION_TRANSACTED的确认没有区别。使用PLSQL和JAVA出列时会收到消息,但消息仍在队列中。保留设置为0.对消息,topicSession和会话使用JAVA确认并没有区别。
我在数据库方面并不强大,但研究显示:
SELECT * FROM dba_tab_privs WHERE grantee = 'ZEE_EXEC' AND table_name = 'dbms_aqjms';
应该显示一些结果,但它没有。是否有可能我没有足够的权限将消息出列?如果是这样,我怎么能看到它却不承认呢?
调试应用程序我没有例外,它确认消息并在会话上提交正常,我唯一一次获得异常就是当我将会话事务处理设置为false时。