|Oracle9iAS Containers for J2EE Services Guide
Release 2 (9.0.3)
Part Number A97690-01
This chapter describes the Java Message Service (JMS) furnished as part of Oracle9iAS Containers for J2EE (OC4J). This chapter discusses the following topics:
Java clients and Java middle-tier services must be capable of using enterprise messaging systems. JMS offers a common way for Java programs to access these systems. JMS is the standard messaging API for passing data asynchronously between application components, allowing business integration in heterogeneous and legacy environments. JMS provides two programming models:
JMS queues and topics are bound to the JNDI environment and made available to J2EE applications.
OC4J provides a
ResourceProvider interface to transparently plug in third-party JMS implementations. The JMS resources are available under
java:comp/resource through the resource provider interface delegation.
ResourceProvider interface enables you to plug in third-party message providers for JMS connections. For Oracle JMS, this allows EJBs, servlets, and OC4J clients to access many different queue implementations. With third-party message providers, only EJBS can access queue implementations. The resources are available under
java:comp/resource/ as the default JMS resources.
To add a custom
<resource-provider>, add the following to your
<resource-provider class="providerClassName" name="JNDI name"> <description> description </description> <property name="name" value="value" /> </resource-provider>
In place of the user-replaceable constructs (those in italics) in the preceding code, do the following:
classattribute with the name of the resource-provider class.
nameattribute with a name by which to identify the resource provider. This name will be used in finding the resource provider in the application's JNDI as
descriptiontag with a description of the specific resource provider.
propertytags that the specific resource provider needs to be given as parameters.
Use the following lookup syntax to retrieve a resource provider's resources:
Where providerName is the name of the resource provider (as given in the attribute
name described in the previous section) and resourceName is the name of a resource this resource provider furnishes.
ResourceProvider interface allows you to plug in Oracle JMS, which enables J2EE code (EJBs, MDBs, JSPs, servlets, application clients, and so on) to access Oracle AQ.
To access Oracle JMS queues through JMS, you must do the following:
Identify the JNDI name of the data source to use as the resource provider within the
orion-application.xmlfile of the application.
The following is an example of how to configure the resource provider using XML syntax for Oracle JMS.
oracle.jms.OjmsContextclass, which is configured in the
classattribute, implements the Oracle JMS resource provider.
propertyattribute--Identify the data source that is to be used as this resource provider in the
propertyelement. The topic or queue connects to this data source to access the tables and queues that facilitate the messaging.
For details on configuring data sources, see "Defining Data Sources".
The OC4J message-driven beans (MDB: EJBs that process JMS messages asynchronously) are integrated only with Oracle JMS, through the resource provider interface. MDBs are not integrated with third-party message providers.
An MDB is a JMS message listener that can reliably consume messages from a queue or a subscription of a topic. The advantage of using an MDB instead of a JMS message listener is that you can use the asynchronous nature of a JMS listener with the following EJB container advantages:
TopicSubscriberand its factory at deployment time.
Refer to the MDB chapter for details on deploying an MDB accessing Oracle JMS through the resource provider interface.
This section discusses the following third-party resource providers:
Here are the operations that the resource provider interface supports:
The context scanning resource provider class is a generic resource provider class that is shipped with OCJ for use with third-party message providers.
The Resource Provider interface provides support for plugging in third-party JMS implementations. This example demonstrates how to make MQSeries the default Resource Provider for JMS connections. The MQSeries resources are available in OC4J under
orion-application.xmlto add MQSeries as a custom Resource Provider. Here is an example of using this tag for SonicMQ integration:
<resource-provider class="com.evermind.server.deployment.ContextScanningResourceProvider" name="MQSeries"> <description> MQSeries resource provider </description> <property name="java.naming.factory.initial" value="com.sun.jndi.fscontext.RefFSContextFactory"> </property> <property name="java.naming.provider.url" value="file:/var/mqm/JNDI-Directory"> </property> </resource-provider>
SonicMQ is a messaging broker with a complete implementation of the JMS 1.0.2 specification. The resource provider interface furnishes support for plugging in third-party JMS implementations. This example describes how to make SonicMQ the default resource provider for JMS connections. The SonicMQ resources are available in OC4J under
SonicMQ broker does not embed a JNDI service. Instead, it relies on an external directory server to register the administered objects. Administered objects, such as queues, are either created by an administrator--using SonicMQ Explorer or programmatically--using the Sonic Management API. Oracle registers the administered objects from SonicMQ Explorer using the file system JNDI.
orion-application.xmlto add SonicMQ as a custom resource provider. The following example demonstrates using SonicMQ as the message provider and the file system as the JNDI store:
<resource-provider class="com.evermind.server.deloyment.ContextScanningResourceProvider" name="SonicJMS"> <description> SonicJMS resource provider. </description> <property name="java.naming.factory.initial" value="com.sun.jndi.fscontext.RefFSContextFactory"> <property name="java.naming.provider.url" value="file:/private/jndi-directory/"> </resource-provider>
SwiftMQ is a messaging broker with a complete implementation of the JMS 1.0.1 specification. The Resource Provider interface furnishes support for plugging in third-party JMS implementations. This example describes how to make SwiftMQ the default ResourceProvider for JMS connections. The SwiftMQ resources are available in OC4J under
orion-application.xmlto add SwiftMQ as a custom resource provider, as shown in the following:
<resource-provider class="com.evermind.server.deloyment.ContextScanningResourceProvider" name="SwiftMQ"> <description> SwiftMQ resource provider. </description> <property name="java.naming.factory.initial" value="com.swiftmq.jndi.InitialContextFactoryImpl"> <property name="java.naming.provider.url" value="smqp://localhost:4001"> </resource-provider>