我的问题在标题中被描述,消息有WAIT状态,我想更改延迟日期。如果不可能有一种方法使WAIT状态的消息出列?也许我可以将一些消息出列,然后加入我需要的延迟。
答案 0 :(得分:1)
如果我的理解是正确的,那么你正在寻找对出列令的控制。您可以使用dequeue_options参数:
SQL> CREATE TYPE demo_queue_payload_type AS OBJECT
2 ( message VARCHAR2(4000) );
3 /
SQL> BEGIN
2 DBMS_AQADM.CREATE_QUEUE_TABLE (
3 queue_table => 'demo_queue_table',
4 queue_payload_type => 'demo_queue_payload_type'
5 );
6 END;
7 /
SQL> BEGIN
2
3 DBMS_AQADM.CREATE_QUEUE (
4 queue_name => 'demo_queue',
5 queue_table => 'demo_queue_table'
6 );
7
8 DBMS_AQADM.START_QUEUE (
9 queue_name => 'demo_queue'
10 );
11
12 END;
13 /
SQL> CREATE TABLE message_track(msg varchar2(10), hndl raw(16))
2 /
SQL> DECLARE
2 r_enqueue_options DBMS_AQ.ENQUEUE_OPTIONS_T;
3 r_message_properties DBMS_AQ.MESSAGE_PROPERTIES_T;
4 v_message_handle RAW(16);
5 o_payload demo_queue_payload_type;
6
7 BEGIN
8
9 for i in 1..5 loop
10
11 o_payload := demo_queue_payload_type('message '||i);
12
13 DBMS_AQ.ENQUEUE(
14 queue_name => 'demo_queue',
15 enqueue_options => r_enqueue_options,
16 message_properties => r_message_properties,
17 payload => o_payload,
18 msgid => v_message_handle
19 );
20
21 insert into message_track values ('message '||i, v_message_handle);
22
23 end loop;
24
25 COMMIT;
26
27 END;
28 /
SQL> select * from message_track
2 /
MSG HNDL
---------- --------------------------------
message 1 F25F320406C504B1E043441318AC5E0A
message 2 F25F320406C604B1E043441318AC5E0A
message 3 F25F320406C704B1E043441318AC5E0A
message 4 F25F320406C804B1E043441318AC5E0A
message 5 F25F320406C904B1E043441318AC5E0A
SQL> select MSG_ID, user_data FROM aq$demo_queue_table
2 /
MSG_ID
--------------------------------
USER_DATA(MESSAGE)
--------------------------------------------------------------------------------
F25F320406C504B1E043441318AC5E0A
DEMO_QUEUE_PAYLOAD_TYPE('message 1')
F25F320406C604B1E043441318AC5E0A
DEMO_QUEUE_PAYLOAD_TYPE('message 2')
F25F320406C704B1E043441318AC5E0A
DEMO_QUEUE_PAYLOAD_TYPE('message 3')
MSG_ID
--------------------------------
USER_DATA(MESSAGE)
--------------------------------------------------------------------------------
F25F320406C804B1E043441318AC5E0A
DEMO_QUEUE_PAYLOAD_TYPE('message 4')
F25F320406C904B1E043441318AC5E0A
DEMO_QUEUE_PAYLOAD_TYPE('message 5')
SQL> set serveroutput on
SQL> DECLARE
2 r_dequeue_options DBMS_AQ.DEQUEUE_OPTIONS_T;
3 r_message_properties DBMS_AQ.MESSAGE_PROPERTIES_T;
4 v_message_handle RAW(16);
5 o_payload demo_queue_payload_type;
6
7 BEGIN
8
9 DBMS_AQ.DEQUEUE(
10 queue_name => 'demo_queue',
11 dequeue_options => r_dequeue_options,
12 message_properties => r_message_properties,
13 payload => o_payload,
14 msgid => v_message_handle
15 );
16
17 DBMS_OUTPUT.PUT_LINE(
18 '*** Dequeued message is [' || o_payload.message || '] ***'
19 );
20
21 COMMIT;
22
23 END;
24 /
*** Dequeued message is [message 1] ***
SQL> DECLARE
2 r_dequeue_options DBMS_AQ.DEQUEUE_OPTIONS_T;
3 r_message_properties DBMS_AQ.MESSAGE_PROPERTIES_T;
4 v_message_handle RAW(16);
5 o_payload demo_queue_payload_type;
6
7 BEGIN
8
9 for cur in (select * from message_track where msg = 'message 5') loop
10 r_dequeue_options.msgid := cur.hndl;
11 end loop;
12
13
14 DBMS_AQ.DEQUEUE(
15 queue_name => 'demo_queue',
16 dequeue_options => r_dequeue_options,
17 message_properties => r_message_properties,
18 payload => o_payload,
19 msgid => v_message_handle
20 );
21
22 DBMS_OUTPUT.PUT_LINE(
23 '*** Dequeued message is [' || o_payload.message || '] ***'
24 );
25
26 COMMIT;
27
28 END;
29 /
*** Dequeued message is [message 5] ***