Over a million developers have joined DZone.
Platinum Partner

Managing Camel Routes With JMX APIs

· Integration Zone

The Integration Zone is brought to you in partnership with 3scale. Take control of your APIs and get a free t-shirt when you complete the 3step Challenge

Here is a quick example of how to programmatically access Camel MBeans to monitor and manipulate routes...

first, get a connection to a JMX server (assumes localhost, port 1099, no auth)
note, always cache the connection for subsequent requests (can cause memory utilization issues otherwise)

JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi");
JMXConnector jmxc = JMXConnectorFactory.connect(url);
MBeanServerConnection server = jmxc.getMBeanServerConnection();

use the following to iterate over all routes and retrieve statistics (state, exchanges, etc)...

ObjectName objName = new ObjectName("org.apache.camel:type=routes,*");
List<ObjectName> cacheList = new LinkedList(server.queryNames(objName, null));
for (Iterator<ObjectName> iter = cacheList.iterator(); iter.hasNext();)
{
    objName = iter.next();
    String keyProps = objName.getCanonicalKeyPropertyListString();
    ObjectName objectInfoName = new ObjectName("org.apache.camel:" + keyProps);
    String routeId = (String) server.getAttribute(objectInfoName, "RouteId");
    String description = (String) server.getAttribute(objectInfoName, "Description");
    String state = (String) server.getAttribute(objectInfoName, "State");
    ...
}

use the following to execute operations against a Camel route (stop,start, etc)

ObjectName objName = new ObjectName("org.apache.camel:type=routes,*");
List<ObjectName> cacheList = new LinkedList(server.queryNames(objName, null));
for (Iterator<ObjectName> iter = cacheList.iterator(); iter.hasNext();)
{
    objName = iter.next();
    String keyProps = objName.getCanonicalKeyPropertyListString();
    if(keyProps.contains(routeID))
    {
        ObjectName objectRouteName = new ObjectName("org.apache.camel:" + keyProps);
        Object[] params = {};
        String[] sig = {};
        server.invoke(objectRouteName, operationName, params, sig);
        return;
    }
}

 summary

These APIs can easily be used to build a web or command line based tool to support remote Camel management features. All of these features are available via the JMX console and Camel does provide a web console to support some management/monitoring tasks.

See these pages for more information...
http://camel.apache.org/camel-jmx.html
http://camel.apache.org/web-console.html

 

 

 

 

 

 

 

 

The Integration Zone is brought to you in partnership with 3scale. Learn how API providers have changed the way we think about integration in The Platform Vision of API Giants.

Topics:

Published at DZone with permission of Ben O' Day , DZone MVB .

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}