Over a million developers have joined DZone.

How to Monitor ActiveMQ Networks

DZone's Guide to

How to Monitor ActiveMQ Networks

· Integration Zone
Free Resource

Build APIs from SQL and NoSQL or Salesforce data sources in seconds. Read the Creating REST APIs white paper, brought to you in partnership with CA Technologies.

If you’re running ActiveMQ in a distributed setup using network of brokers, you’re probably interested in techniques available to monitor your network. This usually implies viewing the status of the network bridges and generating events when the status changes. There were some improvements in this area for the next 5.5 release and here I’ll try to explain this topic a bit more.

To demonstrate these techniques we need a simple network, so take a look at the one shown in the following diagram.


We see that broker 1 have two network bridges:

  • One created by duplex connection, originating from broker 2
  • and one direct to the broker 3

Now let’s see for starters what JConsole will show us.



As you can see, both bridges are shown in JConsole under the Network Bridge tab. You can spot bridges created by remote duplex connectors, by having a connector name pattern like duplex#x and also CreatedByDuplex attribute set to true.

The similar information you can get now in Web Console. There’s a new tab, called Network (http://localhost:8161/admin/network.jsp), which will give you the following view.

Web Console

You can notice that again, you can easily separate bridges created by connectors on this broker and those created by remote duplex connector.

Tools are nice for most usages, but what if you want to monitor your network bridges programatically? Well the first thing you can do is to use JMX API to query bridges. The following application, connects to the broker and lists all of its network bridges.

public class Bridges {
    public static void main(String[] args) throws Exception {
        JMXServiceURL url = new JMXServiceURL(
        JMXConnector connector = JMXConnectorFactory.connect(url, null);
        MBeanServerConnection connection = connector.getMBeanServerConnection();
        ObjectName name = new ObjectName(
        Set bridges = connection.queryNames(name, null);
        for (ObjectName bridgeName : bridges) {
            NetworkBridgeViewMBean view =
                    (NetworkBridgeViewMBean) MBeanServerInvocationHandler.newProxyInstance(
                            connection, bridgeName, NetworkBridgeViewMBean.class, true);
            System.out.println(”Bridge to ” + view.getRemoteBrokerName() 
                    + ” (” + view.getRemoteAddress() + “) ”
                    + ((view.isCreatedByDuplex() ? “- created by duplex” : “”)));

So if you run it against broker 1, you’ll get something like

Bridge to static-broker3 (localhost/ 
Bridge to static-broker2 (/ - created by duplex

You can see both bridges, and an indication that bridge to broker 2 is created by remote duplex.

JMX API will give you just the static snapshot of the available bridges. If you’re interested in notifications when bridges are being stopped or started, you can use advisory messages. The following example shows how to subscribe to the appropriate advisory topic and get events of the interest.

public class BridgeAdvisories implements MessageListener {
    public static void main(String[] args) throws Exception {
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
        Connection conn = factory.createConnection();
        Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = sess.createConsumer(AdvisorySupport.getNetworkBridgeAdvisoryTopic());
        consumer.setMessageListener(new BridgeAdvisories());
    public void onMessage(Message message) {
        try {
            BrokerInfo brokerInfo = (BrokerInfo) ((ActiveMQMessage) message).getDataStructure();
            boolean started = message.getBooleanProperty("started");
            if (started) {
                boolean createdByDuplex = message.getBooleanProperty("createdByDuplex");
                System.out.println("Network bridge to " + brokerInfo.getBrokerName() + " ("
                        + brokerInfo.getBrokerURL() + ") has been started " + (createdByDuplex ? "by duplex" : ""));
            } else {
                System.out.println("Network bridge to " + brokerInfo.getBrokerName() + " ("
                        + brokerInfo.getBrokerURL() + ") has been stopped");
        } catch (JMSException e) {

If you run this against our broker 1 and start and stop brokers 2 and 3, you can expect the output similar to the following.

Network bridge to static-broker3 (tcp://dejan-bosanacs-macbook-pro.local:61617) has been stopped
Network bridge to static-broker3 (tcp://dejan-bosanacs-macbook-pro.local:61617) has been started 
Network bridge to static-broker2 (tcp://dejan-bosanacs-macbook-pro.local:61618) has been stopped
Network bridge to static-broker2 (tcp://dejan-bosanacs-macbook-pro.local:61618) has been started by duplex

So with this we covered techniques that you can use to monitor networks of ActiveMQ broker, which I hope you’ll find useful. If you’re interested in learning more about ActiveMQ (and related technologies), you can attend one of the online trainings organized by FuseSource

The Integration Zone is brought to you in partnership with CA Technologies.  Use CA Live API Creator to quickly create complete application backends, with secure APIs and robust application logic, in an easy to use interface.


Published at DZone with permission of Dejan Bosanac, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}