ActiveMQ_7JMX

2018-12-14 08:36:18来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

activemq配置jmx

       配置activemq中的jmx可以用于监控activemq信息。

 

activemq.xml配置

       修改broker属性

 

       添加节点managementContext

<managementContext>

            <managementContext createConnector="true" connectorPort="1099" connectorPath="/jmxrmi" jmxDomainName="myDomain"/>

        </managementContext>

 

activemq启动项配置

ACTIVEMQ_SUNJMX_START="-Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false \

    -Dcom.sun.management.jmxremote.rmi.port=1099 \

    -Dcom.sun.management.jmxremote.authenticate=false \

    -Djava.rmi.server.hostname=192.168.114.129"

 

jconsole连接测试

 

 

java连接测试

public class QueueList {

    private static String connectorPort="1099";

    private static String connectorPath="/jmxrmi";

    private static String jmxDomain="myDomain";

   

    @Test

    public void getQueueInfoList() throws Exception{

       LocateRegistry.createRegistry(1099);

       JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://192.168.114.129:"+connectorPort+connectorPath);   

       JMXConnector connector = JMXConnectorFactory.connect(url);

       connector.connect();

       MBeanServerConnection connection = connector.getMBeanServerConnection();

       ObjectName name = new ObjectName(jmxDomain+":type=Broker,brokerName=broker1");

       BrokerViewMBean mBean = MBeanServerInvocationHandler.newProxyInstance(connection, name, BrokerViewMBean.class, true);   

       System.out.println("-----queue数:"+mBean.getQueues().length);

       if(mBean != null){

           for(ObjectName na: mBean.getQueues()){

              QueueViewMBean qBean = MBeanServerInvocationHandler.newProxyInstance(connection, na, QueueViewMBean.class, true);

              System.out.println("--------------->");

              System.out.println("消息队列名称:"+qBean.getName());

              System.out.println("队列中剩余的消息数:"+qBean.getQueueSize());

              System.out.println("消费者数:"+qBean.getConsumerCount());

              System.out.println("出队数:"+qBean.getDequeueCount());

              System.out.println("入队列数:"+qBean.getEnqueueCount());

           }

       }

       System.out.println("-----topic数:"+mBean.getTopics().length);

       if(mBean != null){

           for(ObjectName na: mBean.getTopics()){

              QueueViewMBean qBean = MBeanServerInvocationHandler.newProxyInstance(connection, na, QueueViewMBean.class, true);

              System.out.println("--------------->");

              System.out.println("消息队列名称:"+qBean.getName());

              System.out.println("队列中剩余的消息数:"+qBean.getQueueSize());

              System.out.println("消费者数:"+qBean.getConsumerCount());

              System.out.println("出队数:"+qBean.getDequeueCount());

             

           }

       }

    }

}

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:ActiveMQ_6持久化

下一篇:记录小白实习生的HashMap源码 put元素 的学习和一些疑问