Lesson 5 | Developing an Advanced Queuing Application Setup |
Objective | Use PL/SQL to create an Advanced Queuing Application |
Develop Oracle Queuing Application
The best way to understand how to use Advanced Queuing is to create a sample application that uses the feature. The next several lessons will walk you through the creation of a simple application that will be able to post a message to a queue,
retrieve the message from the queue, and propagate a message to other queues.
The PL/SQL code shown in the lessons will focus on the procedural logic necessary to implement your queues and not display some of the surrounding syntax necessary to create PL/SQL packages and procedures.
The complete code is available for download as part of the exercise following Lesson 9 in this module.
This application will not use some of the more specific
features of Advanced Queuing.
Application Scenario
You will be building a mini-application to handle order processing for your pet store by using Advanced Queuing. When an order is placed, a message will be sent to a queue. That message will be read by the Billing Department and later propagated to an Oracle8i database at your supplier. With Advanced Queuing, you can effectively write an agent to read the messages and implement the actions necessary to process the order. The messages could come from your pet store, from another pet store, or from a remote sales rep.
Setting up the Queue
Before you can use a queue, you must set it up properly. You will initially need only a single queue for this sample application. To create the queue in the
PETSTORE
schema, use the four following PL/SQL calls:
- Use this syntax:
CREATE type PETSTORE.Message_typ as object (
order_msg VARCHAR2(100));
This PL/SQL call creates a message type that will be the "payload," or content, of the message.
For the purposes of this application, the message will contain only brief text, which is shown below, but it could contain more structured and detailed information.
- Use this syntax:
EXECUTE DBMS_AQADM.CREATE_QUEUE_TABLE (
queue_table => 'PETSTORE.queue1',
queue_payload_type=> ''PETSTORE.Message_typ');
This PL/SQL call creates a queue table, which will store messages with a payload of the type created in the previous line of code. Although multiple queues can share a queue table, all the queues in a table must have the same message payload.
- Once you have created the queue table, you can create a queue that uses the table. This procedure creates an actual queue, which is stored in the previously created queue table:
EXECUTE DBMS_AQADM.CREATE_QUEUE (
queue_name => 'queue1',
queue_table => ''PETSTORE.queue1');
- The final step in initializing the queue is to start the queue with this PL/SQL command:
EXECUTE DBMS_AQADM.START_QUEUE (
queue_name => 'queue1');
Your queue is now ready to accept messages.
Setting Up Advanced Queue
In the next lesson, you will learn how to enqueue a message.