Monday, August 19, 2013

Active 5.8.0 Master Slave Web Console Fix

Recently I ran into an issue when I attempted to use ActiveMQ 5.8.0 Web Console to monitor a two node Master/Slave ActiveMQ cluster.

The ActiveMQ 5.8.0 Web Console (hosted in a Tomcat container) connects to remote ActiveMQ instance over JMX. In ActiveMQ 5.8.0, the JMX connector is enabled for both Master and Slave nodes. Due to which the Web Console is unable to determine which node is the master node. Hence the issue. 

In order to get around this problem, I created a class which extends the RemoteJMXBrokerFacade class by adding intelligence to an overridden findBrokers(...) method such that the Web Console considers an ActiveMQ node as a master node if and only if it is able to fetch a reference to the BrokerViewMBean. 

The above operation throws an IllegalStateException if the broker was to be slave node. 

The Web Console gets the list of JMX Connectors for all the ActiveMQ Brokers in a cluster via the following property


The following is the source code:

package org.apache.activemq.web;

import java.util.Set;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

 * This class helps ActiveMQ Web Console determine if the remote broker instance is master or slave
 * In the webconsole-properties.xml, replace the <code>org.apache.activemq.web.RemoteJMXBrokerFacade</code> class 
 * with <code>org.apache.activemq.web.MasterSlaveAwareJMXBrokerFacade</code>
 * <pre>
 * {@code
 *  <bean id="brokerQuery" class="org.apache.activemq.web.MasterSlaveAwareJMXBrokerFacade" autowire="constructor" destroy-method="shutdown">
    <property name="configuration" ref="configuration"/>
    <property name="brokerName"><null/></property>
 * }
 * </pre>
public class MasterSlaveAwareJMXBrokerFacade extends RemoteJMXBrokerFacade {

 private static final transient Logger LOG = LoggerFactory

 protected Set<ObjectName> findBrokers(MBeanServerConnection connection)
   throws IOException, MalformedObjectNameException {

  LOG.debug("Finding brokers");
  ObjectName name;

  name = new ObjectName("org.apache.activemq:type=Broker,brokerName=*");

  Set<ObjectName> brokers = connection.queryNames(name, null);

  try {
   ObjectName brokerObjectName = (ObjectName) brokers.iterator().next();
   BrokerViewMBean mbean = (BrokerViewMBean) MBeanServerInvocationHandler
     .newProxyInstance(connection, brokerObjectName,
       BrokerViewMBean.class, true);

   LOG.debug("Broker Id : " + mbean.getBrokerId());

  } catch (Throwable t) {
   // TODO Auto-generated catch block
   LOG.error("Exception occurred while trying to retrieve BrokerViewMBean", t);
   throw new RuntimeException(t);
  return brokers;


If the Web Console attempts to connect to slave broker, the following exception gets thrown.
SEVERE: Servlet.service() for servlet [jsp] in context with path [/activemq-web-console-5.8.0] threw exception [javax.el.ELException: Error reading 'brokerName' on type org.apache.activemq.web.RemoteJMXBrokerFacade] with root cause
java.lang.IllegalStateException: Broker is not yet started.
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(
 at java.lang.reflect.Method.invoke(
 at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(
 at com.sun.jmx.mbeanserver.StandardMBeanIntrospector.invokeM2(
 at com.sun.jmx.mbeanserver.MBeanIntrospector.invokeM(
 at com.sun.jmx.mbeanserver.PerInterface.getAttribute(
 at com.sun.jmx.mbeanserver.MBeanSupport.getAttribute(
 at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(
 at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(
 at java.lang.reflect.Method.invoke(
 at sun.rmi.server.UnicastServerRef.dispatch(
 at sun.rmi.transport.Transport$
 at Method)
 at sun.rmi.transport.Transport.serviceCall(
 at sun.rmi.transport.tcp.TCPTransport.handleMessages(
 at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(
 at sun.rmi.transport.tcp.TCPTransport$
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(
 at java.util.concurrent.ThreadPoolExecutor$

This solution has worked for me. I would like to know if you have a better way to fix this.


  1. Do you know if this bug is fixed in ActiveMQ 5.9.0?

    1. @johnlindwall I haven't checked this on 5.9.0 version yet. It is on my todo list :)

  2. This comment has been removed by the author.

  3. Hi Ashwini , Do you know hoe to get the broker or broker service instance of the existing broker ? i was just looking for the snippets to get the broker service instance of the remote broker which i should not create one instead i have to get the existing broker service or broker instance from the remote broker ? any suggestions.