Advanced Queuing   «Prev  Next»

Lesson 2What is Advanced Queuing?
Objective Define Advanced Queuing and the entities involved

What is Advanced Queuing in Oracle?

A number of terms relate to Advanced Queuing that you will have to understand to use its functionality:
  1. Message: A message is the basic unit of information that is transmitted. You define the information in a message as an object type.
  2. Queue: A queue is a repository for messages. You can define any number of individual queues. Messages can be enqueued, or placed, into a queue, and dequeued, or removed, from a queue.
  3. Queue table: Queues are stored in queue tables, which are database tables that can contain one or more queues. You can use standard SQL statements to query information in a queue table.
  4. Agent: An agent is a queue user. Agents interact with queues. There are two types of agents: a producer, who creates messages for a queue, and a consumer, who takes messages from queues.
  5. Recipient and subscription lists: A message can be directed toward more than one recipient, or to a list of subscribers associated with a queue. A queue can have a subscriber list, but you can still direct a message to a particular recipient or recipients explicitly.
  6. Rule: A rule is a Boolean expression that acts as a filter for subscribers to a queue. For instance, a message could be directed to different subscribers based on priority or some quality of its message payload.
  7. Rule-based subscriber: A rule-based subscriber is a subscriber to a queue who gets messages only based on the evaluation of a rule.
  8. Queue monitor: The queue monitor is a background process that performs administrative tasks for queues, such as collecting statistics on a queue or limiting the window of time when a message can be retrieved. The queue monitor is optional.

Oracle 12c Performance Tuning

Advanced Queuing in Action

The concept behind Advanced Queuing (also known as AQ) is fairly simple. In a normal interaction with an Oracle8i database, the communication between a user and the database server is synchronous[1] when a user sends a message to the Oracle server and waits for a response from the server.
Advanced Queuing uses the capabilities of the Oracle server to implement asynchronous communication. A user sends a message to a queue, where it waits until another user or process takes the message out of the queue. The sender is not blocked while waiting for a response from the server, as it is with synchronous communication.
The process of communication between the sender and recipient of a message is still guaranteed. The main difference in implementation is that the delivery time is not guaranteed, because it is dependent on when a recipient retrieves a message as well as when the message is sent.
The following SlideShow illustrates Advanced Queuing at work:

Environment Setup

Administration and access privileges for advanced queuing are controled using two roles:
  1. AQ_ADMINISTRATOR_ROLE - Allows creation and administration of queuing infrastructure.
  2. AQ_USER_ROLE - Allows access to queues for enqueue and dequeue operations.
In the following examples I have used two schemas, one owning the queuing infrastructure and another with access to it.

CONNECT / AS SYSDBA
CREATE USER aq_admin IDENTIFIED BY aq_admin DEFAULT TABLESPACE users;
GRANT connect TO aq_admin;
GRANT create type TO aq_admin;
GRANT aq_administrator_role TO aq_admin;
ALTER USER aq_admin QUOTA UNLIMITED ON users;

CREATE USER aq_user IDENTIFIED BY aq_user DEFAULT TABLESPACE users;
GRANT connect TO aq_user;
GRANT aq_user_role TO aq_user;

How Queues are set up

1) Queues are set up in an Oracle database
1) Queues are set up in an Oracle Database

2) A producer creates a message and sends it to a particular queue
2) A producer creates a message and sends it to a particular queue

3) The queue holds the message until ...
3) The queue holds the message until ...

4) A consumer retrieves the message, at which point it leaves the queue
4) A consumer retrieves the message, at which point it leaves the queue

For more about when to use Advanced Queuing, click the link below.
When To use Advanced Queuing
In the next lesson, you will learn about the data dictionary views used for Advanced Queuing.

[1] Asynchronous: A process where a command is submitted and the submitter does not wait for a response from the recipient of the command.