JBoss Messaging Distributed Queue Example

$Revision: 1017 $

Overview


This example demonstrates how to write JMS code that connects to a JBoss Messaging cluster and sends messages to a distributed queue. The example creates two connections to two distinct cluster nodes on which we have previously deployed a distributed queue. The example sends and receives messages using both connections.

Note
This is an example that assumes a NullMessagePullPolicy. This is the default configuration option a release ships with, and also is a very boring options, since messages are NOT redistributed among nodes. An example that assumes a DefaultMessagePullPolicy is coming soon (http://jira.jboss.org/jira/browse/JBMESSAGING-907).

This example relies on having access to a running JBoss Messaging cluster with at least two nodes. The JBoss Messaging cluster must be installed and started according to the "Installation" paragraph from the clustering documentation, bundled with the release (HTML, HTML-single and PDF). The clustering documentation is also available on-line at http://labs.jboss.com/portal/jbossmessaging/docs/index.html.

This example also relies on having access to the jboss-messaging-client.jar archive included with the release bundle. If you run this example from an unzipped installation bundle, the example run script is correctly configured to find the client jar. Otherwise, you must modify example's build.xml accordingly.

Running the example


1. Make sure that a JBoss Messaging cluster with at least two nodes is up and running.

2. Go to the example's home directory

cd ...\examples\distributed-queue

3. Run the example:

ant


The output of a successful run should be similar to:


$ ant
Buildfile: build.xml

identify:
     [echo] ###########################################################################
     [echo] #                Running the DISTRIBUTED QUEUE example                    #
     [echo] ###########################################################################
     [echo] The topic:      testDistributedQueue
     [echo] The client jar: ../../../output/lib/jboss-messaging-client.jar

sanity-check:

init:
    [mkdir] Created dir: C:\work\src\svn\messaging\docs\examples\distributed-queue\output
    [mkdir] Created dir: C:\work\src\svn\messaging\docs\examples\common\output

compile:
    [javac] Compiling 2 source files to C:\work\src\svn\messaging\docs\examples\common\output
    [javac] Compiling 2 source files to C:\work\src\svn\messaging\docs\examples\distributed-queue\output

run:
     [java] Distributed queue /queue/testDistributedQueue exists
     [java] The message was successfully sent to the distributed queue
     [java] MessageListener0 received message: Hello!
     [java] MessageListener1 received message: Another Hello!
     [java] The example connected to JBoss Messaging version 1.2.0.GA (1.2)

     [java] #####################
     [java] ###    SUCCESS!   ###
     [java] #####################

BUILD SUCCESSFUL
Total time: 4 seconds