Overview

The OpenJMS code examples demonstrate how to write simple applications using JMS.

The sources of these examples are located in the src/examples directory.

Source Description
src/examples/openjms/examples/client/console/SimpleConsumer.java This demonstrates using a TopicSubscriber to asynchronously receive messages from a topic.
src/examples/openjms/examples/client/console/SimplePublisher.java This demonstrates using a TopicPublisher to send messages to a topic.
src/examples/openjms/examples/client/console/SimpleReceiver.java This demonstrates using a QueueReceiver to synchronously receive messages from a queue.
src/examples/openjms/examples/client/console/SimpleSender.java This demonstrates using a QueueSender to send messages to a queue.

Building the examples

To build the example programs on Windows, open a command prompt and type:

cd %OPENJMS_HOME%
build.bat
        

On Unix:

cd $OPENJMS_HOME
build.sh
        

Running the examples

Running the SimpleConsumer

To run the SimpleConsumer on Windows, type:

runconsumer -topic topic1
          

On Unix:

runconsumer.sh -topic topic1
          

This will connect to the OpenJMS server, subscribe to the topic 'topic1', and wait for messages.

Running the SimplePublisher

To run the SimplePublisher on Windows, type:

runpublisher -topic topic1
          

On Unix:

runpublisher.sh -topic topic1
          

This will connect to the OpenJMS server, and publish 10 TextMessage messages to the topic 'topic1'.

If the SimpleConsumer is running and subscribed to 'topic1', it will display the messages it has received.

Running the SimpleReceiver

To run the SimpleReceiver on Windows, type:

runreceiver -queue queue1
          

On Unix:

runreceiver.sh -queue queue1
          

This will connect to the OpenJMS server, construct a QueueReceiver to receive messages from the queue 'queue1', and block, waiting for messages.

Running the SimpleSender

To run the SimpleSender.java on Windows, type:

runsender -queue queue1
          

On Unix:

runsender.sh -queue queue1
          

This will connect to the OpenJMS server, and send 10 BytesMessage messages to the queue 'queue1'.

If the SimpleReceiver is running and listening to 'queue1', it will display the messages it has received.