Previous |
Next |
Configure a mechanism to enqueue the messages in your messaging system. Typically, an application creates and enqueues messages that will be dequeued and processed by another application. For simplicity, this example creates a trigger called enqueue_orders
to enqueue a message that includes the order ID and order date of an order. The trigger fires when an order is inserted into the oe.orders
table.
To configure a message enqueuing mechanism:
Grant the EXECUTE
privilege on the DBMS_STREAMS_MESSAGING
package to the Oracle Streams administrator.
This example configures a trigger that runs the ENQUEUE
procedure in the DBMS_STREAMS_MESSAGING
package. The user who runs this procedure in a trigger must have explicit EXECUTE
privilege on the package that contains the procedure. The privilege cannot be granted through a role. Therefore, the Oracle Streams administrator must be granted explicit EXECUTE
privilege on the package.
Log in to Enterprise Manager as an administrative user who can grant privileges to the strmadmin
user. For example, you can log in as a user with SYSDBA
privilege. In this example, log in to the ii1.example.com
database.
Go to the Database Home page.
Click Server to open the Server subpage.
Click Users in the Security section.
The Users page appears.
Select the STRMADMIN
user.
Click Edit.
The Edit User page appears, showing the General subpage.
Click Object Privileges to open the Object Privileges subpage.
Select Package in the Select Object Type list.
Click Add to open the Add Package Object Privileges page.
Enter SYS.DBMS_STREAMS_MESSAGING
in the Select Package Objects field.
Move EXECUTE from the Available Privileges list to the Selected Privileges list.
Click OK to add the privilege.
Click Apply to grant the privilege.
Log out of Enterprise Manager.
Note: You can also use the GRANT
SQL statement to grant privileges to a user.
Create a trigger in the ii1.example.com
database to enqueue a message automatically when a change is made to the oe.orders
table.
Log in to ii1.example.com
database in Enterprise Manager as the Oracle Streams administrator.
Go to the Database Home page.
Click Schema to open the Schema subpage.
Click Triggers in the Programs section.
On the Triggers page, click Create.
The Create Trigger page appears, showing the General subpage.
Enter enqueue_orders
in the Name field.
Ensure that strmadmin
is entered in the Schema field.
Enter the following in the Trigger Body field:
DECLARE message strmadmin.order_id_date; BEGIN message := strmadmin.order_id_date( order_id => :NEW.order_id, order_date => TO_CHAR(:NEW.order_date)); DBMS_STREAMS_MESSAGING.ENQUEUE ( queue_name => 'strmadmin.streams_queue', payload => ANYDATA.CONVERTOBJECT(message)); END;
Click Event to open the Event subpage.
Ensure that Table is selected in the Trigger On list.
Enter oe.orders
in the Table (Schema.Table) field.
Select After for Fire Trigger.
Select Insert for Event. In this example, only Insert should be selected because the messages track new orders, not changes to existing orders.
Click Advanced.
Select Trigger for each row.
Enter OLD
in the Old as field in the Referencing section.
Enter NEW
in the New as field in the Referencing section.
Click OK to create the trigger.
Note: You can also use the CREATE
TRIGGER
SQL statement to create a trigger.
Complete the steps in "Task 4: Configuring a Messaging Client to Dequeue Messages" to continue this extended example.