0 Replies Latest reply on Nov 8, 2018 1:33 PM by Kevin Stone

    Wildfly 10 JMX get queues and message counts - code snippet with Exception

    Kevin Stone Newbie
      HashMap<string,string[]> environment = new HashMap<string,string[]>();
      String urlString = "service:jmx:remote+http:/<SERVER_IP>/<server_ip>:9990";
      String[] credentials = new String[] {"xxx","yyy"};
      environment.put(JMXConnector.CREDENTIALS, credentials);
      try {
          JMXConnector conn = JMXConnectorFactory.connect(new JMXServiceURL(urlString), environment);
          MBeanServerConnection  server = conn.getMBeanServerConnection();
          if (server != null) {
              log.info("============== MBean Server found! =================");
         }
         ObjectName filterName = new ObjectName("jboss.as:*");
          Set names = server.queryNames(filterName, null);
          for (ObjectName n : names) {
              if (n.getCanonicalName().toLowerCase().startsWith("jboss.as:core-address=jms.queue")) {
      
                  String qName = n.getKeyProperty("core-address");
                  qName = qName.replace("jms.queue.","");
                  log.info("QUEUE NAME: " + qName);
                  SimpleString address = new SimpleString(queueName);
                  SimpleString name = new SimpleString(queueName);
                  ObjectName on = ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name);
                  JMSQueueControl qc = (JMSQueueControl) MBeanServerInvocationHandler.newProxyInstance(server, on, JMSQueueControl.class, false);
                  log.info("Get message count " + qc);
                  long x = qc.getMessageCount();   // Error occurs here!
                  log.info("Got Message Count");
              }
          }
      }
      catch (Exception ex) {
        ex.printStackTrace();
      }

      /*

      INFO  [QueueWatcher] (default task-74) ============== MBean Server found! =================

      INFO  [QueueWatcher] (default task-74) QUEUE NAME: TestQueue

      INFO  [QueueWatcher] (default task-74) Get message count MBeanProxy(org.jboss.remotingjmx.protocol.v2.ClientConnection$TheConnection@48f2ff00[org.apache.activemq.artemis:module=Core,type=Queue,address="TestQueue",name="TestQueue"])

      ERROR [stderr] (default task-74) javax.management.InstanceNotFoundException: org.apache.activemq.artemis:module=Core,type=Queue,address="TestQueue",name="TestQueue"

      ERROR [stderr] (default task-74)        at org.jboss.as.jmx.PluggableMBeanServerImpl.findDelegate(PluggableMBeanServerImpl.java:1110)

      ERROR [stderr] (default task-74)        at org.jboss.as.jmx.PluggableMBeanServerImpl.getAttribute(PluggableMBeanServerImpl.java:386)

      ERROR [stderr] (default task-74)        at org.jboss.as.jmx.BlockingNotificationMBeanServer.getAttribute(BlockingNotificationMBeanServer.java:148)

      ERROR [stderr] (default task-74)        at org.jboss.remotingjmx.protocol.v2.ServerProxy$GetAttributeHandler.handle(ServerProxy.java:689)

      ERROR [stderr] (default task-74)        at org.jboss.remotingjmx.protocol.v2.ServerCommon$MessageReciever$1$1.run(ServerCommon.java:153)

      ERROR [stderr] (default task-74)        at org.jboss.as.jmx.ServerInterceptorFactory$Interceptor$1.run(ServerInterceptorFactory.java:75)

      ERROR [stderr] (default task-74)        at org.jboss.as.jmx.ServerInterceptorFactory$Interceptor$1.run(ServerInterceptorFactory.java:70)

      ERROR [stderr] (default task-74)        at java.security.AccessController.doPrivileged(Native Method)

      ERROR [stderr] (default task-74)        at javax.security.auth.Subject.doAs(Subject.java:422)

      ERROR [stderr] (default task-74)        at org.jboss.as.controller.AccessAuditContext.doAs(AccessAuditContext.java:149)

      ERROR [stderr] (default task-74)        at org.jboss.as.jmx.ServerInterceptorFactory$Interceptor.handleEvent(ServerInterceptorFactory.java:70)

      ERROR [stderr] (default task-74)        at org.jboss.remotingjmx.protocol.v2.ServerCommon$MessageReciever$1.run(ServerCommon.java:149)

      ERROR [stderr] (default task-74)        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

      ERROR [stderr] (default task-74)        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

      ERROR [stderr] (default task-74)        at java.lang.Thread.run(Thread.java:748)

      */

       

      Anybody know why I am getting this exception?  In fact the exception happens when I invoke any of the methods on the JMSQueueControl object (qc).   If I don't get the message count it prints all the queues just fine.

       

      thanks

      -kevin