ActiveMQ_7JMX

时间:2024-06-24 10:06:44

activemq配置jmx

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

activemq.xml配置

修改broker属性

ActiveMQ_7JMX

添加节点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());

}

}

}

}

相关文章