JBoss Messaging Distributed Topic 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 topic. The client code creates two distinct JMS connections to two different cluster nodes. Each connection is then used to create a subscriber for the distributed topic. The example is considered successful if both subscribers receive a message sent to the topic.

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-topic

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 TOPIC example                    #
     [echo] ###########################################################################
     [echo] The topic:      testDistributedTopic
     [echo] The client jar: ../../../output/lib/jboss-messaging-client.jar

sanity-check:

init:
    [mkdir] Created dir: C:\work\src\svn\messaging\docs\examples\distributed-topic\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-topic\output

run:
     [java] Distributed topic /topic/testDistributedTopic exists
     [java] The message was successfully published on the distributed topic
     [java] MessageListener 1 received message: Hello!
     [java] MessageListener 2 received message: Hello!
     [java] The example connected to JBoss Messaging version 1.2.0.Beta1 (1.2)

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

BUILD SUCCESSFUL
Total time: 4 seconds