Java操作 ActiveMQ 远程监控JMX设置

activemq.xml设置
第一个配置:
在你下载activemq文件夹下的config中,找到activemq.xml,在broker节点增加useJmx=”true”
useJmx表示开启jmx监控
这里写图片描述

2.在managementContext节点更改

Java操作 ActiveMQ 远程监控JMX设置_第1张图片

3.修改bin/文件夹中的启动脚本activemq

1,Windows

SUNJMX=-Dcom.sun.management.jmxremote.port=11099-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.password.file=%ACTIVEMQ_BASE%/conf/jmx.password \
-Dcom.sun.management.jmxremote.access.file=%ACTIVEMQ_BASE%/conf/jmx.access

Java查询ActiveMQ队列信息

public static void main(String[] args) throws IOException, MalformedObjectNameException {
        String url = "service:jmx:rmi:///jndi/rmi://localhost:11099/jmxrmi";
        JMXServiceURL urls = new JMXServiceURL(url);
        JMXConnector connector = JMXConnectorFactory.connect(urls,null);
        connector.connect();
        MBeanServerConnection conn = connector.getMBeanServerConnection();
        //这里brokerName的b要小些,大写会报错
        ObjectName name = new ObjectName("org.apache.activemq:brokerName=localhost,type=Broker");
        BrokerViewMBean mBean = (BrokerViewMBean)MBeanServerInvocationHandler.newProxyInstance(conn, name, BrokerViewMBean.class, true);
        for(ObjectName na : mBean.getQueues()){//获取点对点的队列       mBean.getTopics() 获取订阅模式的队列
            QueueViewMBean queueBean = (QueueViewMBean) 
            MBeanServerInvocationHandler.newProxyInstance(conn, na, QueueViewMBean.class, true);
            System.out.println("******************************");
            System.out.println("队列的名称:"+queueBean.getName());
            System.out.println("队列中剩余的消息数:"+queueBean.getQueueSize());
            System.out.println("消费者数:"+queueBean.getConsumerCount());
            System.out.println("出队列的数量:"+queueBean.getDequeueCount());
        }
    }

Java操作 ActiveMQ 远程监控JMX设置_第2张图片

你可能感兴趣的:(java)