How to create JMX connection to the ServiceMix MBeanServer programmatically.

Solution Verified - Updated -

Environment

  • Fuse ESB Enterprise
  • Fuse ESB

Issue

  • How to create JMX connection to ServiceMix MBeanServer programmatically?

  • How to connect to the ServiceMix JMX server using Java?

Resolution

ServiceMix uses JMX to manage the container and provide instrumented component statistics. It can be used via any JMX Management console (like JConsole, JManage, FUSE HQ etc.). However, sometimes it is desirable to have access to JMX MBeans via user application layer. This can be done in Java using JMX API and here is a sample connect method (assuming default ServiceMix installation configuration)

static private MBeanServerConnection connect(String url, String user, String pass)
   throws IOException {
   JMXConnector connector = null;
   MBeanServerConnection connection = null;

   Map<String, String[]> env = new HashMap<String, String[]>();
   String[] credentials = new String[] {user, pass};
   env.put(JMXConnector.CREDENTIALS, credentials);
   try {
       connector = JMXConnectorFactory.newJMXConnector(new JMXServiceURL(url), env);
       connector.connect();
       connection = connector.getMBeanServerConnection();
   } catch (MalformedURLException e) {
       e.printStackTrace();
   } catch (IOException e) {
       e.printStackTrace();
   }
   return connection;
}

When invoking the above method the url parameter could be set to this String: "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi"

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments