Advanced Queuing   «Prev  Next»

Lesson 9Running the Application
Objective Run the application you have created with Advanced Queuing

Run Advanced Queuing in Oracle

You have now walked through all the code you need for a simple application that uses Advanced Queuing. There are four parts to this application.

Initialization

Before you can use the features of Advanced Queuing, you have to set up a queue to use, involving four steps:
  1. Create an object type that will act as the message payload of the message.
  2. Create a queue table that will hold the queue.
  3. Create the queue itself and assign it to the message table.
  4. Start the queue.
The first three actions need to be executed only once the object type, queue table, and queue are persistent objects in the Oracle8i database. You have restart the queue every time you restart your Oracle8i database.
For the purposes of this application, you also created a second queue to demonstrate propagation.

Enqueuing

Once the queue is operational, a user can send a message to the queue. Enqueuing a message essentially consists of calling a single PL/SQL procedure, DBMS_AQ.ENQUEUE(), with the appropriate parameters and payload. You use the ENQUEUE() procedure, which is a simple wrapper[1] for the DBMS_AQ.ENQUEUE() procedure with default values for the parameters.

Dequeuing

You also use a single PL/SQL procedure to dequeue a message from the queue. You have a variety of options you can set on the dequeuing operation, such as which message to get and how to treat the message once it is retrieved. You use the DEQUEUE() procedure, which is a simple wrapper for the DBMS_AQ.DEQUEUE() procedure with default values for the parameters.

Propagation

Although you might want eventually to propagate your messages to other queues, for the purposes of this application, you will not use the propagation feature of Advanced Queuing.

Shutdown

The final step in using your application is to run a script file to close the queue, drop the queue, and drop the queue table. Normally, you would not use this script, because you want your queues to remain active, but the script is provided so you can return your environment to its original state.

Checking your results

To see the results of your queuing actions, you will have to use some SQL statements to check the contents of a queue.
There are two SQL statements you will use to check the status of the queues you create.
  1. The first SQL statement is used to ensure that the queues exist, that the startup script you used created the queue table and
  2. the queues and started the queues:

SELECT * FROM USER_QUEUES;

You will also use this same SQL statement to check to make sure that the cleanup script, which stops and drops the queues and then drops the queue tables, works correctly. The second SQL statement is used to check a view to show the messages in the queue table named QUEUE1.
SELECT QUEUE, MSG_ID, 
TO_CHAR(enq_time, 'MON DD HH:MI:SS') 
FROM AQ$QUEUE1

You must use the TO_CHAR function to show the hours, minutes, and seconds for the time a message was enqueued–the default display of the date shows only the month, date, and year. The next lesson is the module conclusion.

Queuing and Dequeuing Messages

Click the two links below to read about queuing and dequeuing messages.
Running Application advanced Queuing
Using Advanced Queuing

[1]Wrapper: Code that wraps a type of logic with some other code to make a cleaner interface.