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





AQ Programmatic Environments


Previous Chapter | Next Chapter

AQ Programmatic Environments

This chapter describes the elements you need to work with and issues you will want to take into consideration in preparing your AQ application environment. The following topics are discussed:

* Programmatic Environments for Accessing AQ

* Using PL/SQL to Access AQ

* Using OCI to Access AQ

* Using Visual Basic (OO4O) to Access AQ

* Using AQ Java (oracle.AQ) Classes to Access AQ

* Using Oracle Java Messaging Service to Access AQ

* Using the AQ XML Servlet to Access AQ

Programmatic Environments for Accessing AQ

The following programmatic environments are used to access the Advanced Queuing functions of Oracle:

* Native AQ Interface

   1. PL/SQL (DBMS_AQADM and DBMS_AQ packages): supports administrative and operational functions

   2. C (OCI): supports operational functions

   3. Visual Basic (OO4O): supports operational functions

   4. Java (oracle.AQ package using JDBC): supports administrative and operational functions

* JMS Interface to AQ

   * Java (javax.jms and oracle.jms packages using JDBC): supports the standard JMS administrative and operational functions and Oracle JMS Extensions

* XML Interface to AQ

   * The AQ XML servlet supports operational functions using an XML message format.

Using PL/SQL to Access AQ

PL/SQL packages, DBMS_AQADM and DBMS_AQ support access to Oracle Advanced Queuing administrative and operational functions using the native AQ interface. These functions include the following:

* Create: queue, queue table, nonpersistent queue, multi-consumer queue/topic, RAW message, message with structured data

* Get: queue table, queue, multi-consumer 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 multi-consumer queue/topic (publish-subscribe model)

* Subscribing for messages in multi-consumer 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

Using OCI to Access AQ

Oracle Call Interface (OCI) provides an interface to Oracle Advanced Queuing functions using the native AQ interface.

An OCI client can perform the following actions:

* Enqueue messages

* Dequeue messages

* Listen for messages on sets of queues

* Register to receive message notifications

In addition, OCI clients can receive asynchronous notifications for new messages in a queue using OCISubscriptionRegister.

Using Visual Basic (OO4O) to Access AQ

Visual Basic (OO4O) supports access to Oracle Advanced Queuing operational functions using the native AQ interface.

These functions include the following:

* Create: connection, RAW message, message with structured data

* Enqueue messages to single consumer queue (point-to-point model)

* Publish messages to multi-consumer queue/topic (publish-subscribe model)

* Browse messages in a queue

* Receive messages from queue/topic

* Register to received messages asynchronously

Using AQ Java (oracle.AQ) Classes to Access AQ

Java AQ API supports both the administrative and operational features of Oracle AQ (Advanced Queueing). In developing Java programs for messaging applications, you will use JDBC to open a connection to the database and then the oracle.AQ, the Java AQ API for message queuing. This means that you will no longer need to use PL/SQL interfaces.

Accessing Java AQ Classes

The Java AQ classes are located in $ORACLE_HOME/rdbms/jlib/aqapi.jar. These classes can be used with any Oracle8i JDBC driver.

* Using OCI8 or Thin JDBC Driver: If your application uses the OCI8 or thin JDBC driver:

o For JDK 1.2 you must include $ORACLE_HOME/rdbms/jlib/aqapi.jar in the CLASSPATH

o For JDK 1.1 you must include $ORACLE_HOME/rdbms/jlib/aqapi11.jar in the CLASSPATH.

* Using Oracle Server Driver in JServer: If the application is using the Oracle Server driver and accessing the java AQ API from java stored procedures, the Java files are generally automatically pre-loaded in a Java-enabled database. If the Java files are not loaded, you must first load the jmscommon.jar and aqapi.jar files into the database using the "loadjava" utility.

Advanced Queuing Examples

Appendix A, "Oracle Advanced Queuing by Example" contains the following examples:

* Enqueue and Dequeue of Object Type Messages (CustomDatum interface) Using Java

* Enqueue and Dequeue of Object Type Messages (using SQLData interface) Using Java

* Create a Queue Table and Queue Using Java

* Create a Queue and Start Enqueue/Dequeue Using Java

* Create a Multi-Consumer Queue and Add Subscribers Using Java

* Enqueue of RAW Messages using Java

* Dequeue of Messages Using Java

* Dequeue of Messages in Browse Mode Using Java

* Enqueue of Messages with Priority Using Java

* Enqueuing and Dequeuing Object Type Messages That Contain LOB Attributes Using Java

Managing the Java AQ API The various implementations of the Java AQ API are managed via an AQDriverManager. Both OLite and Oracle9i will have an AQDriver that is registered with the AQDriverManager. The driver manager is used to create an AQSession that can be used to perform messaging tasks.

The Oracle8i AQ driver is registered using the Class.forName ("oracle.AQ.AQOracleDriver") command.

When the AQDriverManager.createAQSession() method is invoked, it calls the appropriate AQDriver (amongst the registered drivers) depending on the parameter passed to the createAQSession() call.

The Oracle9i AQDriver expects a valid JDBC connection to be passed in as a parameter to create an AQSession. Users must have the execute privilege on the DBMS_AQIN package to use the AQ Java interfaces. Users can also acquire these rights through the AQ_USER_ROLE or the AQ_ADMINSTRATOR_ROLE. Users will also need the appropriate system and queue privileges for 8.1-style queue tables.

Using Oracle Java Messaging Service to Access AQ

Java Messaging Service (JMS): JMS is a messaging standard defined by Sun Microsystems, Oracle, IBM, and other vendors. JMS is a set of interfaces and associated semantics that define how a JMS client accesses the facilities of an enterprise messaging product.

Oracle Java Messaging Service: Oracle Java Messaging Service provides a Java API for Oracle Advanced Queuing based on the JMS standard. Oracle JMS supports the standard JMS interfaces and has extensions to support the AQ administrative operations and other AQ features that are not a part of the standard.

Standard JMS Features

Standard JMS features include:

* Point-to-point model of communication - using queues

* Publish-subscribe model of communication - using topics

* Five types of messages - ObjectMessage, StreamMessage, TextMessage, BytesMessage, MapMessage

* Synchronous and Asynchronous delivery of messages

* Message selection based on message header fields/properties

Oracle JMS Extensions

Oracle JMS extensions include the following:

* Administrative API - to create queue tables, queues and topics

* Point-to-multipoint communication - using recipient lists for topics

* Message propagation between destinations. Allows the application to define remote subscribers.

* Supports transacted sessions that enable you to perform JMS as well as SQL operations in one atomic transaction.

* Message retention after messages have been dequeued

* Message delay - messages can be made visible after a certain delay

* Exception handling - messages are moved to exception queues if they cannot be processed successfully

* In addition to the standard JMS message types, Oracle supports AdtMessages. These are stored in the database as Oracle objects and hence the payload of the message can be queried after it is enqueued. Subscriptions can be defined on the contents of these messages as opposed to just the message properties.

* Topic browsing - allows durable subscribers to browse through the messages in a publish-subscribe (topic) destination, and optionally allows these subscribers to purge the browsed messages (so that they are no longer retained by AQ for that subscriber).

Accessing Standard and Oracle JMS

Oracle JMS uses JDBC to connect to the database, hence it applications can run as follows:

* Outside the database using the OCI8 or thin JDBC driver

* Inside Oracle8i JServer using the Oracle Server driver

The standard JMS interfaces are in the javax.jms package.

The Oracle JMS interfaces are in the oracle.jms package.

* Using OCI8 or Thin JDBC Driver: To use JMS with clients running outside the database, you must include the appropriate JDBC driver, JNDI jar files and the following AQ jar files in your CLASSPATH:

o For JDK 1.1 include the following:

$ORACLE_HOME/rdbms/jlib/jmscommon.jar

$ORACLE_HOME/rdbms/jlib/aqapi11.jar

$ORACLE_HOME/jlib/jndi.jar

$ORACLE_HOME/jdbc/lib/classes111.jar

o For JDK 1.2 include the following:

$ORACLE_HOME/rdbms/jlib/jmscommon.jar

$ORACLE_HOME/rdbms/jlib/aqapi.jar

$ORACLE_HOME/jlib/jndi.jar

$ORACLE_HOME/jdbc/lib/classes12.jar

* Using Oracle Server Driver in JServer: If your application is running inside the JServer, you should be able to access the Oracle JMS classes that have been automatically loaded when the JServer was installed. If these classes are not available, you may have to load jmscommon.jar followed by aqapi.jar using the loadjava utility.

Privileges

Users must have EXECUTE privilege on DBMS_AQIN and DBMS_AQJMS packages in order to use the Oracle JMS interfaces. Users can also acquire these rights through the AQ_USER_ROLE or the AQ_ADMINSTRATOR_ROLE.

Users will also need the appropriate system and queue or topic privileges to send or receive messages.

Using the AQ XML Servlet to Access AQ

You can use the AQ XML servlet to access Oracle9i AQ using open protocols like HTTP and SMTP and using an XML message format called Internet Data Access Presentation (IDAP).

Using the AQ servlet, a client can perform the following actions:

* Send messages to single-consumer queues

* Publish messages to multi-consumer queues/topics

* Receive messages from queues

* Register to receive message notifications

The servlet can be created by defining a Java class that extends the oracle.AQ.xml.AQxmlServlet or oracle.AQ.xml.AQxmlServlet20 class. These classes in turn extend the javax.servlet.http.HttpServlet class.

The servlet can be deployed on any Web server or ServletRunner that implements Javasoft's Servlet 2.0 or Servlet 2.2 interfaces.

* To deploy the AQ Servlet with a Web server that implements Javasoft's Servlet2.0 interfaces, you must define a class that extends the oracle.AQ.xml.AQxmlServle20 class.

* To deploy the AQ Servlet with a Web server that implements Javasoft's Servlet2.2 interfaces, you must define a class that extends the oracle.AQ.xml.AQxmlServlet class.

The servlet can be compiled using JDK 1.1.x or JDK 1.2.x libraries.

* For JDK 1.1.x the CLASSPATH must contain:

$ORACLE_HOME/jdbc/lib/classes111.jar
$ORACLE_HOME/jlib/jta.jar
$ORACLE_HOME/jdbc/lib/nls_charset11.jar
$ORACLE_HOME/jlib/jndi.jar
$ORACLE_HOME/lib/lclasses11.zip
$ORACLE_HOME/lib/xmlparserv2.jar
$ORACLE_HOME/lib/xschema.jar
$ORACLE HOME/rdbms/jlib/aqapi11.jar
$ORACLE_HOME/rdbms/jlib/jmscommon.jar
$ORACLE_HOME/rdbms/jlib/aqxml.jar
$ORACLE_HOME/rdbms/jlib/xsu111.jar
$ORACLE_HOME/lib/servlet.jar

* For JDK 1.2.x the CLASSPATH must contain:

$ORACLE_HOME/jdbc/lib/classes12.jar
$ORACLE_HOME/jlib/jta.jar
$ORACLE_HOME/jdbc/lib/nls_charset12.jar
$ORACLE_HOME/jlib/jndi.jar
$ORACLE_HOME/lib/lclasses12.zip
$ORACLE_HOME/lib/xmlparserv2.jar
$ORACLE_HOME/lib/xschema.jar
$ORACLE_HOME/rdbms/jlib/aqapi.jar
$ORACLE_HOME/rdbms/jlib/jmscommon.jar
$ORACLE_HOME/rdbms/jlib/aqxml.jar
$ORACLE_HOME/rdbms/jlib/xsu12.jar
$ORACLE_HOME/lib/servlet.jar

Since the servlet uses JDBC OCI drivers to connect to the Oracle9i database server, the 9i Oracle Client libraries must be installed on the machine that hosts the servlet. The LD_LIBRARY_PATH must contain $ORACLE_HOME/lib.

Previous Chapter | Next Chapter

More Articles

1. What Is Advanced Queuing?
2. General Features of Advanced Queuing
3. Enqueue, Dequeue, Propagation Features of Advanced Queuing
4. Elements of Advanced Queuing
5. Basic Components of Advanced Queuing

More Tutorials on Oracle dba ...

Source :Oracle Documentation

Liked it ? Want to share it ? Social Bookmarking

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




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