Now that we have ActiveMQ deployed, it would be nice to reduce the impact of a broker going offline — whether it's dropped off the network, or you need to upgrade the kernel or the ActiveMQ install itself. Let's set up a high availability ActiveMQ cluster.
High Availability Options
There are several ways to run ActiveMQ as a master/slave cluster for HA. Since we already have an HA MySQL setup, I want to use that as the datastore. In ActiveMQ terms, that means setting up a JDBC master/slave cluster.
Setting Up ActiveMQ with a MySQL Datastore
This turns out to be really easy. First, configure ActiveMQ to use MySQL, then make sure you're using InnoDB. The only change I made to those instructions was switching dataDirectory="${activemq.base}/activemq-data" to dataDirectory="${activemq.base}/data". Remember to set the broker name in activemq.xml to match the machine name. That's it — you've got one broker running with a MySQL datastore.
Adding a Slave for Failover
To set up the slave, install a second ActiveMQ instance following the exact same steps — just make sure the broker name is unique. That's genuinely all there is to it.
Starting the Cluster
Start the DaemonTools services. It doesn't matter which broker becomes master, so the order you start them in is irrelevant.
svc -u /etc/service/activemq
When you tail the logs of both brokers, you should see one of them pause after loading the database driver. It's trying to acquire the lock on the datastore and will wait there until the master fails and the lock is released. At that point, it takes over as the new master.
You can test failover by shutting down the current master. Watch the slave's logs — when it says it's acquired the lock, you know the failover worked.