Stop and Start All Camel Routes


Here is a quick example of how you might stop all Camel routes regardless of the CamelContext. I assume that you have prior knowledge of how to connect via JMX, or you can see my last post on Purging ActiveMQ Queues via JMX.

ObjectName jmxRoutesName = new ObjectName("org.apache.camel:type=routes,*");
for (ObjectName jmxRouteName : conn.queryNames(jmxRoutesName, null)) {
    ManagedRouteMBean routeMBean =
            MBeanServerInvocationHandler.newProxyInstance(conn, jmxRouteName, ManagedRouteMBean.class, true);

The ManagedRouteMBean has quite a bit of other usefulness in it.