Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Advanced JMS Messaging with OpenJMS : Page 4

Learn to use the more advanced features of OpenJMS to filter messages, create clients that can receive messages sent even when they aren't running, and create persistent messages that can survive a provider failure.


advertisement
Message Persistence
If a JMS provider should fail, you can use message persistence to ensure that messages are not lost. Using the persistent delivery mode (the default) instructs the JMS provider to persist messages to a stable store (a database) as part of the client's send operation.

By default, OpenJMS writes to a file (openjms.db which is found in the bin directory of the OpenJMS installation).

Configuring a database for message persistence requires the following steps:

  1. Add the JDBC driver to the CLASSPATH
  2. Edit the OpenJMS configuration file and specify connection properties
  3. Create the tables OpenJMS needs for persisting messages
Oracle8i, Sybase ASE, MySQL, and HSQLDB have been formally tested for message persistence. However, OpenJMS should work with any JDBC 2.0 compliant database.

I used IBM's DB2 Universal Database to test things out by first modifying the setenv.bat batch file (located in the bin directory of the OpenJMS installation) to point the CLASSPATH entry to the DB2 JDBC driver:

set CLASSPATH=C:\Program Files\IBM\SQLLIB\java\db2java.zip

You'll need to create the database before you can configure it. In DB2, issue the following command to the DB2 Command Line Processor:

db2 => create db openjms

Next, edit the OpenJMS configuration file (opensjms.xml, located in the config directory of the OpenJMS installation) and modify it to specify the DB2 database connection properties:



<DatabaseConfiguration> <RdbmsDatabaseConfiguration driver="COM.ibm.db2.jdbc.app.DB2Driver" url="jdbc:db2:openjms" user="db2user" password="db2password" /> </DatabaseConfiguration>

Depending on the database you are using, you might be able to create the tables which OpenJMS needs by using the db2tool application (located in the OpenJMS installation's bin directory) which ships with OpenJMS. This is done with the command:

dbtool.bat -create -config %OPENJMS_HOME%\config\openjms.xml

To create the tables for DB2, I had to issue the following command from the DB2 Command Window after changing to the config\db of the OpenJMS installation directory and logging into DB2 as the user specified in the openjms.xml file:

db2 -tvf create_db2.sql

The config\db directory contains scripts for most popular databases.

The figure below shows the DB2 Control Center peeking into the openjms database, in which the OpenJMS tables have been created.

 
Figure 4: The OpenJMS tables created in DB2.
After successfully configuring your persistence database with the necessary tables, OpenJMS will persist messages there, ensuring no message is lost during an OpenJMS provider failure.

This article has shown you some of the more advanced JMS topics, including message selectors, durable subscriptions, and message persistence. You can use message selectors to filter a client's consumption of messages. Durable subscriptions eliminate the need for a subscriber to be running when a message is published. Message persistence ensures that messages are not lost in case the JMS provider in your setup fails.



Kulvir Singh Bhogal works as an IBM consultant, devising and implementing J2EE-centric solutions at customer sites across the nation.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date