High Availability ActiveMQ using a MySQL datastore
Now that we have ActiveMQ deployed it'd be quite nice to reduce the impact of a broker being unavailable - perhaps because it's dropped off the network, or because we want to upgrade the kernel or ActiveMQ install. Let's setup a High Availability ActiveMQ cluster.
High Availability Options
There are lots of ways to run ActiveMQ as master / slave cluster for HA but we already have an HA MySQL setup so I'd like to use that as the datatstore. In ActiveMQ terms that means I'd like to setup a JDBC master / slave cluster.
Setting up ActiveMQ to use a MySQL Datastore
It turns out that this is really easy to setup. First, configure ActiveMQ to use MySQL then make sure you're using InnoDB. The only change I made to these instructions was to change dataDirectory="${activemq.base}/activemq-data"
to dataDirectory="${activemq.base}/data"
. Remember to change the broker name in activemq.xml to match the machine name. You've now got one broker running with a MySQL datastore.
Adding a slave for failover
To setup the slave a slave, install a second instance of ActiveMQ doing exactly the same as above - make sure the broker name is unique. Umm... that's it!
Starting the cluster
Start the DaemonTools services. It doesn't really matter which broker is master so it doesn't matter which order you start them in.
svc -u /etc/service/activemq
When you tail the logs of both brokers you should see one stop after loading the database driver. It's trying to acquire the lock on the datastore and will stay here until the master fails and the lock is released. At that point it will take over as the master.
You can test failover by shutting down the current master. Success is shown in the logs of the slave that's taking over as master: it'll say it's acquired the lock.
curl -LO http://barkingiguana.com/2008/12/16/high-availability-activemq-using-a-mysql-datastore.html.orig
curl -LO http://barkingiguana.com/2008/12/16/high-availability-activemq-using-a-mysql-datastore.html.orig.asc
gpg --verify high-availability-activemq-using-a-mysql-datastore.html.orig{.asc,}
If you'd like to have a conversation about this post, email craig@barkingiguana.com. I don't bite.