Configuring Oracle JMS

In the previous section you saw how to create and configure an Oracle 10g AS JMS-based application. In this section you'll take that application and make it run against the Oracle JMS provider. As we mentioned earlier, Oracle 10g AS provides a standard mechanism with which you can plug in additional JMS providers: the ResourceProvider interface. Oracle 10g AS comes complete with an implementation of this interface, oracle.jms.OjmsContext , which enables Oracle JMS to be used as a JMS provider.

Oracle JMS is based on the Oracle Streams Advanced Queuing (AQ) feature of the Oracle database. AQ is a full messaging system built on top of the Oracle database system supporting both point-to-point and publish/subscribe messaging. AQ has a vast array of features that improve upon plain JMS, but one of the biggest benefits of AQ is the fact that it has many different client libraries that allow it to be accessed from Java, C, PL/SQL and many more. This makes AQ a great way to integrate applications that were written using different languages. A full discussion of AQ is outside the scope of this chapter and this book, but we'll demonstrate how to configure a queue on a database that's running AQ in the following section.

Setting Up the Queue

Configuring an OJMS queue is mostly a database process. The first step is to create a user with the appropriate permissions, and then, using the DBMS_AQADM package, create the tables and queues in that user's schema. The following SQL script will create the user jmsuser and give him the appropriate permissions. It will then create the queue and queue table within the jmsuser schema.

 DROP USER jmsuser CASCADE ; GRANT connect, resource,AQ_ADMINISTRATOR_ROLE TO jmsuser IDENTIFIED BY pwd ; 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; BEGIN    DBMS_AQADM.CREATE_QUEUE_TABLE(         Queue_table            => 'helloWorldQueueTbl',         Queue_payload_type     => 'SYS.AQ$_JMS_MESSAGE',         sort_list => 'PRIORITY,ENQ_TIME',         multiple_consumers  => false,         compatible             => '8.1.5');    DBMS_AQADM.CREATE_QUEUE(       Queue_name          => 'helloWorldQueue',       Queue_table         => 'helloWorldQueueTbl');    DBMS_AQADM.START_QUEUE(       queue_name         => 'helloWorldQueue'); END; / quit; 

If you want to create a topic destination rather than a queue, just set the multiple_consumers parameter of the CREATE_QUEUE_TABLE procedure to true .

Configuring Oracle 10g AS

Configuring Oracle 10g AS for the Oracle JMS provider requires modifications to two configuration files: the global application.xml and data-sources.xml . The first step is to configure the resource provider in the application.xml file, as shown here:

 <resource-provider class="oracle.jms.OjmsContext" name="oraclejms">            <description> OJMS/AQ </description>            <property name="datasource" value="jdbc/OracleDS"></property> </resource-provider> 

Though the description isn't important, the name you specify in the <resource-provider> tag is, because it will be used later as part of the JNDI name for resources managed by the Oracle JMS provider.

The OjmsContext resource provider also requires you to specify a <property> element with the name of the data source it should use. This should point to the database holding the Oracle AQ queue. Therefore, it's necessary to configure a data source in the data-sources.xml file that points at that Oracle database server, as follows :

 <data-source       class="com.evermind.sql.DriverManagerDataSource"       name="OracleDS"       location="jdbc/OracleCoreDS"       xa-location="jdbc/xa/OracleXADS"       ejb-location="jdbc/OracleDS"       connection-driver="oracle.jdbc.driver.OracleDriver"       username="jmsuser"       password="pwd"       url="jdbc:oracle:thin:@meerkat:1521:orcl"       inactivity-timeout="30"       /> 

If you used the SQL script described earlier to create the queues in Oracle AQ, then the username and password will be the same otherwise you should change them to match your environment. The URL for your Oracle database will undoubtedly be different than the one configured here, so make sure that you change that to match your environment as well.

At this point, the resource provider you've configured should be available globally to all applications. If you wish to set up a resource provider specific to an individual application, move the <resource-provider> declaration from the global application.xml file to that application's orion-application.xml file.

Configuring the Hello World Application

All that's left is to reconfigure the application so that it uses the Oracle JMS queues instead of the Oracle 10g AS JMS queues. Because we used local JNDI names in the Java code and in the application-client .xml file, all that's required is a change to the orion-application-client.xml file, as shown here:

 <resource-ref-mapping name="jms/queueConnectionFactory"  location="java:comp/resource/oraclejms/QueueConnectionFactories/aqQcf"/>  <resource-env-ref-mapping name="jms/helloWorldQueue"  location="java:comp/resource/oraclejms/Queues/jmsuser.helloWorldQueue"/> 

You'll notice that we've changed the location attributes to the values required by Oracle JMS. To build these location strings, start with the prefix, java:comp/resource , which is used by all resource providers. Follow that with the resource provider's name: in this case, oraclejms . After that the remainder of the location is specific to the resource provider. For Oracle JMS, queue connection factories are accessed under the QueueConnectionFactories name and queues are accessed under the Queues name. Likewise you can access topic connection factories and topics using TopicConnectionFactories and Topics .

The name used for the queue connection factory in the final part of the location attribute is unimportant, unless you require access to a specifically configured connection factory. The configuration of connection factories in AQ is outside the scope of this chapter, but you'll find more details in the online AQ reference at http://download-west.oracle.com/docs/cd/B13789_01/server.101/b10728/toc.htm .

Tip 

If you're having problems getting this example to work, start OC4J with the datasource.verbose system property set to true . This will output some fairly detailed information about the data sources and will help you to trace the behavior of the data source that's configured for the AQ server.

Before you run the sender to test the Oracle queue, run a SELECT COUNT(*) FROM helloWorldQueueTbl query on the helloWorldQueueTbl table in Oracle to make sure the current message count is zero. After running the sender, run the SELECT query again to check that the message is in the queue.



Oracle Application Server 10g. J2EE Deployment and Administration
Oracle Application Server 10g: J2EE Deployment and Administration
ISBN: 1590592352
EAN: 2147483647
Year: 2004
Pages: 150

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net