|
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g Release 3 (10.1.3) B14428-01 |
|
![]() Previous |
![]() Next |
To configure the OJMS message service provider, you must:
Install and configure the OJMS provider (see "Installing and Configuring the OJMS Provider").
Choose appropriate JNDI names for your destination and connection factory (see "OracleAS JMS Destination and Connection Factory Names").
Configure the data-sources.xml file to identify your database (see "Configuring data-sources.xml").
Optionally, map the actual JNDI names to logical names (see "Configuring an Environment Reference to a JMS Destination or Connection Resource Manager Connection Factory").
Associate the OJMS message service provider with the message-driven beans that will use it.
For more information, see:
For more information, see "Oracle JMS (OJMS) Provider: Advanced Queueing (AQ)-Based".
The actual JNDI names for the JMS destination and connection factory depend on your OJMS installation as shown in Table 23-2.
Table 23-2 OJMS Destination and Connection Factory Names
| Type | Form |
|---|---|
|
Queue |
|
|
Queue Connection Factory |
|
|
Topic |
|
|
Topic Connection Factory |
|
The values for the variables in Table 23-2 are defined as follows:
<ProviderName>: the JNDI name of the data source that is providing OJMS service (see "Identify the JNDI Name of the Oracle AQ JMS Data Source")
<QName>: the name of the queue you created in the database (see step 3 b in "Installing and Configuring the OJMS Provider").
<QCFName>: the name of the queue connection factory. You may specify any arbitrary name.
<TName>: the name of the topic you created in the database (see step 3 b in "Installing and Configuring the OJMS Provider").
<TCFName>: the name of the topic connection factory. You may specify any arbitrary name.
|
Note: The following sections use SQL for creating queues, topics, their tables, and assigning privileges that is provided within the MDB demo on the OC4J sample code page athttp://www.oracle.com/technology/tech/java/oc4j/demos.
|
You or your DBA must install Oracle AQ according to the Oracle Streams Advanced Queuing User's Guide and Reference. and generic database manuals.
You or your DBA should create an RDBMS user through which the MDB connects to the database and grant this user appropriate access privileges to perform OJMS operations.
The privileges that you need depend on what functionality you are requesting. Refer to the Oracle Streams Advanced Queuing User's Guide and Reference. for more information on privileges necessary for each type of function.
The following example creates jmsuser, which must be created within its own schema, with privileges required for Oracle AQ operations. You must be a SYS DBA to execute these statements.
DROP USER jmsuser CASCADE ; GRANT connect, resource,AQ_ADMINISTRATOR_ROLE TO jmsuser IDENTIFIED BY jmsuser ; GRANT execute ON sys.dbms_aqadm TO jmsuser; GRANT execute ON sys.dbms_aq TO jmsuser; GRANT execute ON sys.dbms_aqin TO jmsuser; GRANT execute ON sys.dbms_aqjms TO jmsuser; connect jmsuser/jmsuser;
You may need to grant other privileges, such as two-phase commit or system administration privileges, based on what the user needs. See the JTA chapter in the Oracle Containers for J2EE Services Guide for the two-phase commit privileges.
You or your DBA should create the tables and queues to support the JMS Destination objects.
Refer to the Oracle Streams Advanced Queuing User's Guide and Reference. for more information on the DBMS_AQADM packages and Oracle AQ messages types.
Create the tables that handle the JMS Destination (queue or topic).
In OJMS, both topics and queues use a queue table. The rpTestMdb JMS example creates a single table: rpTestQTab for a queue.
To create the queue table, execute the following SQL:
DBMS_AQADM.CREATE_QUEUE_TABLE(
Queue_table => 'rpTestQTab',
Queue_payload_type => 'SYS.AQ$_JMS_MESSAGE',
sort_list => 'PRIORITY,ENQ_TIME',
multiple_consumers => false,
compatible => '8.1.5');
The multiple_consumers parameter denotes whether there are multiple consumers or not; thus, is always false for a queue and true for a topic.
Create the JMS Destination. If you are creating a topic, you must add each subscriber for the topic. The rpTestMdb JMS example requires a single queue—rpTestQueue.
The following creates a queue called rpTestQueue within the queue table rpTestQTab. After creation, the queue is started.
DBMS_AQADM.CREATE_QUEUE(
Queue_name => 'rpTestQueue',
Queue_table => 'rpTestQTab');
DBMS_AQADM.START_QUEUE(
queue_name => 'rpTestQueue');
If you wanted to add a topic, then the following example shows how you can create a topic called rpTestTopic within the topic table rpTestTTab. After creation, two durable subscribers are added to the topic. Finally, the topic is started and a user is granted a privilege to it.
|
Note: Oracle AQ uses theDBMS_AQADM.CREATE_QUEUE method to create both queues and topics.
|
DBMS_AQADM.CREATE_QUEUE_TABLE(
Queue_table => 'rpTestTTab',
Queue_payload_type => 'SYS.AQ$_JMS_MESSAGE',
multiple_consumers => true,
compatible => '8.1.5');
DBMS_AQADM.CREATE_QUEUE( 'rpTestTopic', 'rpTestTTab');
DBMS_AQADM.ADD_SUBSCRIBER('rpTestTopic', sys.aq$_agent('MDSUB', null, null));
DBMS_AQADM.ADD_SUBSCRIBER('rpTestTopic', sys.aq$_agent('MDSUB2', null, null));
DBMS_AQADM.START_QUEUE('rpTestTopic');
|
Note: The names defined here must be the same names used to define the queue or topic in theorion-ejb-jar.xml file.
|
Configure a data source for the database where the OJMS provider is installed. The JMS topics and queues use database tables and queues to facilitate messaging. The type of data source you use depends on the functionality you want.
For no transactions or single-phase transactions, you can use either an emulated or non-emulated data sources. For two-phase commit transaction support, you can use only a non-emulated data source.
Example 23-2 Emulated With OCI JDBC Driver
The following shows an emulated data source that uses the OCI JDBC driver. Thus, it is J2EE 1.3 compliant, which supports session pooling. However, it can only maintain single-phase commit transactions.
The example is displayed in the format of an XML definition; see the Oracle Containers for J2EE Configuration and Administration Guide for directions on adding a new data source to the configuration.
<data-source class="oracle.j2ee.sql.DriverManagerDataSource" name="OracleDS" location="jdbc/CartEmulatedOracleCoreDS" xa-location="jdbc/xa/CartEmulatedOracleXADS" ejb-location="jdbc/CartEmulatedDS" connection-driver="oracle.jdbc.driver.OracleDriver" username="myuser" password="mypasswd" url="jdbc:oracle:oci8:@(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=mysun) (PORT=5521))(CONNECT_DATA=(SID=orcl)))" inactivity-timeout="30" />
Example 23-3 Emulated Data Source With Thin JDBC Driver
The following example contains an emulated data source that uses the thin JDBC driver. To support a two-phase commit transaction, use a non-emulated data source. For differences between emulated and non-emulated data sources, see the Data Source chapter in the Oracle Containers for J2EE Services Guide.
The example is displayed in the format of an XML definition; see the Oracle Containers for J2EE Configuration and Administration Guide for directions on adding a new data source to the configuration through the Oracle Enterprise Manager 10g tool.
<data-source class="oracle.j2ee.sql.DriverManagerDataSource" name="OracleDS" location="jdbc/emulatedOracleCoreDS" xa-location="jdbc/xa/emulatedOracleXADS" ejb-location="jdbc/emulatedDS" connection-driver="oracle.jdbc.driver.OracleDriver" username="jmsuser" password="jmsuser" url="jdbc:oracle:thin:@myhost.foo.com:1521:mydb" />
Customize this data source to match your environment. For example, substitute the host name, port, and SID of your database for mysun:1521:orcl.
|
Note: Instead of providing the password in the clear, you can use password indirection. For details, see the Oracle Containers for J2EE Services Guide. |
Identify the JNDI name of the data source that is to be used as the OJMS provider within the <resource-provider> element.
If this is to be the JMS provider for all applications (global), configure the global application.xml file.
If this is to be the JMS provider for a single application (local), configure the orion-application.xml file of the application.
The following code sample shows how to configure the JMS provider using XML syntax for OJMS.
class attribute—The OJMS provider is implemented by the oracle.jms.OjmsContext class, which is configured in the class attribute.
property attribute—Identify the data source that is to be used as this JMS provider in the property element. The topic or queue connects to this data source to access the tables and queues that facilitate the messaging.
The following example demonstrates that the data source identified by "jdbc/emulatedDS" is to be used as the OJMS provider. This JNDI name is identified in the ejb-location element in Example 23-3. If this example used a non-emulated data source, then the name would be the same as in the location element.
<resource-provider class="oracle.jms.OjmsContext" name="myProvider"> <description> OJMS/AQ </description> <property name="datasource" value="jdbc/emulatedDS"></property> </resource-provider>