2 Replies Latest reply on Oct 22, 2012 3:16 PM by gte338m

    Calling Qpid JMX from ear deployed in JBoss7.1.2Final

    gte338m Newbie

      All

      I have a Java Qpid Broker running on the same machine as JBoss7.1.2.Final.  And am attempting to call JMX running in Qpid from an ear running in JBoss.


      The following code when ran in a main method runs as expected.  However, when I put the code inside an ear and call it via a webservice endpoint, I get the exception below.  Appears that jboss is interpreting the url as if the code is attempting to connect to the jboss service.  I was thinking that because qpid is listening on port 8999, that jboss would hit that port, there by triggering the jmx lookup on qpid.

       

      Exception:

      Failed to retrieve RMIServer stub: javax.naming.NameNotFoundException: rmi://localhost:8999/jmxrmi -- service jboss.naming.context.java.rmi:.localhost:8999.jmxrmi"}

       

      Code:

       

       

      private static void main() {

       

              String[] attributes = new String[]{"Name", "Owner", "ActiveConsumerCount", "AutoDelete", "Capacity", "ConsumerCount", "Description", "Durable", "Exclusive", "FlowOverfull",

                  "FlowResumeCapacity", "MaximumDeliveryCount", "MaximumMessageAge", "MaximumMessageCount", "MaximumMessageSize", "MaximumQueueDepth", "MessageCount", "QueueDepth", "QueueType", "ReceivedMessageCount"};

              try {

                  Map<String, Object> environment = new HashMap<String, Object>();

      // credentials: user name and password

                  environment.put(JMXConnector.CREDENTIALS, new String[]{"admin", "admin"});

                  JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:8999/jmxrmi");

                  JMXConnector jmxConnector = JMXConnectorFactory.connect(url, environment);

                  MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection();

                  String[] domains = mbsc.getDomains();

                  for (int k = 0; k < domains.length; k++) {

                      String domain = domains[k];

                      ObjectName queueObjectName = new ObjectName(domain + ":*");

                      Set nameSet = mbsc.queryNames(queueObjectName, null);

                      Iterator it = nameSet.iterator();

                      while (it.hasNext()) {

                          ObjectName n = (ObjectName) it.next();

                          //System.out.println(n.getCanonicalName() + ": " + n.getKeyPropertyListString());

                          ObjectName queueObjectName2 = new ObjectName(domain+":"+n.getKeyPropertyListString());

                          Iterator it2 = mbsc.getAttributes(queueObjectName2, attributes).asList().iterator();

                          System.out.println("########################NEXT DOMAIN: "+domain+":"+n.getKeyPropertyListString());

                          while (it2.hasNext()) {

                              Attribute att = (Attribute) it2.next();

                              System.out.println("attribute: "+att.getName() + " value: " + att.getValue());

                          }

                         

                      }

                  }

              } catch (Exception e) {

                  e.printStackTrace();

              }

          }

       

      Thanks

        • 1. Re: Calling Qpid JMX from ear deployed in JBoss7.1.2Final
          gte338m Newbie

          Note that Qpid RMI Registry is running on port 8999 that is used in the url.  I was thinking that JBoss would attempt to connect to that port to requrest the jmxrmi stub indentifiedl in the url service:jmx:rmi:///jndi/rmi://localhost:8999/jmxrmi.

           

          Thanks

          • 2. Re: Calling Qpid JMX from ear deployed in JBoss7.1.2Final
            gte338m Newbie

            I found the fix.  I had to add java 1.6 rt.jar to the ejb jar's metadata.mf file and switch code to the following eliminating the use of JMXServiceURL obj.

             

            Hashtable environment = new Hashtable();

                        environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");

                        //environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.url.rmi.rmiURLContextFactory");

                        environment.put(Context.PROVIDER_URL, "rmi://localhost:8999");

                        environment.put(JMXConnector.CREDENTIALS, new String[]{"admin", "admin"});

                        Context c = new InitialContext(environment);

                        javax.management.remote.rmi.RMIServer o = (javax.management.remote.rmi.RMIServer)c.lookup("jmxrmi");

                        RMIConnection mbsc = o.newClient(new String[]{"admin", "admin"});