Configuring Third-Party JMS

If you want to access queues and topics that aren't in Oracle 10g AS JMS or Oracle JMS, you can configure the application server to use additional JMS providers. Oracle 10g AS provides a ResourceProvider interface as a standardized mechanism for linking in these third-party providers. However, rather than relying on individual manufacturers to build adapters for their products, Oracle provides an out-of-the-box ResourceProvider implementation the ContextScanningResourceProvider class , which binds objects from an external JNDI tree into the local tree. This mechanism works well because most JMS providers tend to bind their objects into a JNDI tree.

Using ContextScanningResourceProvider , you can use a third-party provider for the Hello World application. We've chosen to use SwiftMQ because it's available as a small evaluation download for both Windows and UNIX platformsit even runs on Mac OS X. Plus the installation is a breeze ! Visit the SwiftMQ website at www.swiftmq.com and download the evaluation version of the SwiftMQ Router. The download is available in a TAR format for UNIX and a ZIP format for Windows. The scripts in each release are specific to the operating environment.

To install the SwiftMQ Router, simply extract the archive to a suitable location and you're done. SwiftMQ already comes with some preconfigured queues for testing, so rather than create a new one, just fire up the first router by running ${SWIFTMQ_HOME}/scripts/unix/smqr1.sh script. For Windows users, the location for the start script is ${SWIFTMQ_HOME}/scripts/win32/smqr1.sh .

The next step is to add an additional <resource-provider> entry to the global application.xml file, as shown here:

 <resource-provider         class="com.evermind.server.deployment.ContextScanningResourceProvider"         display-name="SwiftMQ resource"         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" />         <property name="resource.names"                      value="testqueue@router1,plainsocket@router1" />     </resource-provider> 

From the preceding code you can see that the ContextScanningResourceProvider is configured with three properties. First, it requires the java.naming.factory.initial and java.naming.provider.url propertieswithout them it won't know which JNDI tree to search for resources. The resource.names property specifies which resources in SwiftMQ's JNDI tree should be bound into the local JNDI context. Here, we've included the testqueue queue and the plainsocket connection factory from router 1.

The next step is to point the local names used by the Hello World application to the SwiftMQ resources instead of the Oracle 10g AS JMS or Oracle JMS resources that they're currently bound to. As mentioned before, this is simply a matter of making the appropriate change in orion-application.xml :

 <resource-ref-mapping name="jms/queueConnectionFactory"  location="java:comp/resource/swiftmq/plainsocket@router1"/>  <resource-env-ref-mapping name="jms/helloWorldQueue"  location="java:comp/resource/swiftmq/testqueue"/> 

Again, you'll notice that the JNDI names for the external resources have the prefix java:comp/resource followed by the resource provider name that's specified in application.xml and then the provider-specific name.

Now for the interesting partthe documentation states that you should be able to simply drop the swiftmq.jar file into the $J2EE_HOME/lib directory, start up the server, and everything will be OK. Unfortunately, that's not the case. After placing the .jar file in every lib directory in the OC4J directory, after attempting to configure it as an additional <library> within application.xml , and after starting up, OC4J still informed me that it was unable to find the com.swiftmq.jndi.InitialContextFactoryImpl class. We tried this on OC4J on Mac OS X, Linux and Windows as well as on Oracle 10g AS Standard for Windows, but it didn't work on any of those installations. In the end we decided to take a different approach and instructed Java to load the swiftmq.jar into the classloader hierarchy above OC4J that way it would be available to OC4J at startup.

To do this, specify the bootclasspath option when starting OC4J, as follows :

 java -Xbootclasspath/a:$SWIFT_MQ/jars/swiftmq.jar:$SWIFT_MQ/jars/jms.jar \                         -jar oc4j.jar 

You'll notice that we also load the jms.jar file supplied with SwiftMQ. This is because SwiftMQ requires classes that aren't available in the OC4J JMS distribution.

You should now be able to run your Hello World sender and receiver applications in order to send and receive messages using the SwiftMQ message 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