The OpenAMQ clustering implementation covers two main functionalities:
We take two brokers, running on the same or different systems. One broker is the primary, one is the backup. When the cluster starts, the primary is master and the backup is slave. If the primary dies, the backup takes over the role of master. If the primary comes back, it remains slave. To reset the cluster, restart the backup.
For HA clustering to work, applications must connect to first the primary server, and if that fails, the backup server. Applications must use the correct order (primary, then secondary).
You can share the same configuration for both brokers by specifying the key options on the command-line. In amq_server.cfg, add this section:
<cluster
vhost = "/"
primary_peer = "localhost:5555"
backup_peer = "localhost:6666"
/>
Then start the two brokers as follows (you can use any legal values for the port numbers):
amq_server --port 5555 --is_primary 1 amq_server --port 6666 --is_backup 1
Alternatively you can use two separate configuration files, with the primary server using this:
<cluster
vhost = "/"
is_primary = "1"
backup_peer = "localhost:6666"
/>
And the backup server using this:
<cluster
vhost = "/"
is_backup = "1"
primary_peer = "localhost:5555"
/>
The vhost option is used to ensure that connecting applications are using the correct cluster. This value must match the value used by applications.
We connect an exchange on one broker (or HA pair of brokers) to the matching exchange on a remote broker (or HA pair of brokers).
The local exchange either sends messages to the remote exchange, or subscribes to messages from it.
There are three message transfer modes:
The classic scenario is when local applications want to receive topic data published centrally.
The configuration looks like this:
<cluster_mta
name = "exchange-name"
vhost = "virtual-host-name"
host = "remotehost:port"
login = "peering"
mode = "1"
/>
All bindings made to the specified exchange are copied to the specified remote host exchange.
Most often used with topic or headers exchanges.
Worked example:
The classic scenario is when local applications want to publish data both to local clients and remote ones.
The configuration looks like this:
<cluster_mta
name = "exchange-name"
vhost = "virtual-host-name"
host = "remotehost:port"
login = "peering"
mode = "2"
/>
All messages published to the local exchange are automatically published to the remote exchange as well.
Most often used with topic or headers exchanges.
The classic scenario is when local applications want to use services that could be either local, or remote.
The configuration looks like this:
<cluster_mta
name = "exchange-name"
vhost = "virtual-host-name"
host = "remotehost:port"
login = "peering"
mode = "3"
/>
All messages published to the local exchange are automatically published to the remote exchange only if they are not delivered locally.
Most often used with direct exchanges so that services can be placed either locally or remotely, invisibly to the applications.