Config and start ActiveMQ in master-slave mode on single machine

0
6693
ActiveMQ
ActiveMQ

ActiveMQ provides a pretty easy way to config master-slave mode when running on single machine, that is, when the master queue server is down, the slave can top up to handle the incoming messages.

Let say that we want to create two servers, one master and one backup.

The first thing to do is to generate two ActiveMQ instances for those two. This can be done via `create` command:


$ activemq create mq-master

$ activemq create mq-slave

The commands will generate two new config directories along with binary to start server instance.

Create ActiveMQ instances
Create ActiveMQ instances

When deploy, just start two instances by accessing their config directories.


$ mq-master\bin\mq-master start
$ mq-slave\bin\mq-slave start

Since `mq-master` has been started first, it will hold the queue server lock, `mq-slave` will load config as normal but will not start as the server lock has been hold by `mq-master`.


Loading message broker from: xbean:activemq.xml
 INFO | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1@59ec2012: startup date [Sun Aug 13 13:35:24 ICT 2017]; root of context hierarchy
 INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[D:\installed\activemq\data\kahadb]
 INFO | Database D:\installed\activemq\data\kahadb\lock is locked by another server. This broker is now in slave mode waiting a lock to be acquired

Now, if for any reason `mq-master` goes down, then the lock will be released, then `mq-slave` will get the lock and replace the down `mq-master`.