|Lesson 9||Running 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.
Before you can use the features of Advanced Queuing, you have to set up a queue to use, involving four steps:
- Create an object type that will act as the message payload of the message.
- Create a queue table that will hold the queue.
- Create the queue itself and assign it to the message table.
- 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.
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,
with the appropriate parameters and payload. You use the
procedure, which is a simple wrapper
procedure with default values for the parameters.
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.
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.
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.
- The first SQL statement is used to ensure that the queues exist, that the startup script you used created the queue table and
- 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
SELECT QUEUE, MSG_ID,
TO_CHAR(enq_time, 'MON DD HH:MI:SS')
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
Code that wraps a type of logic with some other code to make a cleaner interface.