Tuesday, July 28, 2009

AQ, Agent and Subscription Creation Script

------------------------------------------------------------------------
-- 1. Check whether the Qtable exist, if not then create
-------------------------------------------------------------------------
l_qtable_name:='QTABLENAME';
l_q_name:='QUEUENAME';

SELECT COUNT(*)
INTO v_q_table_count
FROM user_tables
WHERE table_name = l_qtable_name;

DBMS_AQADM.CREATE_QUEUE_TABLE (queue_table => l_qtable_name, multiple_consumers=> TRUE, queue_payload_type => 'SYS.AQ$_JMS_TEXT_MESSAGE');
DBMS_AQADM.CREATE_QUEUE (queue_name => l_q_name, queue_table =>l_qtable_name,retention_time=> 86400);
DBMS_AQADM.START_QUEUE (queue_name => l_q_name);

v_q_subscriber := sys.aq$_agent('USERNAME', NULL, NULL);
dbms_aqadm.add_subscriber(queue_name => l_q_name, subscriber => v_q_subscriber);
DBMS_OUTPUT.PUT_LINE('Subscribed to USER = USERNAME' );

No comments: