This example demonstrates a JMS Topic deployed on three different nodes. The three nodes are configured to form a cluster.
Subscribers for the topic are created on each node, and a producer is created on only one of the nodes.
Some messages are sent by the producer, and we verify that all subscribers receive all the sent messages.
This example uses ActiveMQ's default stand-alone clustered configuration. The relevant snippet from the server configuration, which tells the servers to form a cluster between the three nodes and to load balance the messages between the nodes is:
<cluster-connection name="my-cluster">
<address>jms</address>
<discovery-group-ref discovery-group-name="dg-group1"/>
</cluster-connection>
To run the example, simply type mvn verify -Pexample
from this directory. This will
automatically start the 3 cluster nodes, each with its specific configuration.
To start the tests manually, the following steps are:
bin
directory and start the first server (with default configuration):
./run.sh ../config/stand-alone/clustered
export CLUSTER_PROPS="-Ddata.dir=../data-server2 -Djnp.port=2099 -Djnp.rmiPort=2098 -Dactivemq.remoting.netty.port=6445 -Dactivemq.remoting.netty.batch.port=6455"
./run.sh ../config/stand-alone/clustered
export CLUSTER_PROPS="-Ddata.dir=../data-server3 -Djnp.port=3099 -Djnp.rmiPort=3098 -Dactivemq.remoting.netty.port=7445 -Dactivemq.remoting.netty.batch.port=7455"
./run.sh ../config/stand-alone/clustered
./build.sh runRemote
(orbuild.bat runRemote
on windows)
The example connects to the three cluster nodes using JNDI (which are retrieved from
server0, server1, and
server2' s JNDI properties file). The JNDI ports were specified
using the environment property jnp.port
(or 1098 by default) when starting the 3 cluster nodes.
For a description of the example code, please read the clustered-topic example which is very similar (it has 2 nodes while this example has 3 nodes).