我不知道這是用C可能的,但是從PL/SQL,您可以創建具有以下簽名的回調過程。
CREATE PROCEDURE demo_queue_callback_procedure(
context RAW,
reginfo SYS.AQ$_REG_INFO,
descr SYS.AQ$_DESCRIPTOR,
payload RAW,
payloadl NUMBER
) AS
r_dequeue_options DBMS_AQ.DEQUEUE_OPTIONS_T;
r_message_properties DBMS_AQ.MESSAGE_PROPERTIES_T;
v_message_handle RAW(16);
o_payload demo_queue_payload_type;
BEGIN
r_dequeue_options.msgid := descr.msg_id;
r_dequeue_options.consumer_name := descr.consumer_name;
DBMS_AQ.DEQUEUE(
queue_name => descr.queue_name,
dequeue_options => r_dequeue_options,
message_properties => r_message_properties,
payload => o_payload,
msgid => v_message_handle
);
-- Do something with the payload received. Must commit to get message out of table.
COMMIT;
END; /
- 創建一個用戶,並註冊回調過程
DBMS_AQADM.ADD_SUBSCRIBER (
queue_name => 'demo_queue',
subscriber => SYS.AQ$_AGENT(
'demo_queue_subscriber',
NULL,
NULL)
);
DBMS_AQ.REGISTER (
SYS.AQ$_REG_INFO_LIST(
SYS.AQ$_REG_INFO(
'DEMO_QUEUE:DEMO_QUEUE_SUBSCRIBER',
DBMS_AQ.NAMESPACE_AQ,
'plsql://DEMO_QUEUE_CALLBACK_PROCEDURE',
HEXTORAW('FF')
)
),
1
);
你將不得不改變上述從錯誤隊列中讀取,但我認爲概念是相同的。
我沒有得到如何以這種方式它會自動出隊,如果在隊列中的東西? – user1
因爲您通過調用DBMS_AQ.Register將註冊存儲過程作爲處理程序。每次消息在隊列中時都會調用此過程。請參閱以下鏈接:[鏈接](http://www.oratechinfo.co.uk/aq.html)[鏈接](http://docs.oracle.com/cd/B12037_01/appdev.101/b10802/d_aq熱媒) – OldProgrammer