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
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Data Engineering
  3. IoT
  4. How to Monitor ActiveMQ Networks

How to Monitor ActiveMQ Networks

Dejan Bosanac user avatar by
Dejan Bosanac
·
Jun. 06, 12 · Interview
Like (0)
Save
Tweet
Share
7.76K Views

Join the DZone community and get the full member experience.

Join For Free

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.

Network

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.

JConsole1

JConsole2.png

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(
                "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
        JMXConnector connector = JMXConnectorFactory.connect(url, null);
        connector.connect();
        MBeanServerConnection connection = connector.getMBeanServerConnection();
        ObjectName name = new ObjectName(
                "org.apache.activemq:BrokerName=static-broker1,Type=NetworkBridge,*");
        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/127.0.0.1:61617) 
Bridge to static-broker2 (/127.0.0.1:52776) - 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());
        conn.start();
    }
    @Override
    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) {
            e.printStackTrace();
        }
    }
}

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

Network Monitor (synchronization)

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

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How To Choose the Right Streaming Database
  • Monolithic First
  • Building Microservice in Golang
  • Introduction to Container Orchestration

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: