|Lesson 6||Developing P/SQL Applications for Enqueuing |
|Objective ||Set up enqueuing to the Advanced Queue |
Developing PL/SQL Applications for Enqueuing
Now that you have a queue set up, you can create PL/SQL code to enqueue a message to the queue.
Enqueuing a message
To enqueue a message, you will have to use the following PL/SQL code in a procedure. This procedure will be in a PL/SQL package called
The procedure itself will be called
AQ_ENQ, and it will take an incoming parameter of data type
This incoming parameter will pass the message text to the message payload.
The body of the PL/SQL package includes the following code:
- You need to declare four variables necessary to enqueue a message:
Enqueue_options: Allows you to set various options for enqueuing the message. You use the data type
enqueue_options_t, which is defined in the
Message_properties: Allows you to set various options for the message itself. You use the data type
message_properties_t, which is defined in the
Message_handle: Will accept a value assigned by the Advanced Queuing process.
Message: The message payload you created when you created the queue.
- The next step is to start the procedural code by assigning the value of the
parameter to the message payload:
Message := Message_typ("This is a sample message);
- The final step in enqueuing a message is to call the
ENQUEUE procedure from the
DBMS_AQ package and end the procedural code:
DBMS_AQ.ENQUEUE(queue_name => 'queue1',
enqueue_options => enqueue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
You use each of the variables you declared at the start of the procedure. Because you will not be changing any of the options for enqueuing the message or for the message itself, you do not have to set any values for the
The enqueuing process described above is illustrated in the following Slide Show: