SlideShare a Scribd company logo
1 of 94
Download to read offline
Oracle Advanced Queuing(AQ)
Presenters:
Gurpreet Singh
OVERVIEW
2 Oracle Advanced Queuing
• What Is Advanced Queuing?
• General Features of Advanced Queuing
• Enqueue Features
• Dequeue Features
• Propagation Features
• Elements of Advanced Queuing
• Using PL/SQL to Access AQ
• DBMS_AQ
• Data Structures for DBMS_AQ
• Summary of DBMS_AQ Subprograms
• DBMS_AQADM
• Summary of DBMS_AQADM Subprograms
• Setting up data structure
• Creating a Queue Table and Queue of Object Type
• Creating a Queue Table and Queue of Raw Type
• Creating a Prioritized Message Queue Table and Queue
• Creating a Multiconsumer Queue Table and Queue
• Creating a Queue to Demonstrate Propagation
• Enqueuing of Object Type Messages Using PL/SQL
OVERVIEW
3 Oracle Advanced Queuing
• DEqueuing of Object Type Messages Using PL/SQL
• Enqueuing of RAW Type Messages Using PL/SQL
• DEqueuing of RAW Type Messages Using PL/SQL
• Enqueuing of Messages by Priority Using PL/SQL
• DEqueuing of Messages by Priority Using PL/SQL
• Enqueuing of Messages with Time Delay and Expiration Using PL/SQL
• Enqueuing and Dequeuing of Messages to/from a Multiconsumer Queue Using PL/SQL
• Managing Propagation From One Queue To Other Queues In The Same Database Using PL/SQL
• Manage Propagation From One Queue To Other Queues In Another Database Using PL/SQL
• Unscheduling Propagation Using PL/SQL
• Dropping AQ Objects
• Revoking Roles and Privileges
MESSAGING & QUEUING
4 Oracle Advanced Queuing
 An essential part of Distributed Application Development (DAD)
 A key piece of a middle-ware known as Message-Oriented
Middleware (MOM)
Motto: Every DAD needs a MOM
WHAT DOES MOM PROVIDE?
5 Oracle Advanced Queuing
 Time-independent responses in a client/server environment
 Help in passing information between servers and clients
 A facility that allows general-purpose messages to be
exchanged in a client/server system using message queues
WHAT IS ADVANCED QUEUING?
6 Oracle Advanced Queuing
 Oracle Advance Queuing is Oracle’s message queuing facility
 Available as of Oracle 8.0.3
 First database-integrated messaging system in the industry
WHAT IS ADVANCED QUEUING?
7 Oracle Advanced Queuing
When Web-based business applications communicate with each other, producer
applications ENQUEUE messages and consumer applications DEQUEUE messages.
Advanced Queuing provides database-integrated message queuing functionality.
Advanced Queuing leverages the functions of the Oracle database so that messages
can be stored persistently, propagated between queues on different machines and
databases, and transmitted using Oracle Net Services, HTTP(S), and SMTP.
WHAT IS ADVANCED QUEUING?
8 Oracle Advanced Queuing
WHAT IS ADVANCED QUEUING?
9 Oracle Advanced Queuing
Advanced Queuing provides the message management functionality and
asynchronous communication needed for application integration. In an integrated
environment, messages travel between the Oracle database server and the
applications and users, as shown in Figure. Using Oracle Net Services, messages are
exchanged between a client and the Oracle database server or between two Oracle
databases. Oracle Net Services also propagates messages from one Oracle queue to
another.
WHAT IS ADVANCED QUEUING?
10 Oracle Advanced Queuing
You can access Advanced Queuing functionality through the following interfaces:
 PL/SQL using DBMS_AQ, DBMS_AQADM, and DBMS_AQELM.
 Visual Basic using Oracle Objects for OLE.
 Java using the oracle.AQ Java package.
 Java Message Service (JMS) using the oracle.jms Java package.
 Internet access using HTTP, HTTPS, and SMTP
Advanced Queuing exhibits high performance characteristics as measured by the
following metrics:
 Number of messages enqueued/dequeued per second
 Time to evaluate a complex query on a message warehouse
 Time to recover/restart the messaging process after a failure
Queuing systems must be scalable. Advanced Queuing exhibits high performance as
the number of programs using the application increases, as the number of messages
increases, and as the size of the message warehouse increases.
GENERAL FEATURES OF ADVANCED QUEUING
11 Oracle Advanced Queuing
 Nonrepudiation and the AQ$<QueueTableName> View
 Point-to-Point and Publish-Subscribe Messaging
 Oracle Internet Directory
 Oracle Enterprise Manager Integration
 Message Format Transformation
 SQL Access
 Support for Statistics Views
 Structured Payloads
 Retention and Message History
 Tracking and Event Journals
 Queue-Level Access Control
 Nonpersistent Queues
 Support for Oracle9i Real Application Clusters
 XMLType Payloads
NONREPUDIATION AND THE AQ$<QUEUETABLENAME>
VIEW
12 Oracle Advanced Queuing
Advanced Queuing maintains the entire history of information about a message along with the message
itself. You can look up history information by using the AQ$<QueueTableName> view. This information
serves as the proof of sending and receiving of messages and can be used for nonrepudiation of the
sender and nonrepudiation of the receiver.
The following information is kept at enqueue for nonrepudiation of the enqueuer:
 AQ agent doing the enqueue
 Enqueue time
 Transaction ID of the transaction doing the enqueue
The following information is kept at dequeue for nonrepudiation of the dequeuer:
 AQ agent doing dequeue
 Dequeue time
 Transaction ID of the transaction doing dequeue
After propagation, the Original_Msgid field in the destination queue of propagation corresponds to the
message ID of the source message. This field can be used to correlate the propagated messages. This is
useful for nonrepudiation of the dequeuer of propagated messages.
Stronger nonrepudiation can be achieved by enqueuing the digital signature of the sender at the time of
enqueue with the message and by storing the digital signature of the dequeuer at the time of dequeue.
POINT-TO-POINT AND PUBLISH-SUBSCRIBE
MESSAGING
13 Oracle Advanced Queuing
A combination of features allows publish-subscribe messaging between applications. These features
include rule-based subscribers, message propagation, the listen feature, and notification capabilities.
Advanced Queuing sends and receives messages in the following ways:
 Point-to-Point
 Publish-Subscribe
Point-to-Point
A point-to-point message is aimed at a specific target. Senders and receivers decide on a common queue
in which to exchange messages. Each message is consumed by only one receiver. Each application has its
own message queue, known as a single-consumer queue.
Publish-Subscribe
A publish-subscribe message can be consumed by multiple receivers. Publish-subscribe messaging has a
wide dissemination mode--broadcast--and a more narrowly aimed mode--multicast, also called point-to-
multipoint.
Broadcasting is the equivalent of a radio station not knowing exactly who the audience is for a given
program. The dequeuers are subscribers to multiconsumer queues In contrast, multicast is the same as a
magazine publisher who knows who the subscribers are. Multicast is also referred to as point-to-
multipoint because a single publisher sends messages to multiple receivers, called recipients, who may or
may not be subscribers to the queues that serve as exchange mechanisms.
ORACLE INTERNET DIRECTORY
14 Oracle Advanced Queuing
Oracle Internet Directory is a native LDAPv3 directory service built on the Oracle database that centralizes
a wide variety of information, including e-mail addresses, telephone numbers, passwords, security
certificates, and configuration data for many types of networked devices. You can look up enterprise-wide
queuing information--queues, subscriptions, and events--from one location, the Oracle Internet Directory.
ORACLE ENTERPRISE MANAGER INTEGRATION
15 Oracle Advanced Queuing
You can use Enterprise Manager to do the following:
 Create and manage queues, queue tables, propagation schedules, and transformations
 Monitor your AQ environment using the AQ topology at the databse and queue levels, and by viewing
queue errors and queue and session statistics.
MESSAGE FORMAT TRANSFORMATION
16 Oracle Advanced Queuing
The message format transformation feature supports applications that use data in different formats. 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 as follows:
• During enqueue, to transform the message to the correct type before inserting it into the queue.
 You can convert a message to the payload type of the queue at enqueue time. Thus, the type of
the message to be enqueued need not match the payload type of the queue.
• During dequeue, to receive the message in the desired format
 A message can be transformed to the desired format before returning it to the dequeuer.
• By a remote subscriber, who can choose to receive a message in a format different from the format of
the source queue
 Before propagating the message to the remote subscriber, the message is transformed
according to the transformation that the remote subscriber specified when subscribing to the
queue.
Following figure shows, queuing, routing, and transformation are essential building blocks to an integrated
application architecture. The figure shows how data from the Out queue of a CRM application is routed
and transformed in the integration hub and then propagated to the In queue of the Web application. The
transformation engine maps the message from the format of the Out queue to the format of the In queue.
SQL ACCESS
17 Oracle Advanced Queuing
Messages are placed in normal rows in a database table, and so can be queried using standard SQL. This
means that you can use SQL to access the message properties, the message history, and the payload. With
SQL access you can also do auditing and tracking. All available SQL technology, such as indexes, can be
used to optimize access to messages.
select * from aq.aq$objmsgs80_qtab
SUPPORT FOR STATISTICS VIEWS
18 Oracle Advanced Queuing
Basic statistics about queues are available using the GV$AQ view.
select * from GV$AQ
STRUCTURED PAYLOADS
19 Oracle Advanced Queuing
You can use object types to structure and manage message payloads. RDBMSs in general have a richer
typing system than messaging systems. Since Oracle is an object-relational DBMS, it supports both
traditional relational types as well as user-defined types. Many powerful features are enabled as a result
of having strongly typed content, such as content whose format is defined by an external type system.
These include:
 Content-based routing: Advanced Queuing can examine the content and automatically route the
message to another queue based on the content.
 Content-based subscription: a publish and subscribe system is built on top of a messaging system so
that you can create subscriptions based on content.
 Querying: the ability to execute queries on the content of the message enables message warehousing.
CREATE type aq.Message_typ as
object (
subject VARCHAR2(30),
text VARCHAR2(80));
RETENTION AND MESSAGE HISTORY
20 Oracle Advanced Queuing
The systems administrator specifies the retention duration to retain messages after consumption.
Advanced Queuing stores information about the history of each message, preserving the queue and
message properties of delay, expiration, and retention for messages destined for local or remote receivers.
The information contains the enqueue and dequeue times and the identification of the transaction that
executed each request. This allows users to keep a history of relevant messages. The history can be used
for tracking, data warehouse, and data mining operations, as well as specific auditing functions.
select * from dba_queues where qid=14140
TRACKING AND EVENT JOURNALS
21 Oracle Advanced Queuing
If messages are retained, they can be related to each other. For example, if a message m2 is produced as a
result of the consumption of message m1, m1 is related to m2. This allows users to track sequences of
related messages. These sequences represent event journals, which are often constructed by applications.
Advanced Queuing is designed to let applications create event journals automatically.
When an online order is placed, multiple messages are generated by the various applications involved in
processing the order. Advanced Queuing offers features to track interrelated messages independent of the
applications that generated them. You can determine who enqueued and dequeued messages, who the
users are, and who did what operations.
With Advanced Queuing tracking features, you can use SQL SELECT and JOIN statements to get order
information from AQ$QUETABLENAME and the views ENQ_TRAN_ID, DEQ_TRAN_ID, USER_DATA (the
payload), CORR_ID, and MSG_ID. These views contain the following data used for tracking:
 Transaction IDs--from ENQ_TRAN_ID and DEQ_TRAN_ID, captured during enqueuing and dequeuing.
 Correlation IDs--from CORR_ID, part of the message properties
 Message content that can be used for tracking--USER_DATA
QUEUE-LEVEL ACCESS CONTROL
22 Oracle Advanced Queuing
The owner of an queue can grant or revoke queue-level privileges on the queue. Database administrators
can grant or revoke new AQ system-level privileges to any database user. Database administrators can also
make any database user an AQ administrator.
NONPERSISTENT QUEUES
23 Oracle Advanced Queuing
Advanced Queuing can deliver nonpersistent messages asynchronously to subscribers. These messages
can be event-driven and do not persist beyond the failure of the system (or instance). Advanced Queuing
supports persistent and nonpersistent messages with a common API.
A message in a nonpersistent queue is not stored in a database table. You create a nonpersistent queue,
which can be either a single-consumer or multiconsumer type. These queues are created in a system-
created queue table (AQ$_MEM_SC for single-consumer queues and AQ$_MEM_MC for multiconsumer
queues) in the schema specified by the create_np_queue command. Subscribers can be added to the
multiconsumer queues. Nonpersistent queues can be destinations for propagation.
You use the enqueue interface to enqueue messages into a nonpersistent queue in the normal way. You
can enqueue RAW and Object Type (ADT) messages into a nonpersistent queue. You retrieve messages
from a nonpersistent queue through the asynchronous notification mechanism, registering for the
notification (using LNOCISubcriptionRegister or DBMS_AQADM.REGISTER) for the queues you are
interested in.
When a message is enqueued into a queue, it is delivered to clients with active registrations for the queue.
The messages are published to the interested clients without incurring the overhead of storing them in the
database.
XMLTYPE PAYLOADS
24 Oracle Advanced Queuing
You can create queues that use the new opaque type, XMLType. These queues can be used to transmit and
store messages that are XML documents. Using XMLType, you can do the following:
 Store any type of message in a queue
 Store documents internally as CLOBs
 Store more than one type of payload in a queue
 Query XMLType columns using the operators ExistsNode() and SchemaMatch()
 Specify the operators in subscriber rules or dequeue conditions
ENQUEUE FEATURES
25 Oracle Advanced Queuing
 Correlation Identifiers
 Subscription and recipient lists
 Priority and ordering of messages in Enqueuing
 Message grouping
 Propagation
 Sender Identification
 Time specification and scheduling
 Asynchronous notification
CORRELATION IDENTIFIERS
26 Oracle Advanced Queuing
Users can assign an identifier to each message, thus providing a means to retrieve specific messages at a
later time.
SUBSCRIPTION AND RECIPIENT LISTS
27 Oracle Advanced Queuing
A single message can be designed to be consumed by multiple consumers. A queue administrator can
specify the list of subscribers who can retrieve messages from a queue. Different queues can have
different subscribers, and a consumer program 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.
You can design a single message for consumption by multiple consumers in a number of different ways.
The consumers who are allowed to retrieve the message are specified as explicit recipients of the message
by the user or application that enqueues the message. Every explicit recipient is an agent identified by
name, address, and protocol.
A queue administrator may also specify a default list of recipients who can retrieve all the messages from a
specific queue. These implicit recipients become subscribers to the queue by being specified in the default
list. If a message is enqueued without specifying any explicit recipients, the message is delivered to all the
designated subscribers.
A rule-based subscriber is one that has a rule associated with it in the default recipient list. A rule-based
subscriber will be sent a message with no explicit recipients specified only if the associated rule evaluated
to TRUE for the message. 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.
PRIORITY AND ORDERING OF MESSAGES IN
ENQUEUING
28 Oracle Advanced Queuing
It is possible to specify the priority of the enqueued message. An enqueued message can also have its
exact position in the queue specified. This means that users have three options to specify the order in
which messages are consumed:
(a) a sort order specifies which properties are used to order all message in a queue;
(b) a priority can be assigned to each message;
(c) a sequence deviation allows you to position a message in relation to other messages.
Further, if several consumers act on the same queue, a consumer will get the first message that is available
for immediate consumption. A message that is in the process of being consumed by another consumer will
be skipped.
MESSAGE GROUPING
29 Oracle Advanced Queuing
Messages belonging to one queue can be grouped to form a set that can only be consumed by one user at
a time. This requires that the queue be created in a queue table that is enabled for message grouping. All
messages belonging to a group have to be created in the same transaction and all messages created in one
transaction belong to the same group. This feature allows users to segment complex messages into simple
messages; for example, messages directed to a queue containing invoices can be constructed as a group of
messages starting with the header message, followed by messages representing details, followed by the
trailer message.
PROPAGATION
30 Oracle Advanced Queuing
This feature enables applications to communicate with each other without having to be connected to the
same database or the same queue. Messages can be propagated from one Oracle AQ to another,
irrespective of whether the queues are local or remote. Propagation is done using database links and
Oracle Net Services.
SENDER IDENTIFICATION
31 Oracle Advanced Queuing
Applications can mark the messages they send with a custom identification. Oracle also automatically
identifies the queue from which a message was dequeued. This allows applications to track the pathway of
a propagated message or a string messages within the same database.
TIME SPECIFICATION AND SCHEDULING
32 Oracle Advanced Queuing
Delay interval or expiration intervals can be specified for an enqueued message, thereby providing
windows of execution. A message can be marked as available for processing only after a specified time
elapses (a delay time) and has to be consumed before a specified time limit expires.
ASYNCHRONOUS NOTIFICATION
33 Oracle Advanced Queuing
The asynchronous notification feature allows clients to receive notification of a message of interest. The
client can use it to monitor multiple subscriptions. The client does not have to be connected to the
database to receive notifications regarding its subscriptions.
Clients can use the OCI function, LNOCISubcriptionRegister, or the PL/SQL procedure DBMS_AQ.REGISTER
to register interest in messages in a queue.
DEQUEUE FEATURES
34 Oracle Advanced Queuing
 Recipients
 Navigation of Messages in Dequeuing
 Modes of Dequeuing
 Optimization of Waiting for the Arrival of Messages
 Retries with Delays
 Optional Transaction Protection
 Exception Handling
 Listen Capability (Wait on Multiple Queues)
 Dequeue Message Header with No Payload
RECIPIENTS
35 Oracle Advanced Queuing
A message can be retrieved by multiple recipients without the need for multiple copies of the same
message.
Designated recipients can be located locally or at remote sites.
NAVIGATION OF MESSAGES IN DEQUEUING
36 Oracle Advanced Queuing
Users have several options to select a message from a queue. They can select the first message or once
they have selected a message and established a position, they can retrieve the next. The selection is
influenced by the ordering or can be limited by specifying a correlation identifier. Users can also retrieve a
specific message using the message identifier.
MODES OF DEQUEUING
37 Oracle Advanced Queuing
A DEQUEUE request can either browse or remove a message. If a message is browsed, it remains available
for further processing. If a message is removed, it is not available more for DEQUEUE requests. Depending
on the queue properties, a removed message may be retained in the queue table. Specified as
DEQUEUE_OPTIONS_T Attributes
OPTIMIZATION OF WAITING FOR THE ARRIVAL OF
MESSAGES
38 Oracle Advanced Queuing
A DEQUEUE can be issued against an empty queue. To avoid polling for the arrival of a new message, a
user can specify if and for how long the request is allowed to wait for the arrival of a message.
RETRIES WITH DELAYS
39 Oracle Advanced Queuing
A message must be consumed exactly once. If an attempt to dequeue a message fails and the transaction
is rolled back, the message will be made available for reprocessing after some user-specified delay elapses.
Reprocessing will be attempted up to the user-specified limit.
OPTIONAL TRANSACTION PROTECTION
40 Oracle Advanced Queuing
ENQUEUE and DEQUEUE requests are normally part of a transaction that contains the requests, thereby
providing the desired transactional behavior. You can, however, specify that a specific request is a
transaction by itself, making the result of that request immediately visible to other transactions. This
means that messages can be made visible to the external world as soon as the ENQUEUE or DEQUEUE
statement is issued or after the transaction is committed.
EXCEPTION HANDLING
41 Oracle Advanced Queuing
A message may not be consumed within given constraints, such as within the window of execution or
within the limits of the retries. If such a condition arises, the message will be moved to a user-specified
exception queue.
SELECT * FROM SYS.ALL_QUEUES
DEQUEUE MESSAGE HEADER WITH NO PAYLOAD
42 Oracle Advanced Queuing
The dequeue mode REMOVE_NODATA can be used to remove a message from a queue without retrieving
the payload. Use this mode to delete a message with a large payload whose content is irrelevant.
PROPAGATION FEATURES
43 Oracle Advanced Queuing
 Automated Coordination of Enqueuing and Dequeuing
 Propagation of Messages with LOBs
 Propagation Scheduling
 Enhanced Propagation Scheduling Capabilities
 Third-Party Support
AUTOMATED COORDINATION OF ENQUEUING AND
DEQUEUING
44 Oracle Advanced Queuing
Recipients can be local or remote. Because Oracle does not support distributed object types, remote
enqueuing or dequeuing using a standard database link does not work. However, you can use AQ message
propagation to enqueue to a remote queue. For example, you can connect to database X and enqueue the
message in a queue, DROPBOX, located in database X. You can configure AQ so that all messages
enqueued in DROPBOX will be automatically propagated to another queue in database Y, regardless of
whether database Y is local or remote. AQ will automatically check if the type of the remote queue in
database Y is structurally equivalent to the type of the local queue in database X and propagate the
message.
Recipients of propagated messages can be applications or queues. If the recipient is a queue, the actual
recipients are determined by the subscription list associated with the recipient queue. If the queues are
remote, messages are propagated using the specified database link. Only AQ-to-AQ message propagation
is supported.
PROPAGATION OF MESSAGES WITH LOBS
45 Oracle Advanced Queuing
Propagation handles payloads with LOB attributes.
PROPAGATION SCHEDULING
46 Oracle Advanced Queuing
Messages can be scheduled to propagate from a queue to local or remote destinations. Administrators can
specify the start time, the propagation window, and a function to determine the next propagation window
(for periodic schedules).
ENHANCED PROPAGATION SCHEDULING
CAPABILITIES
47 Oracle Advanced Queuing
Detailed run-time information about propagation is gathered and stored in the DBA_QUEUE_SCHEDULES
view for each propagation schedule. This information can be used by queue designers and administrators
to fix problems or tune performance. For example, available statistics about the total and average number
of message/bytes propagated can be used to tune schedules. Similarly, errors reported by the view can be
used to diagnose and fix problems. The view also describes additional information such as the session ID
of the session handling the propagation, and the process name of the job queue process handling the
propagation.
select * from DBA_QUEUE_SCHEDULES
THIRD-PARTY SUPPORT
48 Oracle Advanced Queuing
AQ allows messages to be enqueued in queues that can then be propagated to different messaging
systems by third-party propagators. If the protocol number for a recipient is in the range 128 - 255, the
address of the recipient is not interpreted by AQ and so the message is not propagated by the AQ system.
Instead, a third-party propagator can then dequeue the message by specifying a reserved consumer name
in the dequeue operation. The reserved consumer names are of the form AQ$_P#, where # is the protocol
number in the range 128-255. For example, the consumer name AQ$_P128 can be used to dequeue
messages for recipients with protocol number 128. The list of recipients for a message with the specific
protocol number is returned in the recipient_list message property on dequeue.
Another way for Advanced Queuing to propagate messages to and from third-party messaging systems is
through Messaging Gateway, an Enterprise Edition feature of Advanced Queuing. Messaging Gateway
dequeues messages from an AQ queue and guarantees delivery to a third-party messaging system like
MQSeries. Messaging Gateway can also dequeue messages from third-party messaging systems and
enqueue them to an AQ queue
ELEMENTS OF ADVANCED QUEUING
49 Oracle Advanced Queuing
 Message
 Queue
 Queue Table
 Agent
 Recipient
 Recipient and Subscription Lists
 Rule
 Rule-Based Subscribers
 Transformation
 Queue Monitor
MESSAGE
50 Oracle Advanced Queuing
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.
CREATE type aq.Message_typ as
object (
subject VARCHAR2(30),
text VARCHAR2(80));
QUEUE
51 Oracle Advanced Queuing
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.
BEGIN
DBMS_AQADM.CREATE_QUEUE (
queue_name => 'Name of Queue',
queue_table => 'Name of Queue Table');
END;
QUEUE TABLE
52 Oracle Advanced Queuing
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.
BEGIN
DBMS_AQADM.CREATE_QUEUE_TABLE (
queue_table => 'Name of Queue Table',
queue_payload_type => 'Name of Payload');
END;
AGENT
53 Oracle Advanced Queuing
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)
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 [schema.]queue[@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.
TYPE aq$_agent IS OBJECT (
name VARCHAR2(30),
address VARCHAR2(1024),
protocol NUMBER);
RECIPIENT
54 Oracle Advanced Queuing
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
55 Oracle Advanced Queuing
Multiple consumers can consume a single message:
 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.
 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
56 Oracle Advanced Queuing
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
57 Oracle Advanced Queuing
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
58 Oracle Advanced Queuing
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
59 Oracle Advanced Queuing
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.
USING PL/SQL TO ACCESS AQ
60 Oracle Advanced Queuing
• Create: queue, queue table, nonpersistent queue, multiconsumer queue/topic,
RAW message, message with structured data
• Get: queue table, queue, multiconsumer queue/topic
• Alter: queue table, queue/topic
• Drop: queue/topic
• Start or stop: queue/topic
• Grant and revoke privileges
• Add, remove, alter subscriber
• Add, remove, alter AQ Internet agents
• Grant or revoke privileges of database users to AQ Internet agents
• Enable, disable, and alter propagation schedule
• Enqueue messages to single consumer queue (point-to-point model)
• Publish messages to multiconsumer queue/topic (publish-subscribe model)
• Subscribing for messages in multiconsumer queue
• Browse messages in a queue
• Receive messages from queue/topic
• Register to receive messages asynchronously
• Listen for messages on multiple queues/topics
• Post messages to anonymous subscriptions
• Bind or unbind agents in a LDAP server
• Add or remove aliases to AQ objects in a LDAP server
DBMS_AQ
61 Oracle Advanced Queuing
The DBMS_AQ package provides an interface to Oracle's Advanced Queuing.
Java interfaces are available for DBMS_AQ and DBMS_AQADM. The Java interfaces are provided in the
$ORACLE_HOME/rdbms/jlib/aqapi.jar. Users are required to have EXECUTE privileges on the DBMS_AQIN
package to use these interfaces.
DATA STRUCTURES FOR DBMS_AQ
62 Oracle Advanced Queuing
Object Name
The object_name data structure names database objects. It applies to queues, queue tables, agent names,
and object types.
Syntax
object_name := VARCHAR2;
object_name := [<schema_name>.]<name>;
Usage Notes
Names for objects are specified by an optional schema name and a name. If the schema name is not
specified, the current schema is assumed. The name must follow object name guidelines in the Oracle9i
SQL Reference with regard to reserved characters. Schema names, agent names, and object type names
can be up to 30 bytes long. Queue names and queue table names can be up to 24 bytes long.
DATA STRUCTURES FOR DBMS_AQ
63 Oracle Advanced Queuing
Type Name
The type_name data structure defines queue types.
Syntax
type_name := VARCHAR2;
type_name := <object_type> | "RAW";
Attribute Description
<object_types> Maximum number of attributes in the object type is limited to 900.
"RAW" To store payload of type RAW, AQ creates a queue table with a LOB
column as the payload repository. The theoretical maximum size of the
message payload is the maximum amount of data that can be stored in a
LOB column. However, the maximum size of the payload is determined
by which programmatic environment you use to access AQ. For PL/SQL,
Java and precompilers the limit is 32K; for the OCI the limit is 4G. Because
the PL/SQL enqueue and dequeue interfaces accept RAW buffers as the
payload parameters you will be limited to 32K bytes. In OCI, the
maximum size of your RAW data will be limited to the maximum amount
of contiguous memory (as an OCIRaw is simply an array of bytes) that the
OCI Object Cache can allocate. Typically, this will be at least 32K bytes
and much larger in many cases.
Because LOB columns are used for storing RAW payload, the AQ
administrator can choose the LOB tablespace and configure the LOB
storage by constructing a LOB storage string in the storage_clause
parameter during queue table creation time.
DATA STRUCTURES FOR DBMS_AQ
64 Oracle Advanced Queuing
AQ PL/SQL Callback
The plsqlcallback data structure specifies the user-defined PL/SQL procedure, defined in the database to
be invoked on message notification.
Syntax
If a notification message is expected for a RAW payload enqueue, then the PL/SQL callback must have the
following signature:
procedure plsqlcallback(
context IN RAW,
reginfo IN SYS.AQ$_REG_INFO,
descr IN SYS.AQ$_DESCRIPTOR,
payload IN RAW,
payloadl IN NUMBER);
SUMMARY OF DBMS_AQ SUBPROGRAMS
65 Oracle Advanced Queuing
Subprograms Description
ENQUEUE Procedure Adds a message to the specified queue.
DEQUEUE Procedure Dequeues a message from the specified
queue.
LISTEN Procedure Listen to one or more queues on behalf of
a list of agents.
REGISTER Procedure Registers for message notifications
UNREGISTER Procedure Unregisters a subscription which turns off
notification
POST Procedure Posts to a anonymous subscription which
allows all clients who are registered for the
subscription to get notifications.
BIND_AGENT Procedure Creates an entry for an AQ agent in the
LDAP directory
UNBIND_AGENT Procedure Removes an entry for an AQ agent from
the LDAP directory
DBMS_AQADM
66 Oracle Advanced Queuing
The DBMS_AQADM package provides procedures to manage Advanced Queuing configuration and
administration information.
SUMMARY OF DBMS_AQADM SUBPROGRAMS
67 Oracle Advanced Queuing
Subprogram Description
CREATE_QUEUE_TABLE Procedure Creates a queue table for messages of a predefined type.
ALTER_QUEUE_TABLE Procedure Alters an existing queue table.
DROP_QUEUE_TABLE Procedure Drops an existing queue table.
CREATE_QUEUE Procedure Creates a queue in the specified queue table.
CREATE_NP_QUEUE Procedure Creates a nonpersistent RAW queue.
ALTER_QUEUE Procedure Alters existing properties of a queue.
DROP_QUEUE Procedure Drops an existing queue.
START_QUEUE Procedure Enables the specified queue for enqueuing or
dequeueing.
STOP_QUEUE Procedure Disables enqueuing or dequeuing on the specified queue.
GRANT_SYSTEM_PRIVILEGE Procedure Grants AQ system privileges to users and roles.
REVOKE_SYSTEM_PRIVILEGE Procedure Revokes AQ system privileges from users and roles.
GRANT_QUEUE_PRIVILEGE Procedure Grants privileges on a queue to users and roles.
REVOKE_QUEUE_PRIVILEGE Procedure Revokes privileges on a queue from users and roles.
ADD_SUBSCRIBER Procedure Adds a default subscriber to a queue.
ALTER_SUBSCRIBER Procedure Alters existing properties of a subscriber to a specified
queue.
SUMMARY OF DBMS_AQADM SUBPROGRAMS
68 Oracle Advanced Queuing
Subprogram Description
REMOVE_SUBSCRIBER Procedure Removes a default subscriber from a queue.
SCHEDULE_PROPAGATION Procedure Schedules propagation of messages from a queue to a destination
identified by a specific dblink.
UNSCHEDULE_PROPAGATION Procedure Unschedules previously scheduled propagation of messages from a
queue to a destination identified by a specific dblink.
VERIFY_QUEUE_TYPES Procedure Verifies that the source and destination queues have identical
types.
ALTER_PROPAGATION_SCHEDULE Procedure Alters parameters for a propagation schedule.
ENABLE_PROPAGATION_SCHEDULE Procedure Enables a previously disabled propagation schedule.
DISABLE_PROPAGATION_SCHEDULE Procedure Disables a propagation schedule.
MIGRATE_QUEUE_TABLE Procedure Upgrades an 8.0-compatible queue table to an 8.1-compatible
queue table, or downgrades an 8.1-compatible queue table to an
8.0-compatible queue table.
CREATE_AQ_AGENT Procedure Registers an agent for AQ Internet access
ALTER_AQ_AGENT Procedure Alters an agent registered for AQ Internet access
DROP_AQ_AGENT Procedure Drops an agent registered for AQ Internet access
ENABLE_DB_ACCESS Procedure Grants an AQ Internet agent the privileges of a specific database
user
DISABLE_DB_ACCESS Procedure Revokes the privileges of a database user from an AQ Internet
agent
ADD_ALIAS_TO_LDAP Procedure Creates an alias for a queue, agent, or a JMS ConnectionFactory in
LDAP.
DEL_ALIAS_FROM_LDAP Procedure Drops an alias for a queue, agent, or JMS ConnectionFactory in
LDAP.
SETTING UP DATA STRUCTURE
69 Oracle Advanced Queuing
You may need to set up the following data structures for certain examples to work:
CONNECT system/manager;
DROP USER aqadm CASCADE;
CREATE USER aqadm IDENTIFIED BY aqadm;
GRANT CONNECT, RESOURCE TO aqadm;
GRANT EXECUTE ON DBMS_AQADM TO aqadm;
GRANT AQ_ADMINISTRATOR_ROLE TO aqadm;
DROP USER aq CASCADE;
CREATE USER aq IDENTIFIED BY aq;
GRANT CONNECT, RESOURCE TO aq;
GRANT EXECUTE ON DBMS_AQ TO aq;
CREATING A QUEUE TABLE AND QUEUE OF OBJECT
TYPE
70 Oracle Advanced Queuing
/* Creating a message type: */
CREATE type aq.Message_typ as object (
subject VARCHAR2(30),
text VARCHAR2(80));
/* Creating a object type queue table and queue: */
BEGIN DBMS_AQADM.CREATE_QUEUE_TABLE (
queue_table => 'aq.objmsgs80_qtab',
queue_payload_type => 'aq.Message_typ');
END;
BEGIN DBMS_AQADM.CREATE_QUEUE (
queue_name => 'msg_queue',
queue_table => 'aq.objmsgs80_qtab');
END;
BEGIN DBMS_AQADM.START_QUEUE (
queue_name => 'msg_queue');
END;
CREATING A QUEUE TABLE AND QUEUE OF RAW
TYPE
71 Oracle Advanced Queuing
/* Creating a RAW type queue table and queue: */
EXECUTE DBMS_AQADM.CREATE_QUEUE_TABLE (
queue_table => 'aq.RawMsgs_qtab',
queue_payload_type => 'RAW');
EXECUTE DBMS_AQADM.CREATE_QUEUE (
queue_name => 'raw_msg_queue',
queue_table => 'aq.RawMsgs_qtab');
EXECUTE DBMS_AQADM.START_QUEUE (
queue_name => 'raw_msg_queue');
CREATING A PRIORITIZED MESSAGE QUEUE TABLE
AND QUEUE
72 Oracle Advanced Queuing
EXECUTE DBMS_AQADM.CREATE_QUEUE_TABLE (
queue_table => 'aq.priority_msg',
sort_list => 'PRIORITY,ENQ_TIME',
queue_payload_type => 'aq.Message_typ');
EXECUTE DBMS_AQADM.CREATE_QUEUE (
queue_name => 'priority_msg_queue',
queue_table => 'aq.priority_msg');
EXECUTE DBMS_AQADM.START_QUEUE (
queue_name => 'priority_msg_queue');
CREATING A MULTICONSUMER QUEUE TABLE AND
QUEUE
73 Oracle Advanced Queuing
EXECUTE DBMS_AQADM.CREATE_QUEUE_TABLE (
queue_table => 'aq.MultiConsumerMsgs_qtab',
multiple_consumers => TRUE,
queue_payload_type => 'aq.Message_typ');
EXECUTE DBMS_AQADM.CREATE_QUEUE (
queue_name => 'msg_queue_multiple',
queue_table => 'aq.MultiConsumerMsgs_qtab');
EXECUTE DBMS_AQADM.START_QUEUE (
queue_name => 'msg_queue_multiple');
CREATING A QUEUE TO DEMONSTRATE
PROPAGATION
74 Oracle Advanced Queuing
EXECUTE DBMS_AQADM.CREATE_QUEUE (
queue_name => 'another_msg_queue',
queue_table => 'aq.MultiConsumerMsgs_qtab');
EXECUTE DBMS_AQADM.START_QUEUE (
queue_name => 'another_msg_queue');
ENQUEUING OF OBJECT TYPE MESSAGES USING
PL/SQL
75 Oracle Advanced Queuing
To enqueue a single message without any other parameters specify the
queue name and the payload.
/* Enqueue to msg_queue: */
DECLARE
enqueue_options dbms_aq.enqueue_options_t;
message_properties dbms_aq.message_properties_t;
message_handle RAW(16);
message aq.message_typ;
BEGIN
message := message_typ('NORMAL MESSAGE',
'enqueued to msg_queue first.');
dbms_aq.enqueue(queue_name => 'msg_queue',
enqueue_options => enqueue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
COMMIT;
END;
DEQUEUING OF OBJECT TYPE MESSAGES USING
PL/SQL
76 Oracle Advanced Queuing
/* Dequeue from msg_queue: */
DECLARE
dequeue_options dbms_aq.dequeue_options_t;
message_properties dbms_aq.message_properties_t;
message_handle RAW(16);
message aq.message_typ;
BEGIN
DBMS_AQ.DEQUEUE(queue_name => 'msg_queue',
dequeue_options => dequeue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
DBMS_OUTPUT.PUT_LINE ('Message: ' || message.subject ||
' ... ' || message.text );
COMMIT;
END;
ENQUEUING OF RAW TYPE MESSAGES USING
PL/SQL
77 Oracle Advanced Queuing
DECLARE
enqueue_options dbms_aq.enqueue_options_t;
message_properties dbms_aq.message_properties_t;
message_handle RAW(16);
message RAW(4096);
BEGIN
message := HEXTORAW(RPAD('FF',4095,'FF'));
DBMS_AQ.ENQUEUE(queue_name => 'raw_msg_queue',
enqueue_options => enqueue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
COMMIT;
END;
DEQUEUING OF RAW TYPE MESSAGES USING
PL/SQL
78 Oracle Advanced Queuing
/* Dequeue from raw_msg_queue: */
DECLARE
dequeue_options DBMS_AQ.dequeue_options_t;
message_properties DBMS_AQ.message_properties_t;
message_handle RAW(16);
message RAW(4096);
BEGIN
DBMS_AQ.DEQUEUE(queue_name => 'raw_msg_queue',
dequeue_options => dequeue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
COMMIT;
END;
ENQUEUING OF MESSAGES BY PRIORITY USING
PL/SQL
79 Oracle Advanced Queuing
/* Enqueue two messages with priority 30 and 5: */
DECLARE
enqueue_options dbms_aq.enqueue_options_t;
message_properties dbms_aq.message_properties_t;
message_handle RAW(16);
message aq.message_typ;
BEGIN
message := message_typ('PRIORITY MESSAGE',
'enqued at priority 30.');
message_properties.priority := 30;
DBMS_AQ.ENQUEUE(queue_name => 'priority_msg_queue',
enqueue_options => enqueue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
message := message_typ('PRIORITY MESSAGE',
'Enqueued at priority 5.');
message_properties.priority := 5;
DBMS_AQ.ENQUEUE(queue_name => 'priority_msg_queue',
enqueue_options => enqueue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
END;
DEQUEUING OF MESSAGES BY PRIORITY USING
PL/SQL
80 Oracle Advanced Queuing
/* Dequeue from priority queue: */
DECLARE
dequeue_options DBMS_AQ.dequeue_options_t;
message_properties DBMS_AQ.message_properties_t;
message_handle RAW(16);
message aq.message_typ;
BEGIN
DBMS_AQ.DEQUEUE(queue_name => 'priority_msg_queue',
dequeue_options => dequeue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
DBMS_OUTPUT.PUT_LINE ('Message: ' || message.subject ||
' ... ' || message.text );
COMMIT;
DBMS_AQ.DEQUEUE(queue_name => 'priority_msg_queue',
dequeue_options => dequeue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
DBMS_OUTPUT.PUT_LINE ('Message: ' || message.subject ||
' ... ' || message.text );
COMMIT;
END;
/* On return, the second message with priority set to 5 will be retrieved before
the message with priority set to 30 since priority takes precedence over enqueue
time. */
ENQUEUING OF MESSAGES WITH TIME DELAY AND
EXPIRATION USING PL/SQL
81 Oracle Advanced Queuing
/* Enqueue message for delayed availability: */
DECLARE
enqueue_options dbms_aq.enqueue_options_t;
message_properties dbms_aq.message_properties_t;
message_handle RAW(16);
message aq.Message_typ;
BEGIN
message := Message_typ('DELAYED',
'This message is delayed one week.');
message_properties.delay := 7*24*60*60;
message_properties.expiration := 2*7*24*60*60;
dbms_aq.enqueue(queue_name => 'msg_queue',
enqueue_options => enqueue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
COMMIT;
END;
ENQUEUING AND DEQUEUING OF MESSAGES TO/FROM A
MULTICONSUMER QUEUE USING PL/SQL
82 Oracle Advanced Queuing
/* Create subscriber list: */
DECLARE
subscriber aq$_agent;
/* Add subscribers RED and GREEN to the suscriber list: */
BEGIN
subscriber := aq$_agent('RED', NULL, NULL);
DBMS_AQADM.ADD_SUBSCRIBER(queue_name => 'msg_queue_multiple',
subscriber => subscriber);
subscriber := aq$_agent('GREEN', NULL, NULL);
DBMS_AQADM.ADD_SUBSCRIBER(queue_name => 'msg_queue_multiple',
subscriber => subscriber);
END;
ENQUEUING AND DEQUEUING OF MESSAGES TO/FROM A
MULTICONSUMER QUEUE USING PL/SQL
83 Oracle Advanced Queuing
DECLARE
enqueue_options DBMS_AQ.enqueue_options_t;
message_properties DBMS_AQ.message_properties_t;
recipients DBMS_AQ.aq$_recipient_list_t;
message_handle RAW(16);
message aq.message_typ;
/* Enqueue MESSAGE 1 for subscribers to the queue
i.e. for RED and GREEN: */
BEGIN
message := message_typ('MESSAGE 1',
'This message is queued for queue subscribers.');
DBMS_AQ.ENQUEUE(queue_name => 'msg_queue_multiple',
enqueue_options => enqueue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
/* Enqueue MESSAGE 2 for specified recipients i.e. for RED and BLUE.*/
message := message_typ('MESSAGE 2',
'This message is queued for two recipients.');
recipients(1) := aq$_agent('RED', NULL, NULL);
recipients(2) := aq$_agent('BLUE', NULL, NULL);
message_properties.recipient_list := recipients;
DBMS_AQ.ENQUEUE(queue_name => 'msg_queue_multiple',
enqueue_options => enqueue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
COMMIT;
END;
Note that RED is both a subscriber to the queue, as well as being a specified recipient of MESSAGE 2.
By contrast, GREEN is only a subscriber to those messages in the queue (in this case, MESSAGE) for
which no recipients have been specified. BLUE, while not a subscriber to the queue, is nevertheless
specified to receive MESSAGE 2.
ENQUEUING AND DEQUEUING OF MESSAGES TO/FROM A
MULTICONSUMER QUEUE USING PL/SQL
84 Oracle Advanced Queuing
/* Dequeue messages from msg_queue_multiple: */
DECLARE
dequeue_options DBMS_AQ.dequeue_options_t;
message_properties DBMS_AQ.message_properties_t;
message_handle RAW(16);
message aq.message_typ;
no_messages exception;
pragma exception_init (no_messages, -25228);
BEGIN
dequeue_options.wait := DBMS_AQ.NO_WAIT;
BEGIN
/* Consumer BLUE will get MESSAGE 2: */
dequeue_options.consumer_name := 'BLUE';
dequeue_options.navigation := FIRST_MESSAGE;
LOOP
DBMS_AQ.DEQUEUE(queue_name => 'msg_queue_multiple',
dequeue_options => dequeue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
DBMS_OUTPUT.PUT_LINE ('Message: ' || message.subject ||
' ... ' || message.text );
dequeue_options.navigation := NEXT_MESSAGE;
END LOOP;
EXCEPTION
WHEN no_messages THEN
DBMS_OUTPUT.PUT_LINE ('No more messages for BLUE');
COMMIT;
END;
ENQUEUING AND DEQUEUING OF MESSAGES TO/FROM A
MULTICONSUMER QUEUE USING PL/SQL
85 Oracle Advanced Queuing
BEGIN
/* Consumer RED will get MESSAGE 1 and MESSAGE 2: */
dequeue_options.consumer_name := 'RED';
dequeue_options.navigation := DBMS_AQ.FIRST_MESSAGE;
LOOP
DBMS_AQ.DEQUEUE(queue_name => 'msg_queue_multiple',
dequeue_options => dequeue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
DBMS_OUTPUT.PUT_LINE ('Message: ' || message.subject ||
' ... ' || message.text );
dequeue_options.navigation := NEXT_MESSAGE;
END LOOP;
EXCEPTION
WHEN no_messages THEN
DBMS_OUTPUT.PUT_LINE ('No more messages for RED');
COMMIT;
END;
ENQUEUING AND DEQUEUING OF MESSAGES TO/FROM A
MULTICONSUMER QUEUE USING PL/SQL
86 Oracle Advanced Queuing
BEGIN
/* Consumer GREEN will get MESSAGE 1: */
dequeue_options.consumer_name := 'GREEN';
dequeue_options.navigation := FIRST_MESSAGE;
LOOP
DBMS_AQ.DEQUEUE(queue_name => 'msg_queue_multiple',
dequeue_options => dequeue_options,
message_properties => message_properties,
payload => message,
msgid => message_handle);
DBMS_OUTPUT.PUT_LINE ('Message: ' || message.subject ||
' ... ' || message.text );
dequeue_options.navigation := NEXT_MESSAGE;
END LOOP;
EXCEPTION
WHEN no_messages THEN
DBMS_OUTPUT.PUT_LINE ('No more messages for GREEN');
COMMIT;
END;
MANAGING PROPAGATION FROM ONE QUEUE TO OTHER
QUEUES IN THE SAME DATABASE USING PL/SQL
87 Oracle Advanced Queuing
/* Schedule propagation from queue q1def to other queues in the same database */
EXECUTE DBMS_AQADM.SCHEDULE_PROPAGATION(queue_name => 'q1def');
/* Disable propagation from queue q1def to other queues in the same
database */
EXECUTE DBMS_AQADM.DISABLE_PROPAGATION_SCHEDULE(
queue_name => 'q1def');
/* Alter schedule from queue q1def to other queues in the same database */
EXECUTE DBMS_AQADM.ALTER_PROPAGATION_SCHEDULE(
queue_name => 'q1def',
duration => '2000',
next_time => 'SYSDATE + 3600/86400',
latency => '32');
/* Enable propagation from queue q1def to other queues in the same database */
EXECUTE DBMS_AQADM.ENABLE_PROPAGATION_SCHEDULE(
queue_name => 'q1def');
/* Unschedule propagation from queue q1def to other queues in the same database
*/
EXECUTE DBMS_AQADM.UNSCHEDULE_PROPAGATION(
queue_name => 'q1def');
MANAGE PROPAGATION FROM ONE QUEUE TO OTHER
QUEUES IN ANOTHER DATABASE USING PL/SQL
88 Oracle Advanced Queuing
/* Schedule propagation from queue q1def to other queues in another database
reached by the database link another_db.world */
EXECUTE DBMS_AQADM.SCHEDULE_PROPAGATION(
queue_name => 'q1def',
destination => 'another_db.world');
/* Disable propagation from queue q1def to other queues in another database
reached by the database link another_db.world */
EXECUTE DBMS_AQADM.DISABLE_PROPAGATION_SCHEDULE(
queue_name => 'q1def',
destination => 'another_db.world');
/* Alter schedule from queue q1def to other queues in another database reached
by the database link another_db.world */
EXECUTE DBMS_AQADM.ALTER_PROPAGATION_SCHEDULE(
queue_name => 'q1def',
destination => 'another_db.world',
duration => '2000',
next_time => 'SYSDATE + 3600/86400',
latency => '32');
/* Enable propagation from queue q1def to other queues in another database
reached by the database link another_db.world */
EXECUTE DBMS_AQADM.ENABLE_PROPAGATION_SCHEDULE(
queue_name => 'q1def',
destination => 'another_db.world');
/* Unschedule propagation from queue q1def to other queues in another database
reached by the database link another_db.world */
EXECUTE DBMS_AQADM.UNSCHEDULE_PROPAGATION(
queue_name => 'q1def',
destination => 'another_db.world');
UNSCHEDULING PROPAGATION USING PL/SQL
89 Oracle Advanced Queuing
/* Unschedule propagation from msg_queue_multiple to the destination another_
db.world */
EXECUTE DBMS_AQADM.UNSCHEDULE_PROPAGATION(
queue_name => 'msg_queue_multiple',
destination => 'another_db.world');
DROPPING AQ OBJECTS
90 Oracle Advanced Queuing
/* Cleans up all objects related to the object type: */
CONNECT aq/aq
EXECUTE DBMS_AQADM.STOP_QUEUE (
queue_name => 'msg_queue');
EXECUTE DBMS_AQADM.DROP_QUEUE (
queue_name => 'msg_queue');
EXECUTE DBMS_AQADM.DROP_QUEUE_TABLE (
queue_table => 'aq.objmsgs80_qtab');
/* Cleans up all objects related to the RAW type: */
EXECUTE DBMS_AQADM.STOP_QUEUE (
queue_name => 'raw_msg_queue');
EXECUTE DBMS_AQADM.DROP_QUEUE (
queue_name => 'raw_msg_queue');
EXECUTE DBMS_AQADM.DROP_QUEUE_TABLE (
queue_table => 'aq.RawMsgs_qtab');
DROPPING AQ OBJECTS
91 Oracle Advanced Queuing
/* Cleans up all objects related to the priority queue: */
EXECUTE DBMS_AQADM.STOP_QUEUE (
queue_name => 'priority_msg_queue');
EXECUTE DBMS_AQADM.DROP_QUEUE (
queue_name => 'priority_msg_queue');
EXECUTE DBMS_AQADM.DROP_QUEUE_TABLE (
queue_table => 'aq.priority_msg');
/* Cleans up all objects related to the multiple-consumer queue: */
EXECUTE DBMS_AQADM.STOP_QUEUE (
queue_name => 'msg_queue_multiple');
EXECUTE DBMS_AQADM.DROP_QUEUE (
queue_name => 'msg_queue_multiple');
EXECUTE DBMS_AQADM.DROP_QUEUE_TABLE (
queue_table => 'aq.MultiConsumerMsgs_qtab');
DROP TYPE aq.message_typ;
REVOKING ROLES AND PRIVILEGES
92 Oracle Advanced Queuing
CONNECT sys/change_on_install
DROP USER aq;
CONTACTS
93
Sopra Steria
AMSL
Building No 4, Plot No - 20&21,Sector - 135,
Dist- Gautam Buddha Nagar,Noida (UP)-201304
www.soprasteria.co.uk
Er Gurpreet Singh
Junior Software Engineer
CUG. 2142
M. +91-9803723925
Gurpreet.singh2@soprasteria.com
Oracle Advanced Queuing
Oracle Advanced Queuing94

More Related Content

What's hot

Understanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginnersUnderstanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginnersCarlos Sierra
 
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsOracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsZohar Elkayam
 
Understand oracle real application cluster
Understand oracle real application clusterUnderstand oracle real application cluster
Understand oracle real application clusterSatishbabu Gunukula
 
Oracle Database SQL Tuning Concept
Oracle Database SQL Tuning ConceptOracle Database SQL Tuning Concept
Oracle Database SQL Tuning ConceptChien Chung Shen
 
Oracle AWR Data mining
Oracle AWR Data miningOracle AWR Data mining
Oracle AWR Data miningYury Velikanov
 
Performance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and UnderscoresPerformance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and UnderscoresJitendra Singh
 
Analyzing and Interpreting AWR
Analyzing and Interpreting AWRAnalyzing and Interpreting AWR
Analyzing and Interpreting AWRpasalapudi
 
Understanding my database through SQL*Plus using the free tool eDB360
Understanding my database through SQL*Plus using the free tool eDB360Understanding my database through SQL*Plus using the free tool eDB360
Understanding my database through SQL*Plus using the free tool eDB360Carlos Sierra
 
Troubleshooting Complex Oracle Performance Problems with Tanel Poder
Troubleshooting Complex Oracle Performance Problems with Tanel PoderTroubleshooting Complex Oracle Performance Problems with Tanel Poder
Troubleshooting Complex Oracle Performance Problems with Tanel PoderTanel Poder
 
Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsEnkitec
 
A deep dive about VIP,HAIP, and SCAN
A deep dive about VIP,HAIP, and SCAN A deep dive about VIP,HAIP, and SCAN
A deep dive about VIP,HAIP, and SCAN Riyaj Shamsudeen
 
Oracle DB 19c: SQL Tuning Using SPM
Oracle DB 19c: SQL Tuning Using SPMOracle DB 19c: SQL Tuning Using SPM
Oracle DB 19c: SQL Tuning Using SPMArturo Aranda
 
Tanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata MigrationsTanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata MigrationsTanel Poder
 
Scaling paypal workloads with oracle rac ss
Scaling paypal workloads with oracle rac ssScaling paypal workloads with oracle rac ss
Scaling paypal workloads with oracle rac ssAnil Nair
 
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...Aaron Shilo
 
Why oracle data guard new features in oracle 18c, 19c
Why oracle data guard new features in oracle 18c, 19cWhy oracle data guard new features in oracle 18c, 19c
Why oracle data guard new features in oracle 18c, 19cSatishbabu Gunukula
 
Tuning for Oracle RAC Wait Events
Tuning for Oracle RAC Wait EventsTuning for Oracle RAC Wait Events
Tuning for Oracle RAC Wait EventsConfio Software
 
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2Tanel Poder
 

What's hot (20)

Understanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginnersUnderstanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginners
 
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsOracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
 
Understand oracle real application cluster
Understand oracle real application clusterUnderstand oracle real application cluster
Understand oracle real application cluster
 
Oracle Database SQL Tuning Concept
Oracle Database SQL Tuning ConceptOracle Database SQL Tuning Concept
Oracle Database SQL Tuning Concept
 
Oracle AWR Data mining
Oracle AWR Data miningOracle AWR Data mining
Oracle AWR Data mining
 
AWR and ASH Deep Dive
AWR and ASH Deep DiveAWR and ASH Deep Dive
AWR and ASH Deep Dive
 
Performance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and UnderscoresPerformance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and Underscores
 
Analyzing and Interpreting AWR
Analyzing and Interpreting AWRAnalyzing and Interpreting AWR
Analyzing and Interpreting AWR
 
Understanding my database through SQL*Plus using the free tool eDB360
Understanding my database through SQL*Plus using the free tool eDB360Understanding my database through SQL*Plus using the free tool eDB360
Understanding my database through SQL*Plus using the free tool eDB360
 
Troubleshooting Complex Oracle Performance Problems with Tanel Poder
Troubleshooting Complex Oracle Performance Problems with Tanel PoderTroubleshooting Complex Oracle Performance Problems with Tanel Poder
Troubleshooting Complex Oracle Performance Problems with Tanel Poder
 
Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning Fundamentals
 
A deep dive about VIP,HAIP, and SCAN
A deep dive about VIP,HAIP, and SCAN A deep dive about VIP,HAIP, and SCAN
A deep dive about VIP,HAIP, and SCAN
 
Analyzing awr report
Analyzing awr reportAnalyzing awr report
Analyzing awr report
 
Oracle DB 19c: SQL Tuning Using SPM
Oracle DB 19c: SQL Tuning Using SPMOracle DB 19c: SQL Tuning Using SPM
Oracle DB 19c: SQL Tuning Using SPM
 
Tanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata MigrationsTanel Poder - Performance stories from Exadata Migrations
Tanel Poder - Performance stories from Exadata Migrations
 
Scaling paypal workloads with oracle rac ss
Scaling paypal workloads with oracle rac ssScaling paypal workloads with oracle rac ss
Scaling paypal workloads with oracle rac ss
 
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
 
Why oracle data guard new features in oracle 18c, 19c
Why oracle data guard new features in oracle 18c, 19cWhy oracle data guard new features in oracle 18c, 19c
Why oracle data guard new features in oracle 18c, 19c
 
Tuning for Oracle RAC Wait Events
Tuning for Oracle RAC Wait EventsTuning for Oracle RAC Wait Events
Tuning for Oracle RAC Wait Events
 
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
Tanel Poder - Troubleshooting Complex Oracle Performance Issues - Part 2
 

Similar to Oracle Advanced Queuing (AQ) Overview

JCON OpenBlend Slovenia 2023 - A High-Speed Data Ingestion Service in Java Us...
JCON OpenBlend Slovenia 2023 - A High-Speed Data Ingestion Service in Java Us...JCON OpenBlend Slovenia 2023 - A High-Speed Data Ingestion Service in Java Us...
JCON OpenBlend Slovenia 2023 - A High-Speed Data Ingestion Service in Java Us...Juarez Junior
 
TDC Connections 2023 - A High-Speed Data Ingestion Service in Java Using MQTT...
TDC Connections 2023 - A High-Speed Data Ingestion Service in Java Using MQTT...TDC Connections 2023 - A High-Speed Data Ingestion Service in Java Using MQTT...
TDC Connections 2023 - A High-Speed Data Ingestion Service in Java Using MQTT...Juarez Junior
 
Oracle Streams
Oracle StreamsOracle Streams
Oracle Streamssmabidazam
 
DeveloperWeek Latin America 2023 - A High-Speed Data Ingestion Service in Jav...
DeveloperWeek Latin America 2023 - A High-Speed Data Ingestion Service in Jav...DeveloperWeek Latin America 2023 - A High-Speed Data Ingestion Service in Jav...
DeveloperWeek Latin America 2023 - A High-Speed Data Ingestion Service in Jav...Juarez Junior
 
🏗️Improve database performance with connection pooling and load balancing tec...
🏗️Improve database performance with connection pooling and load balancing tec...🏗️Improve database performance with connection pooling and load balancing tec...
🏗️Improve database performance with connection pooling and load balancing tec...Alireza Kamrani
 
Big data conference europe real-time streaming in any and all clouds, hybri...
Big data conference europe   real-time streaming in any and all clouds, hybri...Big data conference europe   real-time streaming in any and all clouds, hybri...
Big data conference europe real-time streaming in any and all clouds, hybri...Timothy Spann
 
Vadiraj Raikar_Cloud Automation_DevOps
Vadiraj Raikar_Cloud Automation_DevOpsVadiraj Raikar_Cloud Automation_DevOps
Vadiraj Raikar_Cloud Automation_DevOpsVadiraj Raikar
 
Complete Architecture and Development Guide To Windows Communication Foundati...
Complete Architecture and Development Guide To Windows Communication Foundati...Complete Architecture and Development Guide To Windows Communication Foundati...
Complete Architecture and Development Guide To Windows Communication Foundati...Abdul Khan
 
1480-techintrotoiib-150224130001-conversion-gate01.pptx
1480-techintrotoiib-150224130001-conversion-gate01.pptx1480-techintrotoiib-150224130001-conversion-gate01.pptx
1480-techintrotoiib-150224130001-conversion-gate01.pptxBalakoteswaraReddyM
 
Distributed system architecture
Distributed system architectureDistributed system architecture
Distributed system architectureYisal Khan
 
IBM IMPACT 2014 - AMC-1882 Building a Scalable & Continuously Available IBM M...
IBM IMPACT 2014 - AMC-1882 Building a Scalable & Continuously Available IBM M...IBM IMPACT 2014 - AMC-1882 Building a Scalable & Continuously Available IBM M...
IBM IMPACT 2014 - AMC-1882 Building a Scalable & Continuously Available IBM M...Peter Broadhurst
 
Fyp presentation 2 (SQL Converter)
Fyp presentation 2 (SQL Converter)Fyp presentation 2 (SQL Converter)
Fyp presentation 2 (SQL Converter)Muhammad Shafiq
 
Timothy Spann: Apache Pulsar for ML
Timothy Spann: Apache Pulsar for MLTimothy Spann: Apache Pulsar for ML
Timothy Spann: Apache Pulsar for MLEdunomica
 
WSO2Con USA 2015: WSO2 Integration Platform Deep Dive
WSO2Con USA 2015: WSO2 Integration Platform Deep DiveWSO2Con USA 2015: WSO2 Integration Platform Deep Dive
WSO2Con USA 2015: WSO2 Integration Platform Deep DiveWSO2
 
Message Oriented Middleware
Message Oriented MiddlewareMessage Oriented Middleware
Message Oriented MiddlewareManuswath K.B
 

Similar to Oracle Advanced Queuing (AQ) Overview (20)

JCON OpenBlend Slovenia 2023 - A High-Speed Data Ingestion Service in Java Us...
JCON OpenBlend Slovenia 2023 - A High-Speed Data Ingestion Service in Java Us...JCON OpenBlend Slovenia 2023 - A High-Speed Data Ingestion Service in Java Us...
JCON OpenBlend Slovenia 2023 - A High-Speed Data Ingestion Service in Java Us...
 
TDC Connections 2023 - A High-Speed Data Ingestion Service in Java Using MQTT...
TDC Connections 2023 - A High-Speed Data Ingestion Service in Java Using MQTT...TDC Connections 2023 - A High-Speed Data Ingestion Service in Java Using MQTT...
TDC Connections 2023 - A High-Speed Data Ingestion Service in Java Using MQTT...
 
Oracle Streams
Oracle StreamsOracle Streams
Oracle Streams
 
DeveloperWeek Latin America 2023 - A High-Speed Data Ingestion Service in Jav...
DeveloperWeek Latin America 2023 - A High-Speed Data Ingestion Service in Jav...DeveloperWeek Latin America 2023 - A High-Speed Data Ingestion Service in Jav...
DeveloperWeek Latin America 2023 - A High-Speed Data Ingestion Service in Jav...
 
🏗️Improve database performance with connection pooling and load balancing tec...
🏗️Improve database performance with connection pooling and load balancing tec...🏗️Improve database performance with connection pooling and load balancing tec...
🏗️Improve database performance with connection pooling and load balancing tec...
 
Technical Architectures
Technical ArchitecturesTechnical Architectures
Technical Architectures
 
Spring integration
Spring integrationSpring integration
Spring integration
 
Big data conference europe real-time streaming in any and all clouds, hybri...
Big data conference europe   real-time streaming in any and all clouds, hybri...Big data conference europe   real-time streaming in any and all clouds, hybri...
Big data conference europe real-time streaming in any and all clouds, hybri...
 
Vadiraj Raikar_Cloud Automation_DevOps
Vadiraj Raikar_Cloud Automation_DevOpsVadiraj Raikar_Cloud Automation_DevOps
Vadiraj Raikar_Cloud Automation_DevOps
 
Complete Architecture and Development Guide To Windows Communication Foundati...
Complete Architecture and Development Guide To Windows Communication Foundati...Complete Architecture and Development Guide To Windows Communication Foundati...
Complete Architecture and Development Guide To Windows Communication Foundati...
 
componenets of osb12c
componenets of osb12ccomponenets of osb12c
componenets of osb12c
 
1480-techintrotoiib-150224130001-conversion-gate01.pptx
1480-techintrotoiib-150224130001-conversion-gate01.pptx1480-techintrotoiib-150224130001-conversion-gate01.pptx
1480-techintrotoiib-150224130001-conversion-gate01.pptx
 
Distributed system architecture
Distributed system architectureDistributed system architecture
Distributed system architecture
 
IBM IMPACT 2014 - AMC-1882 Building a Scalable & Continuously Available IBM M...
IBM IMPACT 2014 - AMC-1882 Building a Scalable & Continuously Available IBM M...IBM IMPACT 2014 - AMC-1882 Building a Scalable & Continuously Available IBM M...
IBM IMPACT 2014 - AMC-1882 Building a Scalable & Continuously Available IBM M...
 
Fyp presentation 2 (SQL Converter)
Fyp presentation 2 (SQL Converter)Fyp presentation 2 (SQL Converter)
Fyp presentation 2 (SQL Converter)
 
Componenets of osb12c
Componenets of osb12cComponenets of osb12c
Componenets of osb12c
 
Timothy Spann: Apache Pulsar for ML
Timothy Spann: Apache Pulsar for MLTimothy Spann: Apache Pulsar for ML
Timothy Spann: Apache Pulsar for ML
 
WSO2Con USA 2015: WSO2 Integration Platform Deep Dive
WSO2Con USA 2015: WSO2 Integration Platform Deep DiveWSO2Con USA 2015: WSO2 Integration Platform Deep Dive
WSO2Con USA 2015: WSO2 Integration Platform Deep Dive
 
Message Oriented Middleware
Message Oriented MiddlewareMessage Oriented Middleware
Message Oriented Middleware
 
Sqlnet
SqlnetSqlnet
Sqlnet
 

More from Gurpreet singh

Introduction to Oracle Fusion BIP Reporting
Introduction to Oracle Fusion BIP ReportingIntroduction to Oracle Fusion BIP Reporting
Introduction to Oracle Fusion BIP ReportingGurpreet singh
 
Understanding Flex Fields with Accounting Flexfields(Chart of Accounts) in O...
Understanding Flex Fields with  Accounting Flexfields(Chart of Accounts) in O...Understanding Flex Fields with  Accounting Flexfields(Chart of Accounts) in O...
Understanding Flex Fields with Accounting Flexfields(Chart of Accounts) in O...Gurpreet singh
 
Oracle Application Developmenr Framework
Oracle Application Developmenr FrameworkOracle Application Developmenr Framework
Oracle Application Developmenr FrameworkGurpreet singh
 
Generics and collections in Java
Generics and collections in JavaGenerics and collections in Java
Generics and collections in JavaGurpreet singh
 
IO Streams, Serialization, de-serialization, autoboxing
IO Streams, Serialization, de-serialization, autoboxingIO Streams, Serialization, de-serialization, autoboxing
IO Streams, Serialization, de-serialization, autoboxingGurpreet singh
 
Creating business group in oracle apps
Creating business group in oracle appsCreating business group in oracle apps
Creating business group in oracle appsGurpreet singh
 
Defing locations in Oracle Apps
Defing locations in Oracle AppsDefing locations in Oracle Apps
Defing locations in Oracle AppsGurpreet singh
 
Assigning role AME_BUS_ANALYST
Assigning role AME_BUS_ANALYSTAssigning role AME_BUS_ANALYST
Assigning role AME_BUS_ANALYSTGurpreet singh
 
Introduction to Data Flow Diagram (DFD)
Introduction to Data Flow Diagram (DFD)Introduction to Data Flow Diagram (DFD)
Introduction to Data Flow Diagram (DFD)Gurpreet singh
 
Ingenium test(Exam Management System) Project Presentation (Full)
Ingenium test(Exam Management System) Project Presentation (Full)Ingenium test(Exam Management System) Project Presentation (Full)
Ingenium test(Exam Management System) Project Presentation (Full)Gurpreet singh
 

More from Gurpreet singh (20)

Introduction to Oracle Fusion BIP Reporting
Introduction to Oracle Fusion BIP ReportingIntroduction to Oracle Fusion BIP Reporting
Introduction to Oracle Fusion BIP Reporting
 
Why Messaging system?
Why Messaging system?Why Messaging system?
Why Messaging system?
 
Understanding Flex Fields with Accounting Flexfields(Chart of Accounts) in O...
Understanding Flex Fields with  Accounting Flexfields(Chart of Accounts) in O...Understanding Flex Fields with  Accounting Flexfields(Chart of Accounts) in O...
Understanding Flex Fields with Accounting Flexfields(Chart of Accounts) in O...
 
Oracle Application Developmenr Framework
Oracle Application Developmenr FrameworkOracle Application Developmenr Framework
Oracle Application Developmenr Framework
 
Java Servlet part 3
Java Servlet part 3Java Servlet part 3
Java Servlet part 3
 
Oracle SQL Part 3
Oracle SQL Part 3Oracle SQL Part 3
Oracle SQL Part 3
 
Oracle SQL Part 2
Oracle SQL Part 2Oracle SQL Part 2
Oracle SQL Part 2
 
Oracle SQL Part1
Oracle SQL Part1Oracle SQL Part1
Oracle SQL Part1
 
Generics and collections in Java
Generics and collections in JavaGenerics and collections in Java
Generics and collections in Java
 
IO Streams, Serialization, de-serialization, autoboxing
IO Streams, Serialization, de-serialization, autoboxingIO Streams, Serialization, de-serialization, autoboxing
IO Streams, Serialization, de-serialization, autoboxing
 
Java Servlets Part 2
Java Servlets Part 2Java Servlets Part 2
Java Servlets Part 2
 
Creating business group in oracle apps
Creating business group in oracle appsCreating business group in oracle apps
Creating business group in oracle apps
 
Defing locations in Oracle Apps
Defing locations in Oracle AppsDefing locations in Oracle Apps
Defing locations in Oracle Apps
 
Assigning role AME_BUS_ANALYST
Assigning role AME_BUS_ANALYSTAssigning role AME_BUS_ANALYST
Assigning role AME_BUS_ANALYST
 
PL/SQL Part 5
PL/SQL Part 5PL/SQL Part 5
PL/SQL Part 5
 
PL/SQL Part 3
PL/SQL Part 3PL/SQL Part 3
PL/SQL Part 3
 
PL/SQL Part 2
PL/SQL Part 2PL/SQL Part 2
PL/SQL Part 2
 
PL/SQL Part 1
PL/SQL Part 1PL/SQL Part 1
PL/SQL Part 1
 
Introduction to Data Flow Diagram (DFD)
Introduction to Data Flow Diagram (DFD)Introduction to Data Flow Diagram (DFD)
Introduction to Data Flow Diagram (DFD)
 
Ingenium test(Exam Management System) Project Presentation (Full)
Ingenium test(Exam Management System) Project Presentation (Full)Ingenium test(Exam Management System) Project Presentation (Full)
Ingenium test(Exam Management System) Project Presentation (Full)
 

Recently uploaded

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 

Recently uploaded (20)

Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 

Oracle Advanced Queuing (AQ) Overview

  • 2. OVERVIEW 2 Oracle Advanced Queuing • What Is Advanced Queuing? • General Features of Advanced Queuing • Enqueue Features • Dequeue Features • Propagation Features • Elements of Advanced Queuing • Using PL/SQL to Access AQ • DBMS_AQ • Data Structures for DBMS_AQ • Summary of DBMS_AQ Subprograms • DBMS_AQADM • Summary of DBMS_AQADM Subprograms • Setting up data structure • Creating a Queue Table and Queue of Object Type • Creating a Queue Table and Queue of Raw Type • Creating a Prioritized Message Queue Table and Queue • Creating a Multiconsumer Queue Table and Queue • Creating a Queue to Demonstrate Propagation • Enqueuing of Object Type Messages Using PL/SQL
  • 3. OVERVIEW 3 Oracle Advanced Queuing • DEqueuing of Object Type Messages Using PL/SQL • Enqueuing of RAW Type Messages Using PL/SQL • DEqueuing of RAW Type Messages Using PL/SQL • Enqueuing of Messages by Priority Using PL/SQL • DEqueuing of Messages by Priority Using PL/SQL • Enqueuing of Messages with Time Delay and Expiration Using PL/SQL • Enqueuing and Dequeuing of Messages to/from a Multiconsumer Queue Using PL/SQL • Managing Propagation From One Queue To Other Queues In The Same Database Using PL/SQL • Manage Propagation From One Queue To Other Queues In Another Database Using PL/SQL • Unscheduling Propagation Using PL/SQL • Dropping AQ Objects • Revoking Roles and Privileges
  • 4. MESSAGING & QUEUING 4 Oracle Advanced Queuing  An essential part of Distributed Application Development (DAD)  A key piece of a middle-ware known as Message-Oriented Middleware (MOM) Motto: Every DAD needs a MOM
  • 5. WHAT DOES MOM PROVIDE? 5 Oracle Advanced Queuing  Time-independent responses in a client/server environment  Help in passing information between servers and clients  A facility that allows general-purpose messages to be exchanged in a client/server system using message queues
  • 6. WHAT IS ADVANCED QUEUING? 6 Oracle Advanced Queuing  Oracle Advance Queuing is Oracle’s message queuing facility  Available as of Oracle 8.0.3  First database-integrated messaging system in the industry
  • 7. WHAT IS ADVANCED QUEUING? 7 Oracle Advanced Queuing When Web-based business applications communicate with each other, producer applications ENQUEUE messages and consumer applications DEQUEUE messages. Advanced Queuing provides database-integrated message queuing functionality. Advanced Queuing leverages the functions of the Oracle database so that messages can be stored persistently, propagated between queues on different machines and databases, and transmitted using Oracle Net Services, HTTP(S), and SMTP.
  • 8. WHAT IS ADVANCED QUEUING? 8 Oracle Advanced Queuing
  • 9. WHAT IS ADVANCED QUEUING? 9 Oracle Advanced Queuing Advanced Queuing provides the message management functionality and asynchronous communication needed for application integration. In an integrated environment, messages travel between the Oracle database server and the applications and users, as shown in Figure. Using Oracle Net Services, messages are exchanged between a client and the Oracle database server or between two Oracle databases. Oracle Net Services also propagates messages from one Oracle queue to another.
  • 10. WHAT IS ADVANCED QUEUING? 10 Oracle Advanced Queuing You can access Advanced Queuing functionality through the following interfaces:  PL/SQL using DBMS_AQ, DBMS_AQADM, and DBMS_AQELM.  Visual Basic using Oracle Objects for OLE.  Java using the oracle.AQ Java package.  Java Message Service (JMS) using the oracle.jms Java package.  Internet access using HTTP, HTTPS, and SMTP Advanced Queuing exhibits high performance characteristics as measured by the following metrics:  Number of messages enqueued/dequeued per second  Time to evaluate a complex query on a message warehouse  Time to recover/restart the messaging process after a failure Queuing systems must be scalable. Advanced Queuing exhibits high performance as the number of programs using the application increases, as the number of messages increases, and as the size of the message warehouse increases.
  • 11. GENERAL FEATURES OF ADVANCED QUEUING 11 Oracle Advanced Queuing  Nonrepudiation and the AQ$<QueueTableName> View  Point-to-Point and Publish-Subscribe Messaging  Oracle Internet Directory  Oracle Enterprise Manager Integration  Message Format Transformation  SQL Access  Support for Statistics Views  Structured Payloads  Retention and Message History  Tracking and Event Journals  Queue-Level Access Control  Nonpersistent Queues  Support for Oracle9i Real Application Clusters  XMLType Payloads
  • 12. NONREPUDIATION AND THE AQ$<QUEUETABLENAME> VIEW 12 Oracle Advanced Queuing Advanced Queuing maintains the entire history of information about a message along with the message itself. You can look up history information by using the AQ$<QueueTableName> view. This information serves as the proof of sending and receiving of messages and can be used for nonrepudiation of the sender and nonrepudiation of the receiver. The following information is kept at enqueue for nonrepudiation of the enqueuer:  AQ agent doing the enqueue  Enqueue time  Transaction ID of the transaction doing the enqueue The following information is kept at dequeue for nonrepudiation of the dequeuer:  AQ agent doing dequeue  Dequeue time  Transaction ID of the transaction doing dequeue After propagation, the Original_Msgid field in the destination queue of propagation corresponds to the message ID of the source message. This field can be used to correlate the propagated messages. This is useful for nonrepudiation of the dequeuer of propagated messages. Stronger nonrepudiation can be achieved by enqueuing the digital signature of the sender at the time of enqueue with the message and by storing the digital signature of the dequeuer at the time of dequeue.
  • 13. POINT-TO-POINT AND PUBLISH-SUBSCRIBE MESSAGING 13 Oracle Advanced Queuing A combination of features allows publish-subscribe messaging between applications. These features include rule-based subscribers, message propagation, the listen feature, and notification capabilities. Advanced Queuing sends and receives messages in the following ways:  Point-to-Point  Publish-Subscribe Point-to-Point A point-to-point message is aimed at a specific target. Senders and receivers decide on a common queue in which to exchange messages. Each message is consumed by only one receiver. Each application has its own message queue, known as a single-consumer queue. Publish-Subscribe A publish-subscribe message can be consumed by multiple receivers. Publish-subscribe messaging has a wide dissemination mode--broadcast--and a more narrowly aimed mode--multicast, also called point-to- multipoint. Broadcasting is the equivalent of a radio station not knowing exactly who the audience is for a given program. The dequeuers are subscribers to multiconsumer queues In contrast, multicast is the same as a magazine publisher who knows who the subscribers are. Multicast is also referred to as point-to- multipoint because a single publisher sends messages to multiple receivers, called recipients, who may or may not be subscribers to the queues that serve as exchange mechanisms.
  • 14. ORACLE INTERNET DIRECTORY 14 Oracle Advanced Queuing Oracle Internet Directory is a native LDAPv3 directory service built on the Oracle database that centralizes a wide variety of information, including e-mail addresses, telephone numbers, passwords, security certificates, and configuration data for many types of networked devices. You can look up enterprise-wide queuing information--queues, subscriptions, and events--from one location, the Oracle Internet Directory.
  • 15. ORACLE ENTERPRISE MANAGER INTEGRATION 15 Oracle Advanced Queuing You can use Enterprise Manager to do the following:  Create and manage queues, queue tables, propagation schedules, and transformations  Monitor your AQ environment using the AQ topology at the databse and queue levels, and by viewing queue errors and queue and session statistics.
  • 16. MESSAGE FORMAT TRANSFORMATION 16 Oracle Advanced Queuing The message format transformation feature supports applications that use data in different formats. 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 as follows: • During enqueue, to transform the message to the correct type before inserting it into the queue.  You can convert a message to the payload type of the queue at enqueue time. Thus, the type of the message to be enqueued need not match the payload type of the queue. • During dequeue, to receive the message in the desired format  A message can be transformed to the desired format before returning it to the dequeuer. • By a remote subscriber, who can choose to receive a message in a format different from the format of the source queue  Before propagating the message to the remote subscriber, the message is transformed according to the transformation that the remote subscriber specified when subscribing to the queue. Following figure shows, queuing, routing, and transformation are essential building blocks to an integrated application architecture. The figure shows how data from the Out queue of a CRM application is routed and transformed in the integration hub and then propagated to the In queue of the Web application. The transformation engine maps the message from the format of the Out queue to the format of the In queue.
  • 17. SQL ACCESS 17 Oracle Advanced Queuing Messages are placed in normal rows in a database table, and so can be queried using standard SQL. This means that you can use SQL to access the message properties, the message history, and the payload. With SQL access you can also do auditing and tracking. All available SQL technology, such as indexes, can be used to optimize access to messages. select * from aq.aq$objmsgs80_qtab
  • 18. SUPPORT FOR STATISTICS VIEWS 18 Oracle Advanced Queuing Basic statistics about queues are available using the GV$AQ view. select * from GV$AQ
  • 19. STRUCTURED PAYLOADS 19 Oracle Advanced Queuing You can use object types to structure and manage message payloads. RDBMSs in general have a richer typing system than messaging systems. Since Oracle is an object-relational DBMS, it supports both traditional relational types as well as user-defined types. Many powerful features are enabled as a result of having strongly typed content, such as content whose format is defined by an external type system. These include:  Content-based routing: Advanced Queuing can examine the content and automatically route the message to another queue based on the content.  Content-based subscription: a publish and subscribe system is built on top of a messaging system so that you can create subscriptions based on content.  Querying: the ability to execute queries on the content of the message enables message warehousing. CREATE type aq.Message_typ as object ( subject VARCHAR2(30), text VARCHAR2(80));
  • 20. RETENTION AND MESSAGE HISTORY 20 Oracle Advanced Queuing The systems administrator specifies the retention duration to retain messages after consumption. Advanced Queuing stores information about the history of each message, preserving the queue and message properties of delay, expiration, and retention for messages destined for local or remote receivers. The information contains the enqueue and dequeue times and the identification of the transaction that executed each request. This allows users to keep a history of relevant messages. The history can be used for tracking, data warehouse, and data mining operations, as well as specific auditing functions. select * from dba_queues where qid=14140
  • 21. TRACKING AND EVENT JOURNALS 21 Oracle Advanced Queuing If messages are retained, they can be related to each other. For example, if a message m2 is produced as a result of the consumption of message m1, m1 is related to m2. This allows users to track sequences of related messages. These sequences represent event journals, which are often constructed by applications. Advanced Queuing is designed to let applications create event journals automatically. When an online order is placed, multiple messages are generated by the various applications involved in processing the order. Advanced Queuing offers features to track interrelated messages independent of the applications that generated them. You can determine who enqueued and dequeued messages, who the users are, and who did what operations. With Advanced Queuing tracking features, you can use SQL SELECT and JOIN statements to get order information from AQ$QUETABLENAME and the views ENQ_TRAN_ID, DEQ_TRAN_ID, USER_DATA (the payload), CORR_ID, and MSG_ID. These views contain the following data used for tracking:  Transaction IDs--from ENQ_TRAN_ID and DEQ_TRAN_ID, captured during enqueuing and dequeuing.  Correlation IDs--from CORR_ID, part of the message properties  Message content that can be used for tracking--USER_DATA
  • 22. QUEUE-LEVEL ACCESS CONTROL 22 Oracle Advanced Queuing The owner of an queue can grant or revoke queue-level privileges on the queue. Database administrators can grant or revoke new AQ system-level privileges to any database user. Database administrators can also make any database user an AQ administrator.
  • 23. NONPERSISTENT QUEUES 23 Oracle Advanced Queuing Advanced Queuing can deliver nonpersistent messages asynchronously to subscribers. These messages can be event-driven and do not persist beyond the failure of the system (or instance). Advanced Queuing supports persistent and nonpersistent messages with a common API. A message in a nonpersistent queue is not stored in a database table. You create a nonpersistent queue, which can be either a single-consumer or multiconsumer type. These queues are created in a system- created queue table (AQ$_MEM_SC for single-consumer queues and AQ$_MEM_MC for multiconsumer queues) in the schema specified by the create_np_queue command. Subscribers can be added to the multiconsumer queues. Nonpersistent queues can be destinations for propagation. You use the enqueue interface to enqueue messages into a nonpersistent queue in the normal way. You can enqueue RAW and Object Type (ADT) messages into a nonpersistent queue. You retrieve messages from a nonpersistent queue through the asynchronous notification mechanism, registering for the notification (using LNOCISubcriptionRegister or DBMS_AQADM.REGISTER) for the queues you are interested in. When a message is enqueued into a queue, it is delivered to clients with active registrations for the queue. The messages are published to the interested clients without incurring the overhead of storing them in the database.
  • 24. XMLTYPE PAYLOADS 24 Oracle Advanced Queuing You can create queues that use the new opaque type, XMLType. These queues can be used to transmit and store messages that are XML documents. Using XMLType, you can do the following:  Store any type of message in a queue  Store documents internally as CLOBs  Store more than one type of payload in a queue  Query XMLType columns using the operators ExistsNode() and SchemaMatch()  Specify the operators in subscriber rules or dequeue conditions
  • 25. ENQUEUE FEATURES 25 Oracle Advanced Queuing  Correlation Identifiers  Subscription and recipient lists  Priority and ordering of messages in Enqueuing  Message grouping  Propagation  Sender Identification  Time specification and scheduling  Asynchronous notification
  • 26. CORRELATION IDENTIFIERS 26 Oracle Advanced Queuing Users can assign an identifier to each message, thus providing a means to retrieve specific messages at a later time.
  • 27. SUBSCRIPTION AND RECIPIENT LISTS 27 Oracle Advanced Queuing A single message can be designed to be consumed by multiple consumers. A queue administrator can specify the list of subscribers who can retrieve messages from a queue. Different queues can have different subscribers, and a consumer program 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. You can design a single message for consumption by multiple consumers in a number of different ways. The consumers who are allowed to retrieve the message are specified as explicit recipients of the message by the user or application that enqueues the message. Every explicit recipient is an agent identified by name, address, and protocol. A queue administrator may also specify a default list of recipients who can retrieve all the messages from a specific queue. These implicit recipients become subscribers to the queue by being specified in the default list. If a message is enqueued without specifying any explicit recipients, the message is delivered to all the designated subscribers. A rule-based subscriber is one that has a rule associated with it in the default recipient list. A rule-based subscriber will be sent a message with no explicit recipients specified only if the associated rule evaluated to TRUE for the message. 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.
  • 28. PRIORITY AND ORDERING OF MESSAGES IN ENQUEUING 28 Oracle Advanced Queuing It is possible to specify the priority of the enqueued message. An enqueued message can also have its exact position in the queue specified. This means that users have three options to specify the order in which messages are consumed: (a) a sort order specifies which properties are used to order all message in a queue; (b) a priority can be assigned to each message; (c) a sequence deviation allows you to position a message in relation to other messages. Further, if several consumers act on the same queue, a consumer will get the first message that is available for immediate consumption. A message that is in the process of being consumed by another consumer will be skipped.
  • 29. MESSAGE GROUPING 29 Oracle Advanced Queuing Messages belonging to one queue can be grouped to form a set that can only be consumed by one user at a time. This requires that the queue be created in a queue table that is enabled for message grouping. All messages belonging to a group have to be created in the same transaction and all messages created in one transaction belong to the same group. This feature allows users to segment complex messages into simple messages; for example, messages directed to a queue containing invoices can be constructed as a group of messages starting with the header message, followed by messages representing details, followed by the trailer message.
  • 30. PROPAGATION 30 Oracle Advanced Queuing This feature enables applications to communicate with each other without having to be connected to the same database or the same queue. Messages can be propagated from one Oracle AQ to another, irrespective of whether the queues are local or remote. Propagation is done using database links and Oracle Net Services.
  • 31. SENDER IDENTIFICATION 31 Oracle Advanced Queuing Applications can mark the messages they send with a custom identification. Oracle also automatically identifies the queue from which a message was dequeued. This allows applications to track the pathway of a propagated message or a string messages within the same database.
  • 32. TIME SPECIFICATION AND SCHEDULING 32 Oracle Advanced Queuing Delay interval or expiration intervals can be specified for an enqueued message, thereby providing windows of execution. A message can be marked as available for processing only after a specified time elapses (a delay time) and has to be consumed before a specified time limit expires.
  • 33. ASYNCHRONOUS NOTIFICATION 33 Oracle Advanced Queuing The asynchronous notification feature allows clients to receive notification of a message of interest. The client can use it to monitor multiple subscriptions. The client does not have to be connected to the database to receive notifications regarding its subscriptions. Clients can use the OCI function, LNOCISubcriptionRegister, or the PL/SQL procedure DBMS_AQ.REGISTER to register interest in messages in a queue.
  • 34. DEQUEUE FEATURES 34 Oracle Advanced Queuing  Recipients  Navigation of Messages in Dequeuing  Modes of Dequeuing  Optimization of Waiting for the Arrival of Messages  Retries with Delays  Optional Transaction Protection  Exception Handling  Listen Capability (Wait on Multiple Queues)  Dequeue Message Header with No Payload
  • 35. RECIPIENTS 35 Oracle Advanced Queuing A message can be retrieved by multiple recipients without the need for multiple copies of the same message. Designated recipients can be located locally or at remote sites.
  • 36. NAVIGATION OF MESSAGES IN DEQUEUING 36 Oracle Advanced Queuing Users have several options to select a message from a queue. They can select the first message or once they have selected a message and established a position, they can retrieve the next. The selection is influenced by the ordering or can be limited by specifying a correlation identifier. Users can also retrieve a specific message using the message identifier.
  • 37. MODES OF DEQUEUING 37 Oracle Advanced Queuing A DEQUEUE request can either browse or remove a message. If a message is browsed, it remains available for further processing. If a message is removed, it is not available more for DEQUEUE requests. Depending on the queue properties, a removed message may be retained in the queue table. Specified as DEQUEUE_OPTIONS_T Attributes
  • 38. OPTIMIZATION OF WAITING FOR THE ARRIVAL OF MESSAGES 38 Oracle Advanced Queuing A DEQUEUE can be issued against an empty queue. To avoid polling for the arrival of a new message, a user can specify if and for how long the request is allowed to wait for the arrival of a message.
  • 39. RETRIES WITH DELAYS 39 Oracle Advanced Queuing A message must be consumed exactly once. If an attempt to dequeue a message fails and the transaction is rolled back, the message will be made available for reprocessing after some user-specified delay elapses. Reprocessing will be attempted up to the user-specified limit.
  • 40. OPTIONAL TRANSACTION PROTECTION 40 Oracle Advanced Queuing ENQUEUE and DEQUEUE requests are normally part of a transaction that contains the requests, thereby providing the desired transactional behavior. You can, however, specify that a specific request is a transaction by itself, making the result of that request immediately visible to other transactions. This means that messages can be made visible to the external world as soon as the ENQUEUE or DEQUEUE statement is issued or after the transaction is committed.
  • 41. EXCEPTION HANDLING 41 Oracle Advanced Queuing A message may not be consumed within given constraints, such as within the window of execution or within the limits of the retries. If such a condition arises, the message will be moved to a user-specified exception queue. SELECT * FROM SYS.ALL_QUEUES
  • 42. DEQUEUE MESSAGE HEADER WITH NO PAYLOAD 42 Oracle Advanced Queuing The dequeue mode REMOVE_NODATA can be used to remove a message from a queue without retrieving the payload. Use this mode to delete a message with a large payload whose content is irrelevant.
  • 43. PROPAGATION FEATURES 43 Oracle Advanced Queuing  Automated Coordination of Enqueuing and Dequeuing  Propagation of Messages with LOBs  Propagation Scheduling  Enhanced Propagation Scheduling Capabilities  Third-Party Support
  • 44. AUTOMATED COORDINATION OF ENQUEUING AND DEQUEUING 44 Oracle Advanced Queuing Recipients can be local or remote. Because Oracle does not support distributed object types, remote enqueuing or dequeuing using a standard database link does not work. However, you can use AQ message propagation to enqueue to a remote queue. For example, you can connect to database X and enqueue the message in a queue, DROPBOX, located in database X. You can configure AQ so that all messages enqueued in DROPBOX will be automatically propagated to another queue in database Y, regardless of whether database Y is local or remote. AQ will automatically check if the type of the remote queue in database Y is structurally equivalent to the type of the local queue in database X and propagate the message. Recipients of propagated messages can be applications or queues. If the recipient is a queue, the actual recipients are determined by the subscription list associated with the recipient queue. If the queues are remote, messages are propagated using the specified database link. Only AQ-to-AQ message propagation is supported.
  • 45. PROPAGATION OF MESSAGES WITH LOBS 45 Oracle Advanced Queuing Propagation handles payloads with LOB attributes.
  • 46. PROPAGATION SCHEDULING 46 Oracle Advanced Queuing Messages can be scheduled to propagate from a queue to local or remote destinations. Administrators can specify the start time, the propagation window, and a function to determine the next propagation window (for periodic schedules).
  • 47. ENHANCED PROPAGATION SCHEDULING CAPABILITIES 47 Oracle Advanced Queuing Detailed run-time information about propagation is gathered and stored in the DBA_QUEUE_SCHEDULES view for each propagation schedule. This information can be used by queue designers and administrators to fix problems or tune performance. For example, available statistics about the total and average number of message/bytes propagated can be used to tune schedules. Similarly, errors reported by the view can be used to diagnose and fix problems. The view also describes additional information such as the session ID of the session handling the propagation, and the process name of the job queue process handling the propagation. select * from DBA_QUEUE_SCHEDULES
  • 48. THIRD-PARTY SUPPORT 48 Oracle Advanced Queuing AQ allows messages to be enqueued in queues that can then be propagated to different messaging systems by third-party propagators. If the protocol number for a recipient is in the range 128 - 255, the address of the recipient is not interpreted by AQ and so the message is not propagated by the AQ system. Instead, a third-party propagator can then dequeue the message by specifying a reserved consumer name in the dequeue operation. The reserved consumer names are of the form AQ$_P#, where # is the protocol number in the range 128-255. For example, the consumer name AQ$_P128 can be used to dequeue messages for recipients with protocol number 128. The list of recipients for a message with the specific protocol number is returned in the recipient_list message property on dequeue. Another way for Advanced Queuing to propagate messages to and from third-party messaging systems is through Messaging Gateway, an Enterprise Edition feature of Advanced Queuing. Messaging Gateway dequeues messages from an AQ queue and guarantees delivery to a third-party messaging system like MQSeries. Messaging Gateway can also dequeue messages from third-party messaging systems and enqueue them to an AQ queue
  • 49. ELEMENTS OF ADVANCED QUEUING 49 Oracle Advanced Queuing  Message  Queue  Queue Table  Agent  Recipient  Recipient and Subscription Lists  Rule  Rule-Based Subscribers  Transformation  Queue Monitor
  • 50. MESSAGE 50 Oracle Advanced Queuing 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. CREATE type aq.Message_typ as object ( subject VARCHAR2(30), text VARCHAR2(80));
  • 51. QUEUE 51 Oracle Advanced Queuing 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. BEGIN DBMS_AQADM.CREATE_QUEUE ( queue_name => 'Name of Queue', queue_table => 'Name of Queue Table'); END;
  • 52. QUEUE TABLE 52 Oracle Advanced Queuing 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. BEGIN DBMS_AQADM.CREATE_QUEUE_TABLE ( queue_table => 'Name of Queue Table', queue_payload_type => 'Name of Payload'); END;
  • 53. AGENT 53 Oracle Advanced Queuing 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) 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 [schema.]queue[@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. TYPE aq$_agent IS OBJECT ( name VARCHAR2(30), address VARCHAR2(1024), protocol NUMBER);
  • 54. RECIPIENT 54 Oracle Advanced Queuing 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
  • 55. RECIPIENT AND SUBSCRIPTION LISTS 55 Oracle Advanced Queuing Multiple consumers can consume a single message:  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.  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.
  • 56. RULE 56 Oracle Advanced Queuing 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)
  • 57. RULE-BASED SUBSCRIBERS 57 Oracle Advanced Queuing 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.
  • 58. TRANSFORMATION 58 Oracle Advanced Queuing 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.
  • 59. QUEUE MONITOR 59 Oracle Advanced Queuing 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.
  • 60. USING PL/SQL TO ACCESS AQ 60 Oracle Advanced Queuing • Create: queue, queue table, nonpersistent queue, multiconsumer queue/topic, RAW message, message with structured data • Get: queue table, queue, multiconsumer queue/topic • Alter: queue table, queue/topic • Drop: queue/topic • Start or stop: queue/topic • Grant and revoke privileges • Add, remove, alter subscriber • Add, remove, alter AQ Internet agents • Grant or revoke privileges of database users to AQ Internet agents • Enable, disable, and alter propagation schedule • Enqueue messages to single consumer queue (point-to-point model) • Publish messages to multiconsumer queue/topic (publish-subscribe model) • Subscribing for messages in multiconsumer queue • Browse messages in a queue • Receive messages from queue/topic • Register to receive messages asynchronously • Listen for messages on multiple queues/topics • Post messages to anonymous subscriptions • Bind or unbind agents in a LDAP server • Add or remove aliases to AQ objects in a LDAP server
  • 61. DBMS_AQ 61 Oracle Advanced Queuing The DBMS_AQ package provides an interface to Oracle's Advanced Queuing. Java interfaces are available for DBMS_AQ and DBMS_AQADM. The Java interfaces are provided in the $ORACLE_HOME/rdbms/jlib/aqapi.jar. Users are required to have EXECUTE privileges on the DBMS_AQIN package to use these interfaces.
  • 62. DATA STRUCTURES FOR DBMS_AQ 62 Oracle Advanced Queuing Object Name The object_name data structure names database objects. It applies to queues, queue tables, agent names, and object types. Syntax object_name := VARCHAR2; object_name := [<schema_name>.]<name>; Usage Notes Names for objects are specified by an optional schema name and a name. If the schema name is not specified, the current schema is assumed. The name must follow object name guidelines in the Oracle9i SQL Reference with regard to reserved characters. Schema names, agent names, and object type names can be up to 30 bytes long. Queue names and queue table names can be up to 24 bytes long.
  • 63. DATA STRUCTURES FOR DBMS_AQ 63 Oracle Advanced Queuing Type Name The type_name data structure defines queue types. Syntax type_name := VARCHAR2; type_name := <object_type> | "RAW"; Attribute Description <object_types> Maximum number of attributes in the object type is limited to 900. "RAW" To store payload of type RAW, AQ creates a queue table with a LOB column as the payload repository. The theoretical maximum size of the message payload is the maximum amount of data that can be stored in a LOB column. However, the maximum size of the payload is determined by which programmatic environment you use to access AQ. For PL/SQL, Java and precompilers the limit is 32K; for the OCI the limit is 4G. Because the PL/SQL enqueue and dequeue interfaces accept RAW buffers as the payload parameters you will be limited to 32K bytes. In OCI, the maximum size of your RAW data will be limited to the maximum amount of contiguous memory (as an OCIRaw is simply an array of bytes) that the OCI Object Cache can allocate. Typically, this will be at least 32K bytes and much larger in many cases. Because LOB columns are used for storing RAW payload, the AQ administrator can choose the LOB tablespace and configure the LOB storage by constructing a LOB storage string in the storage_clause parameter during queue table creation time.
  • 64. DATA STRUCTURES FOR DBMS_AQ 64 Oracle Advanced Queuing AQ PL/SQL Callback The plsqlcallback data structure specifies the user-defined PL/SQL procedure, defined in the database to be invoked on message notification. Syntax If a notification message is expected for a RAW payload enqueue, then the PL/SQL callback must have the following signature: procedure plsqlcallback( context IN RAW, reginfo IN SYS.AQ$_REG_INFO, descr IN SYS.AQ$_DESCRIPTOR, payload IN RAW, payloadl IN NUMBER);
  • 65. SUMMARY OF DBMS_AQ SUBPROGRAMS 65 Oracle Advanced Queuing Subprograms Description ENQUEUE Procedure Adds a message to the specified queue. DEQUEUE Procedure Dequeues a message from the specified queue. LISTEN Procedure Listen to one or more queues on behalf of a list of agents. REGISTER Procedure Registers for message notifications UNREGISTER Procedure Unregisters a subscription which turns off notification POST Procedure Posts to a anonymous subscription which allows all clients who are registered for the subscription to get notifications. BIND_AGENT Procedure Creates an entry for an AQ agent in the LDAP directory UNBIND_AGENT Procedure Removes an entry for an AQ agent from the LDAP directory
  • 66. DBMS_AQADM 66 Oracle Advanced Queuing The DBMS_AQADM package provides procedures to manage Advanced Queuing configuration and administration information.
  • 67. SUMMARY OF DBMS_AQADM SUBPROGRAMS 67 Oracle Advanced Queuing Subprogram Description CREATE_QUEUE_TABLE Procedure Creates a queue table for messages of a predefined type. ALTER_QUEUE_TABLE Procedure Alters an existing queue table. DROP_QUEUE_TABLE Procedure Drops an existing queue table. CREATE_QUEUE Procedure Creates a queue in the specified queue table. CREATE_NP_QUEUE Procedure Creates a nonpersistent RAW queue. ALTER_QUEUE Procedure Alters existing properties of a queue. DROP_QUEUE Procedure Drops an existing queue. START_QUEUE Procedure Enables the specified queue for enqueuing or dequeueing. STOP_QUEUE Procedure Disables enqueuing or dequeuing on the specified queue. GRANT_SYSTEM_PRIVILEGE Procedure Grants AQ system privileges to users and roles. REVOKE_SYSTEM_PRIVILEGE Procedure Revokes AQ system privileges from users and roles. GRANT_QUEUE_PRIVILEGE Procedure Grants privileges on a queue to users and roles. REVOKE_QUEUE_PRIVILEGE Procedure Revokes privileges on a queue from users and roles. ADD_SUBSCRIBER Procedure Adds a default subscriber to a queue. ALTER_SUBSCRIBER Procedure Alters existing properties of a subscriber to a specified queue.
  • 68. SUMMARY OF DBMS_AQADM SUBPROGRAMS 68 Oracle Advanced Queuing Subprogram Description REMOVE_SUBSCRIBER Procedure Removes a default subscriber from a queue. SCHEDULE_PROPAGATION Procedure Schedules propagation of messages from a queue to a destination identified by a specific dblink. UNSCHEDULE_PROPAGATION Procedure Unschedules previously scheduled propagation of messages from a queue to a destination identified by a specific dblink. VERIFY_QUEUE_TYPES Procedure Verifies that the source and destination queues have identical types. ALTER_PROPAGATION_SCHEDULE Procedure Alters parameters for a propagation schedule. ENABLE_PROPAGATION_SCHEDULE Procedure Enables a previously disabled propagation schedule. DISABLE_PROPAGATION_SCHEDULE Procedure Disables a propagation schedule. MIGRATE_QUEUE_TABLE Procedure Upgrades an 8.0-compatible queue table to an 8.1-compatible queue table, or downgrades an 8.1-compatible queue table to an 8.0-compatible queue table. CREATE_AQ_AGENT Procedure Registers an agent for AQ Internet access ALTER_AQ_AGENT Procedure Alters an agent registered for AQ Internet access DROP_AQ_AGENT Procedure Drops an agent registered for AQ Internet access ENABLE_DB_ACCESS Procedure Grants an AQ Internet agent the privileges of a specific database user DISABLE_DB_ACCESS Procedure Revokes the privileges of a database user from an AQ Internet agent ADD_ALIAS_TO_LDAP Procedure Creates an alias for a queue, agent, or a JMS ConnectionFactory in LDAP. DEL_ALIAS_FROM_LDAP Procedure Drops an alias for a queue, agent, or JMS ConnectionFactory in LDAP.
  • 69. SETTING UP DATA STRUCTURE 69 Oracle Advanced Queuing You may need to set up the following data structures for certain examples to work: CONNECT system/manager; DROP USER aqadm CASCADE; CREATE USER aqadm IDENTIFIED BY aqadm; GRANT CONNECT, RESOURCE TO aqadm; GRANT EXECUTE ON DBMS_AQADM TO aqadm; GRANT AQ_ADMINISTRATOR_ROLE TO aqadm; DROP USER aq CASCADE; CREATE USER aq IDENTIFIED BY aq; GRANT CONNECT, RESOURCE TO aq; GRANT EXECUTE ON DBMS_AQ TO aq;
  • 70. CREATING A QUEUE TABLE AND QUEUE OF OBJECT TYPE 70 Oracle Advanced Queuing /* Creating a message type: */ CREATE type aq.Message_typ as object ( subject VARCHAR2(30), text VARCHAR2(80)); /* Creating a object type queue table and queue: */ BEGIN DBMS_AQADM.CREATE_QUEUE_TABLE ( queue_table => 'aq.objmsgs80_qtab', queue_payload_type => 'aq.Message_typ'); END; BEGIN DBMS_AQADM.CREATE_QUEUE ( queue_name => 'msg_queue', queue_table => 'aq.objmsgs80_qtab'); END; BEGIN DBMS_AQADM.START_QUEUE ( queue_name => 'msg_queue'); END;
  • 71. CREATING A QUEUE TABLE AND QUEUE OF RAW TYPE 71 Oracle Advanced Queuing /* Creating a RAW type queue table and queue: */ EXECUTE DBMS_AQADM.CREATE_QUEUE_TABLE ( queue_table => 'aq.RawMsgs_qtab', queue_payload_type => 'RAW'); EXECUTE DBMS_AQADM.CREATE_QUEUE ( queue_name => 'raw_msg_queue', queue_table => 'aq.RawMsgs_qtab'); EXECUTE DBMS_AQADM.START_QUEUE ( queue_name => 'raw_msg_queue');
  • 72. CREATING A PRIORITIZED MESSAGE QUEUE TABLE AND QUEUE 72 Oracle Advanced Queuing EXECUTE DBMS_AQADM.CREATE_QUEUE_TABLE ( queue_table => 'aq.priority_msg', sort_list => 'PRIORITY,ENQ_TIME', queue_payload_type => 'aq.Message_typ'); EXECUTE DBMS_AQADM.CREATE_QUEUE ( queue_name => 'priority_msg_queue', queue_table => 'aq.priority_msg'); EXECUTE DBMS_AQADM.START_QUEUE ( queue_name => 'priority_msg_queue');
  • 73. CREATING A MULTICONSUMER QUEUE TABLE AND QUEUE 73 Oracle Advanced Queuing EXECUTE DBMS_AQADM.CREATE_QUEUE_TABLE ( queue_table => 'aq.MultiConsumerMsgs_qtab', multiple_consumers => TRUE, queue_payload_type => 'aq.Message_typ'); EXECUTE DBMS_AQADM.CREATE_QUEUE ( queue_name => 'msg_queue_multiple', queue_table => 'aq.MultiConsumerMsgs_qtab'); EXECUTE DBMS_AQADM.START_QUEUE ( queue_name => 'msg_queue_multiple');
  • 74. CREATING A QUEUE TO DEMONSTRATE PROPAGATION 74 Oracle Advanced Queuing EXECUTE DBMS_AQADM.CREATE_QUEUE ( queue_name => 'another_msg_queue', queue_table => 'aq.MultiConsumerMsgs_qtab'); EXECUTE DBMS_AQADM.START_QUEUE ( queue_name => 'another_msg_queue');
  • 75. ENQUEUING OF OBJECT TYPE MESSAGES USING PL/SQL 75 Oracle Advanced Queuing To enqueue a single message without any other parameters specify the queue name and the payload. /* Enqueue to msg_queue: */ DECLARE enqueue_options dbms_aq.enqueue_options_t; message_properties dbms_aq.message_properties_t; message_handle RAW(16); message aq.message_typ; BEGIN message := message_typ('NORMAL MESSAGE', 'enqueued to msg_queue first.'); dbms_aq.enqueue(queue_name => 'msg_queue', enqueue_options => enqueue_options, message_properties => message_properties, payload => message, msgid => message_handle); COMMIT; END;
  • 76. DEQUEUING OF OBJECT TYPE MESSAGES USING PL/SQL 76 Oracle Advanced Queuing /* Dequeue from msg_queue: */ DECLARE dequeue_options dbms_aq.dequeue_options_t; message_properties dbms_aq.message_properties_t; message_handle RAW(16); message aq.message_typ; BEGIN DBMS_AQ.DEQUEUE(queue_name => 'msg_queue', dequeue_options => dequeue_options, message_properties => message_properties, payload => message, msgid => message_handle); DBMS_OUTPUT.PUT_LINE ('Message: ' || message.subject || ' ... ' || message.text ); COMMIT; END;
  • 77. ENQUEUING OF RAW TYPE MESSAGES USING PL/SQL 77 Oracle Advanced Queuing DECLARE enqueue_options dbms_aq.enqueue_options_t; message_properties dbms_aq.message_properties_t; message_handle RAW(16); message RAW(4096); BEGIN message := HEXTORAW(RPAD('FF',4095,'FF')); DBMS_AQ.ENQUEUE(queue_name => 'raw_msg_queue', enqueue_options => enqueue_options, message_properties => message_properties, payload => message, msgid => message_handle); COMMIT; END;
  • 78. DEQUEUING OF RAW TYPE MESSAGES USING PL/SQL 78 Oracle Advanced Queuing /* Dequeue from raw_msg_queue: */ DECLARE dequeue_options DBMS_AQ.dequeue_options_t; message_properties DBMS_AQ.message_properties_t; message_handle RAW(16); message RAW(4096); BEGIN DBMS_AQ.DEQUEUE(queue_name => 'raw_msg_queue', dequeue_options => dequeue_options, message_properties => message_properties, payload => message, msgid => message_handle); COMMIT; END;
  • 79. ENQUEUING OF MESSAGES BY PRIORITY USING PL/SQL 79 Oracle Advanced Queuing /* Enqueue two messages with priority 30 and 5: */ DECLARE enqueue_options dbms_aq.enqueue_options_t; message_properties dbms_aq.message_properties_t; message_handle RAW(16); message aq.message_typ; BEGIN message := message_typ('PRIORITY MESSAGE', 'enqued at priority 30.'); message_properties.priority := 30; DBMS_AQ.ENQUEUE(queue_name => 'priority_msg_queue', enqueue_options => enqueue_options, message_properties => message_properties, payload => message, msgid => message_handle); message := message_typ('PRIORITY MESSAGE', 'Enqueued at priority 5.'); message_properties.priority := 5; DBMS_AQ.ENQUEUE(queue_name => 'priority_msg_queue', enqueue_options => enqueue_options, message_properties => message_properties, payload => message, msgid => message_handle); END;
  • 80. DEQUEUING OF MESSAGES BY PRIORITY USING PL/SQL 80 Oracle Advanced Queuing /* Dequeue from priority queue: */ DECLARE dequeue_options DBMS_AQ.dequeue_options_t; message_properties DBMS_AQ.message_properties_t; message_handle RAW(16); message aq.message_typ; BEGIN DBMS_AQ.DEQUEUE(queue_name => 'priority_msg_queue', dequeue_options => dequeue_options, message_properties => message_properties, payload => message, msgid => message_handle); DBMS_OUTPUT.PUT_LINE ('Message: ' || message.subject || ' ... ' || message.text ); COMMIT; DBMS_AQ.DEQUEUE(queue_name => 'priority_msg_queue', dequeue_options => dequeue_options, message_properties => message_properties, payload => message, msgid => message_handle); DBMS_OUTPUT.PUT_LINE ('Message: ' || message.subject || ' ... ' || message.text ); COMMIT; END; /* On return, the second message with priority set to 5 will be retrieved before the message with priority set to 30 since priority takes precedence over enqueue time. */
  • 81. ENQUEUING OF MESSAGES WITH TIME DELAY AND EXPIRATION USING PL/SQL 81 Oracle Advanced Queuing /* Enqueue message for delayed availability: */ DECLARE enqueue_options dbms_aq.enqueue_options_t; message_properties dbms_aq.message_properties_t; message_handle RAW(16); message aq.Message_typ; BEGIN message := Message_typ('DELAYED', 'This message is delayed one week.'); message_properties.delay := 7*24*60*60; message_properties.expiration := 2*7*24*60*60; dbms_aq.enqueue(queue_name => 'msg_queue', enqueue_options => enqueue_options, message_properties => message_properties, payload => message, msgid => message_handle); COMMIT; END;
  • 82. ENQUEUING AND DEQUEUING OF MESSAGES TO/FROM A MULTICONSUMER QUEUE USING PL/SQL 82 Oracle Advanced Queuing /* Create subscriber list: */ DECLARE subscriber aq$_agent; /* Add subscribers RED and GREEN to the suscriber list: */ BEGIN subscriber := aq$_agent('RED', NULL, NULL); DBMS_AQADM.ADD_SUBSCRIBER(queue_name => 'msg_queue_multiple', subscriber => subscriber); subscriber := aq$_agent('GREEN', NULL, NULL); DBMS_AQADM.ADD_SUBSCRIBER(queue_name => 'msg_queue_multiple', subscriber => subscriber); END;
  • 83. ENQUEUING AND DEQUEUING OF MESSAGES TO/FROM A MULTICONSUMER QUEUE USING PL/SQL 83 Oracle Advanced Queuing DECLARE enqueue_options DBMS_AQ.enqueue_options_t; message_properties DBMS_AQ.message_properties_t; recipients DBMS_AQ.aq$_recipient_list_t; message_handle RAW(16); message aq.message_typ; /* Enqueue MESSAGE 1 for subscribers to the queue i.e. for RED and GREEN: */ BEGIN message := message_typ('MESSAGE 1', 'This message is queued for queue subscribers.'); DBMS_AQ.ENQUEUE(queue_name => 'msg_queue_multiple', enqueue_options => enqueue_options, message_properties => message_properties, payload => message, msgid => message_handle); /* Enqueue MESSAGE 2 for specified recipients i.e. for RED and BLUE.*/ message := message_typ('MESSAGE 2', 'This message is queued for two recipients.'); recipients(1) := aq$_agent('RED', NULL, NULL); recipients(2) := aq$_agent('BLUE', NULL, NULL); message_properties.recipient_list := recipients; DBMS_AQ.ENQUEUE(queue_name => 'msg_queue_multiple', enqueue_options => enqueue_options, message_properties => message_properties, payload => message, msgid => message_handle); COMMIT; END; Note that RED is both a subscriber to the queue, as well as being a specified recipient of MESSAGE 2. By contrast, GREEN is only a subscriber to those messages in the queue (in this case, MESSAGE) for which no recipients have been specified. BLUE, while not a subscriber to the queue, is nevertheless specified to receive MESSAGE 2.
  • 84. ENQUEUING AND DEQUEUING OF MESSAGES TO/FROM A MULTICONSUMER QUEUE USING PL/SQL 84 Oracle Advanced Queuing /* Dequeue messages from msg_queue_multiple: */ DECLARE dequeue_options DBMS_AQ.dequeue_options_t; message_properties DBMS_AQ.message_properties_t; message_handle RAW(16); message aq.message_typ; no_messages exception; pragma exception_init (no_messages, -25228); BEGIN dequeue_options.wait := DBMS_AQ.NO_WAIT; BEGIN /* Consumer BLUE will get MESSAGE 2: */ dequeue_options.consumer_name := 'BLUE'; dequeue_options.navigation := FIRST_MESSAGE; LOOP DBMS_AQ.DEQUEUE(queue_name => 'msg_queue_multiple', dequeue_options => dequeue_options, message_properties => message_properties, payload => message, msgid => message_handle); DBMS_OUTPUT.PUT_LINE ('Message: ' || message.subject || ' ... ' || message.text ); dequeue_options.navigation := NEXT_MESSAGE; END LOOP; EXCEPTION WHEN no_messages THEN DBMS_OUTPUT.PUT_LINE ('No more messages for BLUE'); COMMIT; END;
  • 85. ENQUEUING AND DEQUEUING OF MESSAGES TO/FROM A MULTICONSUMER QUEUE USING PL/SQL 85 Oracle Advanced Queuing BEGIN /* Consumer RED will get MESSAGE 1 and MESSAGE 2: */ dequeue_options.consumer_name := 'RED'; dequeue_options.navigation := DBMS_AQ.FIRST_MESSAGE; LOOP DBMS_AQ.DEQUEUE(queue_name => 'msg_queue_multiple', dequeue_options => dequeue_options, message_properties => message_properties, payload => message, msgid => message_handle); DBMS_OUTPUT.PUT_LINE ('Message: ' || message.subject || ' ... ' || message.text ); dequeue_options.navigation := NEXT_MESSAGE; END LOOP; EXCEPTION WHEN no_messages THEN DBMS_OUTPUT.PUT_LINE ('No more messages for RED'); COMMIT; END;
  • 86. ENQUEUING AND DEQUEUING OF MESSAGES TO/FROM A MULTICONSUMER QUEUE USING PL/SQL 86 Oracle Advanced Queuing BEGIN /* Consumer GREEN will get MESSAGE 1: */ dequeue_options.consumer_name := 'GREEN'; dequeue_options.navigation := FIRST_MESSAGE; LOOP DBMS_AQ.DEQUEUE(queue_name => 'msg_queue_multiple', dequeue_options => dequeue_options, message_properties => message_properties, payload => message, msgid => message_handle); DBMS_OUTPUT.PUT_LINE ('Message: ' || message.subject || ' ... ' || message.text ); dequeue_options.navigation := NEXT_MESSAGE; END LOOP; EXCEPTION WHEN no_messages THEN DBMS_OUTPUT.PUT_LINE ('No more messages for GREEN'); COMMIT; END;
  • 87. MANAGING PROPAGATION FROM ONE QUEUE TO OTHER QUEUES IN THE SAME DATABASE USING PL/SQL 87 Oracle Advanced Queuing /* Schedule propagation from queue q1def to other queues in the same database */ EXECUTE DBMS_AQADM.SCHEDULE_PROPAGATION(queue_name => 'q1def'); /* Disable propagation from queue q1def to other queues in the same database */ EXECUTE DBMS_AQADM.DISABLE_PROPAGATION_SCHEDULE( queue_name => 'q1def'); /* Alter schedule from queue q1def to other queues in the same database */ EXECUTE DBMS_AQADM.ALTER_PROPAGATION_SCHEDULE( queue_name => 'q1def', duration => '2000', next_time => 'SYSDATE + 3600/86400', latency => '32'); /* Enable propagation from queue q1def to other queues in the same database */ EXECUTE DBMS_AQADM.ENABLE_PROPAGATION_SCHEDULE( queue_name => 'q1def'); /* Unschedule propagation from queue q1def to other queues in the same database */ EXECUTE DBMS_AQADM.UNSCHEDULE_PROPAGATION( queue_name => 'q1def');
  • 88. MANAGE PROPAGATION FROM ONE QUEUE TO OTHER QUEUES IN ANOTHER DATABASE USING PL/SQL 88 Oracle Advanced Queuing /* Schedule propagation from queue q1def to other queues in another database reached by the database link another_db.world */ EXECUTE DBMS_AQADM.SCHEDULE_PROPAGATION( queue_name => 'q1def', destination => 'another_db.world'); /* Disable propagation from queue q1def to other queues in another database reached by the database link another_db.world */ EXECUTE DBMS_AQADM.DISABLE_PROPAGATION_SCHEDULE( queue_name => 'q1def', destination => 'another_db.world'); /* Alter schedule from queue q1def to other queues in another database reached by the database link another_db.world */ EXECUTE DBMS_AQADM.ALTER_PROPAGATION_SCHEDULE( queue_name => 'q1def', destination => 'another_db.world', duration => '2000', next_time => 'SYSDATE + 3600/86400', latency => '32'); /* Enable propagation from queue q1def to other queues in another database reached by the database link another_db.world */ EXECUTE DBMS_AQADM.ENABLE_PROPAGATION_SCHEDULE( queue_name => 'q1def', destination => 'another_db.world'); /* Unschedule propagation from queue q1def to other queues in another database reached by the database link another_db.world */ EXECUTE DBMS_AQADM.UNSCHEDULE_PROPAGATION( queue_name => 'q1def', destination => 'another_db.world');
  • 89. UNSCHEDULING PROPAGATION USING PL/SQL 89 Oracle Advanced Queuing /* Unschedule propagation from msg_queue_multiple to the destination another_ db.world */ EXECUTE DBMS_AQADM.UNSCHEDULE_PROPAGATION( queue_name => 'msg_queue_multiple', destination => 'another_db.world');
  • 90. DROPPING AQ OBJECTS 90 Oracle Advanced Queuing /* Cleans up all objects related to the object type: */ CONNECT aq/aq EXECUTE DBMS_AQADM.STOP_QUEUE ( queue_name => 'msg_queue'); EXECUTE DBMS_AQADM.DROP_QUEUE ( queue_name => 'msg_queue'); EXECUTE DBMS_AQADM.DROP_QUEUE_TABLE ( queue_table => 'aq.objmsgs80_qtab'); /* Cleans up all objects related to the RAW type: */ EXECUTE DBMS_AQADM.STOP_QUEUE ( queue_name => 'raw_msg_queue'); EXECUTE DBMS_AQADM.DROP_QUEUE ( queue_name => 'raw_msg_queue'); EXECUTE DBMS_AQADM.DROP_QUEUE_TABLE ( queue_table => 'aq.RawMsgs_qtab');
  • 91. DROPPING AQ OBJECTS 91 Oracle Advanced Queuing /* Cleans up all objects related to the priority queue: */ EXECUTE DBMS_AQADM.STOP_QUEUE ( queue_name => 'priority_msg_queue'); EXECUTE DBMS_AQADM.DROP_QUEUE ( queue_name => 'priority_msg_queue'); EXECUTE DBMS_AQADM.DROP_QUEUE_TABLE ( queue_table => 'aq.priority_msg'); /* Cleans up all objects related to the multiple-consumer queue: */ EXECUTE DBMS_AQADM.STOP_QUEUE ( queue_name => 'msg_queue_multiple'); EXECUTE DBMS_AQADM.DROP_QUEUE ( queue_name => 'msg_queue_multiple'); EXECUTE DBMS_AQADM.DROP_QUEUE_TABLE ( queue_table => 'aq.MultiConsumerMsgs_qtab'); DROP TYPE aq.message_typ;
  • 92. REVOKING ROLES AND PRIVILEGES 92 Oracle Advanced Queuing CONNECT sys/change_on_install DROP USER aq;
  • 93. CONTACTS 93 Sopra Steria AMSL Building No 4, Plot No - 20&21,Sector - 135, Dist- Gautam Buddha Nagar,Noida (UP)-201304 www.soprasteria.co.uk Er Gurpreet Singh Junior Software Engineer CUG. 2142 M. +91-9803723925 Gurpreet.singh2@soprasteria.com Oracle Advanced Queuing