DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

ActiveMQ: Master/Slave Broker Configuration

Jason Sherman user avatar by
Jason Sherman
·
Jan. 29, 13 · Interview
Like (1)
Save
Tweet
Share
11.79K Views

Join the DZone community and get the full member experience.

Join For Free
This is a followup to my previous post on configuring multiple instances of the ActiveMQ web console into a single instance of Jetty.  In this post I'll show how the pair of brokers were configured to enable them to be highly available in the event that one of the brokers should fail.  The master/slave configuration used in this example is referred to as the Pure Master Slave.  There several different types of master/slave configurations including Shared File System Master Slave and JDBC Master Slave, the latter of which I will look at in a later post.

Pure 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) started  
From 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 Started 
At 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.




Master/slave (technology) master

Published at DZone with permission of Jason Sherman, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Key Elements of Site Reliability Engineering (SRE)
  • gRPC on the Client Side
  • Front-End Troubleshooting Using OpenTelemetry
  • Steel Threads Are a Technique That Will Make You a Better Engineer

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: