activemq配置jmx 配置activemq中的jmx可以用於監控activemq信息。 activemq.xml配置 修改broker屬性 添加節點managementContext <managementContext> <managementContext createConnector= ...
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());
}
}
}
}