Lesson 3 | Queue propagation |
Objective | Work with Queue Propagation. |
tnsnames.ora
file on the local (enqueueing) database:
REMOTEDB = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = remote-host)(PORT = 1521)) (CONNECT_DATA = (SERVICE_NAME = remotedb_service) ) )
CREATE DATABASE LINK remotedb_link CONNECT TO remote_user IDENTIFIED BY password USING 'REMOTEDB';
remote_user
must have appropriate privileges on the remote queue.BEGIN DBMS_AQADM.CREATE_QUEUE_TABLE( queue_table => 'remote_qtab', queue_payload_type => 'SYS.AQ$_JMS_TEXT_MESSAGE', multiple_consumers => FALSE ); DBMS_AQADM.CREATE_QUEUE( queue_name => 'remote_queue', queue_table => 'remote_qtab' ); DBMS_AQADM.START_QUEUE(queue_name => 'remote_queue'); END; /
BEGIN DBMS_AQADM.GRANT_QUEUE_PRIVILEGE( privilege => 'ENQUEUE', queue_name => 'remote_queue', grantee => 'remote_user', grant_option => FALSE ); END; /
EXECUTE
on message types (like SYS.AQ$_JMS_TEXT_MESSAGE
) and SELECT
on the queue table, if applicable.
DECLARE enqueue_options DBMS_AQ.ENQUEUE_OPTIONS_T; message_properties DBMS_AQ.MESSAGE_PROPERTIES_T; message_handle RAW(16); message SYS.AQ$_JMS_TEXT_MESSAGE; BEGIN message := SYS.AQ$_JMS_TEXT_MESSAGE.construct; message.set_text('Hello from Oracle 23c!'); DBMS_AQ.ENQUEUE@remotedb_link ( queue_name => 'remote_queue', enqueue_options => enqueue_options, message_properties => message_properties, payload => message, msgid => message_handle ); END; /
SELECT msgid, user_data FROM remote_qtab;
tnsping
or sqlplus
).BEGIN DBMS_AQADM.CREATE_QUEUE_TABLE( queue_table => 'remote_qtab', queue_payload_type => 'SYS.AQ$_JMS_TEXT_MESSAGE', multiple_consumers => FALSE ); DBMS_AQADM.CREATE_QUEUE( queue_name => 'remote_queue', queue_table => 'remote_qtab' ); DBMS_AQADM.START_QUEUE( queue_name => 'remote_queue' ); END; /
BEGIN DBMS_AQADM.GRANT_QUEUE_PRIVILEGE( privilege => 'ENQUEUE', queue_name => 'remote_queue', grantee => 'REMOTE_USER', grant_option => FALSE ); END; / GRANT EXECUTE ON SYS.AQ$_JMS_TEXT_MESSAGE TO REMOTE_USER;Replace `REMOTE_USER` with the user account used in the DB link. --- ๐น [LOCAL] Step 3 โ Create Database Link to Remote
CREATE DATABASE LINK remotedb_link CONNECT TO REMOTE_USER IDENTIFIED BY remote_password USING 'REMOTEDB'; -- entry in tnsnames.ora
DECLARE enqueue_options DBMS_AQ.ENQUEUE_OPTIONS_T; message_properties DBMS_AQ.MESSAGE_PROPERTIES_T; message_handle RAW(16); message SYS.AQ$_JMS_TEXT_MESSAGE; BEGIN message := SYS.AQ$_JMS_TEXT_MESSAGE.construct; message.set_text('Hello from Oracle 23c automated script!'); DBMS_AQ.ENQUEUE@remotedb_link ( queue_name => 'remote_queue', enqueue_options => enqueue_options, message_properties => message_properties, payload => message, msgid => message_handle ); END; /
SELECT msgid, user_data FROM remote_qtab;
SYS.AQ$_JMS_TEXT_MESSAGE
is a predefined Oracle AQ message type.REMOTEDB
TNS entry exists and is reachable (tnsping REMOTEDB
).REMOTE_USER
must be a valid user with required permissions.The following series of images describes how this works.
DBMS_AQADM.GRANT_SYSTEM_PRIVILEGE
package. SYS
and SYSTEM
are initially given the
AQ ADMINISTRATOR
role and can grant that role to other users. The AQ_USER_ROLE
is only for 8.0 compatible queues. This role is ignored by 8.1 compatible queues. The next lesson discusses connection pooling.
JOB_QUEUE_PROCESSES
to at least 2.EXECUTE
on DBMS_AQADM
to a user.ENQUEUE ANY QUEUE
and DEQUEUE ANY QUEUE
to other users.