MESSAGE QUEUING :-
Message queuing infrastructure enables information sharing and
integration amongst different, possibly distributed, applications. Producer
applications send or enqueue messages into queue from which consumer
applications receive or dequeue messages. Producers and Consumers interact with
the queue asynchronously and this decoupling‟ is the centre piece of message
queuing.
A message stays in the queue until a consumer dequeues it or the
message expires. A producer may stipulate a delay before the message is
available to be consumed and a time after which the message expires. Likewise a
consumer waits when trying to dequeue a message if no message is available. An
agent program or application may act as both a producer and a consumer.
The propagation of messages is like the producers enqueue the
messages into the message queue and the subscribed consumers dequeues them,
both the enqueue and dequeue processes can go on side by side at the same time
they can also be one at the time, i.e., when the producers stops finishing the
enqueuing the messages he sends a message to all the subscribed consumers
stating that they can now dequeue the messages, this type of operation is
usually done when the application needs to be processed one at a time.
Though both enqueue and dequeue operations can go on simultaneously.
Messages which are there in the queue for more than the time allotted to them
for the dequeuing operation are automatically expired and they are no longer
available for the dequeue operation.
ORACLE STREAMS ADVANCED
QUEUING :-
Oracle Streams Advanced Queuing provides database-integrated
message queuing functionality. It is built on top of oracle streams and
leverages the functions of Oracle Database so that messages can be stored
persistently, propagated between queues on different computers and databases,
and transmitted using Oracle Net Services and HTTP(S). Because Oracle Streams
Advanced Queuing is implemented in database tables, all operational benefits of
high availability, scalability, and reliability are also applicable to queue
data. Messages are queued using standard SQL. This means that you can use the
SQL to access the messages properties, the message history and the payload. It
can be possible that there are more than one producer and/or more than one
consumer, if this is the case than according to the priority set in thedequeue
table the consumers are able to dequeue the message though producers can
enqueue at anytime.
Enqueued messages are said to be propagated when they are
reproduced on another queue, which can be in the same database or in a remote
database.
An application A enqueues a request into the request queue. In a
different transaction, the application A dequeues and processes the request.
Application A enqueue the result in the response queue, and in yet another
transaction, Application A dequeues it.
A message producer can submit a list of recipients at the time a
message is enqueued. This allows for a unique set of recipients for each
message in the queue. The recipient list associates with the message overrides
the subscriber list associated with the queue, if there is one. The recipients
need not be in the subscriber list. However, recipients can be selected from
among the subscribers.
AQ COMPONENTS
The four main components of AQ are:-
1. Message – A message
consists of message content, or payload, which can be specified using typed or
raw data and message attributes or control information.
2. Message Queue –
Messages are stored in queues and these queues act as “postal boxes” where different
applications can look for “mail” in the form of the messages. Thus when one application
wants to contact certain applications for certain tasks, it can leave messages
in these queues, and the receiving applications will be able to find these
massages for processing.AQ supports enqueue, dequeue and propagation operations
where the queue type is an abstract datatype. A queue is persisted in the
database using one or more database tables where messages in a queue correspond
to rows in the underlying table.
3. Message Interface –
AQ can seamlessly with the existing applications through support for popular
standards. AQ messages can be created, queried, propagated and consumed using popular
programming interfaces (API) such as PL/SQL, C/C++, Java and Visual Basic. AQ provides
support for the Java Message Service(JMS) API that allows Java applications to utilize
the message queuing functionality.
4. Message handling –
Messages can be routed according to the data in the message payload or attributes.
AQ also support rules based message routing where complex rules can be created
by combining payload based and attributes-based rules. Additionally
message-transformation can be applied to messages to reformat data and
delivered automatically to target applications or subscribers.
BASIC FUNCTIONALITY OF AQ
The two major roles
that are provided for performing AQ administration and user operations:
a) AQ_ADMINISTRATOR_ROLE
: This role allows for the creation and administration of the queuing infrastructure.
b) AQ_USER_ROLE : This
role allows users to access queues for enqueue and dequeue operations.
1) Connect to user
Demo/Demo as sysdba as follows.
2) Create user
aq_admin.
3) Give grant
permission role of aq_administrator_role, connect, create type, create sequence
to aq_admin.
4) Execute grant type access
permission to “aq_admin”.
5) Just like “aq_admin”,
create “aq_user” and give permission of aq_user_role and
connect to “aq_user”.
6) Define Payload
a) The
content, or payload, of a message is often defined using an OBJECT TYPE.
b) We
must define this before creating the queue.
c) We
also grant EXECUTE on the payload object type to our AQ user.
7) Now, connect to
aq_admin/aq_admin.
8) Now,
In the “aq_admin” environment, Create “Type” and “Sequence” & give
“Execute” permission to “aq_user”.
9) Create Queue Table and
Queue :-
a) Now
that we have the payload created, it is time to create the queuing infrastructure.
b) Queues
are implemented using a queue table which can hold multiple queues with the
same payload type.
c) First
the queue table must be defined using the payload type, then the queue can be
defined and started.
d) All
of these operations can be performed using the DBMS_AQADM package as follows:
Example:-
CONNECT
aq_admin_plsql/aq_admin_plsql ("Connect to admin user")
SET SERVEROUTPUT ON
("SQL*Plus command, and it is issued to print the server message in
client.")
BEGIN ("Start
Command in PL/SQL")
--
---------------------------------------------------------
DBMS_AQADM.CREATE_QUEUE_TABLE
(
("Creation of Queue Table in AQ")
queue_table =>
'aq_admin.msg_qt'
, queue_payload_type => 'aq_admin.message_type'
);
--
-------------------------------------------------------
DBMS_AQADM.CREATE_QUEUE
(
("Creation of Queue in AQ")
queue_name =>
'msg_queue'
, queue_table =>
'aq_admin.msg_qt'
, queue_type => DBMS_AQADM.NORMAL_QUEUE
, max_retries => 0
, retry_delay => 0
, retention_time => 1209600
, dependency_tracking => FALSE
,
comment
=> 'Test Object Type Queue'
, auto_commit => FALSE
);
--
-------------------------------------------------------
DBMS_AQADM.START_QUEUE('msg_queue');
("Starting the
queue")
--
-------------------------------------------------------
DBMS_AQADM.GRANT_QUEUE_PRIVILEGE
(
("Giving grant permission to
queue")
privilege => 'ALL'
, queue_name =>
'aq_admin.msg_queue'
, grantee =>
'aq_user'
, grant_option => FALSE
);
--
-------------------------------------------------------
END; ("End Command
in PL/SQL")
/
From Above Statement.Both Queue Table and Queue are created.
(Note : Enqueuing and Dequeuing works on
“aq_user” environment)
10) Enqueue Message use the DBMS_AQ.ENQUEUE procedure to write
messages to the queue as follows:-
a) First Connect to the
“aq_user” .
b) Execute
enqueuer command.
11) Dequeue Message use the DBMS_AQ.DEQUEUE procedure to read
messages from the queue.
12) And get the output.
“It is a simple illustration of
AQ working.”
No comments:
Post a Comment