ActiveMQ: Master/Slave Broker Configuration
Join the DZone community and get the full member experience.
Join For FreePure Master/Slave Configuration
There is not much to configuring a master/slave pair with ActiveMQ, in fact the configuration needed is a single attribute added to the slave broker. In the slave broker's configuration file (activemq.xml) you will need to add the masterConnectorURI attribute to the broker element as follows:
<broker xmlns="http://activemq.apache.org/schema/core" masterConnectorURI="tcp://localhost:61616" brokerName="amq1S" dataDirectory="${activemq.base}/data">Essentially, all you need is the one attribute above. However, if you need to provide credentials for the connection, then you can use the following alternative configuration to connect to the master:
<services> <masterConnector remoteURI="tcp://localhost:61616" userName="User1" password="pass1"/> </services>The URI specified should be the connection URI for the master broker. This allows the slave to make a connection to master as shown below:
INFO | ActiveMQ 5.5.1-fuse-01-13 JMS Message Broker (amq1S) is starting INFO | For help or more information please see: http://activemq.apache.org/ INFO | Connector vm://amq1S Started INFO | Starting a slave connection between vm://amq1S#0 and tcp://localhost:61616 INFO | Slave connection between vm://amq1S#0 and tcp://localhost/127.0.0.1:61616 has been established. INFO | ActiveMQ JMS Message Broker (amq1S, ID:macbookpro-251a.home-53545-1328657220277-1:1) startedFrom the output you can see the slave is aware of the master broker and has made a connection. This connection allows the slave broker to stay in sync with the master by replicating the master broker's data store. Once the slave detects the master has failed it will complete it's start up process by starting all it's connectors:
ERROR | Network connection between vm://amq1S#0 and tcp://localhost/127.0.0.1:61616 shutdown: null java.io.EOFException at java.io.DataInputStream.readInt(DataInputStream.java:375) at org.apache.activemq.openwire.OpenWireFormat.unmarshal(OpenWireFormat.java:275) at org.apache.activemq.transport.tcp.TcpTransport.readCommand(TcpTransport.java:228) at org.apache.activemq.transport.tcp.TcpTransport.doRun(TcpTransport.java:220) at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:203) at java.lang.Thread.run(Thread.java:680) WARN | Master Failed - starting all connectors INFO | Listening for connections at: tcp://macbookpro-251a.home:62616 INFO | Connector openwire StartedAt this point, the slave is knowledgable about all events processed by the master and additional processing can continue without interruption.
The documentation on configuring a pure master slave ActiveMQ instance also contains some optional parameters that you may find useful if you plan to implement this type of master/slave configuration that will ensure the master and slave broker's data stores stay in sync. Hit the link to see these additional parameters, and how they are used.
Download
Want to give this a try? Download the latest FuseSource distribution of ActiveMQ.
Summary
Configuring a Master/Slave ActiveMQ instance is easy. With one simple attribute you can create a highly available ActiveMQ messaging platform.
Published at DZone with permission of Jason Sherman, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments