Now that you have a queue set up, you can create PL/SQL code to enqueue a message to the queue.
Enqueuing Message in Oracle
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 PETSTORE.AQ_EX. The procedure itself will be called AQ_ENQ, and it will take an incoming parameter of data type VARCHAR2(100) called MSG_TEXT.
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 DBMS_AQ package.
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 DBMS_AQ package.
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 MSG_TEXT
parameter to the message payload:
BEGIN
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:
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 enqueue_options or message_properties variables.
The enqueuing process described above is illustrated in the following Slide Show: