next up previous contents
Next: 5 Tomcat Example Up: JOTM Examples guide Previous: 3 JDBC Example   Contents


4 JMS Example

JOTM can be used with any JMS (Java Message Service) provider to gain advantage of both message-oriented architecture and distributed transactions.
This example uses JORAM ( as its JMS provider.

All Ant commands are to be executed from the examples/jms/ directory of a JOTM distribution (examples won't work from JOTM source directory).

4.1 Scenario

The jms example shows how to use JOTM with a JMS provider (in our case, JORAM) to provide distributed transactional messages.

On one hand, SimpleSender sends 4 messages on a JMS queue:

On the other hand, SimpleReceiver receives 3 messages from the same JMS queue:

(SimpleReceiver does not receive the 3rd sent message because it has been rolled back.)

4.2 Setup and compilation

To compile the example, type

$ ant compile

4.3 Run the example

First, you've to set JOTM_HOME to the directory of your JOTM distribution (e.g., ../jotm/output/dist from CVS).
$ export JOTM_HOME=<JOTM_distribution_directory>
To run the example, type in $JOTM_HOME/lib/
$ rmiregistry -J-classpath -Jjotm.jar:jotm_jrmp_stubs.jar \ &
Then in $JOTM_HOME/lib/, type
$ java -classpath jotm.jar:jotm_jrmp_stubs.jar:../config/ \
  org.objectweb.jotm.Main \
  -u UserTransaction -m TransactionManager&
(on one line)

And in the jms/ directory, type

$ ant run.jms

Since the client application of the jms example is a simple RMI/JRMP client, you've to use default protocol configuration for JOTM (i.e RMI/JRMP) in $JOTM_HOME/config/ file.

4.4 Output

the output of the jms example should be somethnig like

$ ...
$ [java] [SimpleJmsXa] lookup the TransactionManager.
$ [java] [SimpleJmsXa] start the JMS server.
$ [java] [SimpleJmsXa] JMS server started.
$ [java] [SimpleJmsXa] create JMS objects, register them in JOTM and bind them.
$ [java] [SimpleJmsXa] JMS objects available.
$ [java] [SimpleJmsXa] start simple sender.
$ [java] [SimpleSender] send : non transactional message
$ [java] [SimpleSender] send : transactional message with commit
$ [java] [SimpleSender] send : transactional message with rollback
$ [java] [SimpleSender] send : LAST message
$ [java] [SimpleJmsXa] start simple receiver.
$ [java] [SimpleReceiver] received: non transactional message
$ [java] [SimpleReceiver] received: transactional message with commit
$ [java] [SimpleReceiver] received: LAST message
$ [java] [SimpleJmsXa] JMS server stopped
$ ...

If SimpleSender has effectively sent 4 messages and SimpleReceiver has effectively received only 3 messages, then the jms example is working!

next up previous contents
Next: 5 Tomcat Example Up: JOTM Examples guide Previous: 3 JDBC Example   Contents
Jeff Mesnil 2003-07-30