learn-oracle
free Oracle DBA tutorial Oracle Jobs
Ask A Question
SQL Statement Tuning
Backup and Recovery Concepts
Oracle 11g New Features
Oracle E Suite & Others
Oracle Data Guard
Oracle DBA FAQ





Elements of Advanced Queuing


Previous Chapter | Next Chapter

By integrating transaction processing with queuing technology, persistent messaging in the form of Advanced Queuing is possible. This section defines a number of Advanced Queuing terms.

Message
A message is the smallest unit of information inserted into and retrieved from a queue. A message consists of the following:

* Control information (metadata)

* Payload (data)

The control information represents message properties used by AQ to manage messages. The payload data is the information stored in the queue and is transparent to Oracle AQ. A message can reside in only one queue. A message is created by the enqueue call and consumed by the dequeue call.

Queue
A queue is a repository for messages. There are two types of queues: user queues, also known as normal queues, and exception queues. The user queue is for normal message processing. Messages are transferred to an exception queue if they cannot be retrieved and processed for some reason. Queues can be created, altered, started, stopped, and dropped by using the Oracle AQ administrative interfaces

User queues can be persistent (the default) or nonpersistent queues. Persistent queues store messages in database tables. These queues provide all the reliability and availability features of database tables. Nonpersistent queues store messages in memory. They are generally used to provide an asynchronous mechanism to send notifications to all users that are currently connected.

Queue Table
Queues are stored in queue tables. Each queue table is a database table and contains one or more queues. Each queue table contains a default exception queue. Figure 7-1, "Basic Queues" shows the relationship between messages, queues, and queue tables.

Agent
An agent is a queue user. This can be an end user or an application. There are two types of agents:

* Producers who place messages in a queue (enqueuing)

* Consumers who retrieve messages (dequeuing)

Any number of producers and consumers may be accessing the queue at a given time. Agents insert messages into a queue and retrieve messages from the queue by using the Oracle AQ operational interfaces

An agent is identified by its name, address and protocol

* The name of the agent may be the name of the application or a name assigned by the application. A queue may itself be an agent--enqueuing or dequeuing from another queue.

* The address field is a character field of up to 1024 bytes that is interpreted in the context of the protocol. For instance, the default value for the protocol is 0, signifying a database link addressing. In this case, the address for this protocol is of the form queue_name@dblink

where queue_name is of the form [schema.]queue and dblink may either be a fully qualified database link name or the database link name without the domain name.

Recipient
The recipient of a message may be specified by its name only, in which case the recipient must dequeue the message from the queue in which the message was enqueued. The recipient may be specified by name and an address with a protocol value of 0. The address should be the name of another queue in the same database or another Oracle database (identified by the database link) in which case the message is propagated to the specified queue and can be dequeued by a consumer with the specified name. If the recipient's name is NULL, the message is propagated to the specified queue in the address and can be dequeued by the subscribers of the queue specified in the address. If the protocol field is nonzero, the name and address are not interpreted by the system and the message can be dequeued by a special consumer

Recipient and Subscription Lists
Multiple consumers can consume a single message:

o The enqueuer can explicitly specify the consumers who may retrieve the message as recipients of the message. A recipient is an agent identified by a name, address, and protocol.

o A queue administrator can specify a default list of recipients who can retrieve messages from a queue. The recipients specified in the default list are known as subscribers. If a message is enqueued without specifying the recipients, the message is sent to all the subscribers.

Different queues can have different subscribers, and the same recipient can be a subscriber to more than one queue. Further, specific messages in a queue can be directed toward specific recipients who may or may not be subscribers to the queue, thereby overriding the subscriber list.

Rule
A rule is used to define one or more subscribers' interest in subscribing to messages that conform to that rule. The messages that meet the rule criterion are delivered to the interested subscribers. A rule is specified as a boolean expression (one that evaluates to true or false) using syntax similar to the WHERE clause of a SQL query. The boolean expression can include conditions on the following:

* Message properties (currently priority and correlation identifier)

* User data properties (object payloads only)

* Functions (as specified in the WHERE clause of a SQL query)

Rule-Based Subscribers
A rule-based subscriber is a subscriber with associated rules in the default recipient list. If an associated rule evaluates to TRUE for a message, the message is sent to the rule-based subscriber even if the message has no specified recipients.

Transformation
A transformation defines a mapping from one Oracle data type to another. The transformation is represented by a SQL function that takes the source data type as input and returns an object of the target data type. A transformation can be specified during enqueue, to transform the message to the correct type before inserting it into the queue. It can be specified during dequeue to receive the message in the desired format. If specified with a remote subscriber, the message will be transformed before propagating it to the destination queue.

Queue Monitor
The queue monitor (QMNn) is a background process that monitors messages in queues. It provides the mechanism for message delay, expiration, and retry delay. The QMNn also performs garbage collection for the queue table and its indexes and index-organized tables (IOTs). For example, the QMNn determines when all subscribers of multiconsumer queues have received a message and subsequently removes the message from the queue table and supporting indexes and IOTs.

You can start a maximum of 10 multiple queue monitors at the same time. You start the queue monitors by setting the dynamic init.ora parameter aq_tm_processes. The queue monitor wakes up every minute, or whenever there is work to do, for instance, if a message is marked expired or ready to be processed.

Java Messaging Service Terminology

When using the oracle.jms Java package, keep in mind the following:

* The JMS equivalent of enqueue is Send.

* The destination of messages is a Queue, without any qualification.

* The container of messages is a Topic, with the idea being that each application can Publish on or Subscribe to a given topic.

* Topic in JMS maps to a Multi-Consumer Queue in the other AQ interfaces.

* The Java package oracle.jms extends the public JMS standard to allow for defined recipient lists.

Demos

The following demos can be found in the $ORACLE_HOME/demo directory:

Demo and Locations Topic
aqjmsdemo01.java Enqueue text messages and dequeue based on message properties
aqjmsdemo02.java Message Listener demo
aqjmsdemo03.java Message Listener demo
aqjmsdemo04.java Oracle Type Payload - Dequeue on payload content
aqjmsdemo05.java Example of the queue browser
aqjmsdemo06.java Schedule propagation between queues in the database
aqjmsdmo.sql Set up AQ JMS demos
aqjmsREADME.txt Describe the AQ Java API and JMS demos
aqorademo01.java Enqueue and dequeue RAW messages
aqorademo02.java Enqueue and dequeue object type messages using the Custom Datum interface
aqoradmo.sql Setup file for AQ java API demos
newaqdemo00.sql Create users, message types, tables, etc.
newaqdemo01.sql Set up queue_tables, queues, subscribers and set up
newaqdemo02.sql Enqueue messages
newaqdemo03.sql Install dequeue procedures
newaqdemo04.sql Perform blocking dequeue
newaqdemo05.sql Perform listen for multiple agents
newaqdemo06.sql Clean up users, queue_tables, queues, subscribers (cleanup script)
ociaqdemo00.c Enqueue messages
ociaqdemo01.c Perform blocking dequeue
ociaqdemo02.c Perform listen for multiple agents


Previous Chapter | Next Chapter

More Articles

1. What Is Advanced Queuing?
2. General Features of Advanced Queuing
3. Enqueue, Dequeue, Propagation Features of Advanced Queuing

More Tutorials on Oracle dba ...

Source :Oracle Documentation

Liked it ? Want to share it ? Social Bookmarking

Add to: Mr. Wong Add to: BoniTrust Add to: Newsider Add to: Digg Add to: Del.icio.us Add to: Reddit Add to: Jumptags Add to: StumbleUpon Add to: Slashdot Add to: Netscape Add to: Furl Add to: Yahoo Add to: Spurl Add to: Google Add to: Blinklist Add to: Technorati Add to: Newsvine Information




Want to share or request Oracle Tutorial articles to become a Oracle DBA. Direct your requests to webmaster@oracleonline.info