JBoss Messaging Distributed Topic Example

$Revision: 82920 $

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 userguide.

For JBoss5, you should copy all as messaging-node0, configure mysql as a database, make it clustered, and copy it as messaging-node1. Start each instance as:

./run -c messaging-node0 -Djboss.service.binding.set=ports-01


and in another window

./run.sh -c messaging-node1 -Djboss.service.binding.set=ports-02 -Djboss.messaging.ServerPeerID=1


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.4.1.GA (1.4)

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

BUILD SUCCESSFUL
Total time: 4 seconds