linux下的设置:
1.cat /etc/hosts 检查hosts文件设置,不用127.0.0.1,用实际IP地址
12.32.234.21 localhost localhost.localdomain localhost4 localhost4.localdomain4
2.${ACTIVEMQ_HOME}/conf/activemq.xml 中的 broker 节点增加 useJmx=”true” 属性
3.${ACTIVEMQ_HOME}/conf/activemq.xml 中的 managementContext 节点修改成如下样子
connectorPort="11099"要加上,否则出现Java.lang.RuntimeException: java.rmi.ConnectException: Connection refused to host: 127.0.0.1的错误
4.chmod 400 /opt/activemq/conf/jmx.*
注意事项: jmx.password和jmx.access 文件权限必须是当前用户只读(也就是400)否则会使得activemq无法启动,而且没有任何地方报错。
5.activemq设置:
ACTIVEMQ_SUNJMX_START="-Dcom.sun.management.jmxremote.port=11099 "ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.password.file=${ACTIVEMQ_CONF}/jmx.password"ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.access.file=${ACTIVEMQ_CONF}/jmx.access"ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.ssl=false"
6.重新启动activemq
/usr/local/activemq/bin/activemq stop/usr/local/activemq/bin/activemq start
观察端口
netstat –nltp|grep 11099
查看11099端口是否开启监控
使用jconsole连接(path:C:\Program Files\Java\jdk1.6.0_16\bin\jconsole.exe)
运行jconsole.exe
在远程进程连接填入
12.32.234.21:11099
再填入用户名和密码admin和activemq(jmx.password里的内容)即可连接
7, 测试方法
public static List<QueueInfoVO> getQueueInfoList(String mqIpAddress, String rmiPort) throws Exception {List<QueueInfoVO> result = new ArrayList<QueueInfoVO>();RemoteJMXBrokerFacade createConnector = new RemoteJMXBrokerFacade();// 填写链接属性System.setProperty("webconsole.jmx.url", "service:jmx:rmi:///jndi/rmi://" + mqIpAddress + ":" + rmiPort+ "/jmxrmi");System.setProperty("webconsole.jmx.user", "admin");System.setProperty("webconsole.jmx.password", "activemq");// 创建配置SystemPropertiesConfiguration configuration = new SystemPropertiesConfiguration();// 创建链接createConnector.setConfiguration(configuration);Collection<QueueViewMBean> queueViewList = createConnector.getQueues();for (QueueViewMBean queueViewMBean : queueViewList) {QueueInfoVO vo = new QueueInfoVO();vo.setQueueName(queueViewMBean.getName());// 名称vo.setQueueSize(queueViewMBean.getQueueSize());// 待消费消息vo.setConsumerCount(queueViewMBean.getConsumerCount());// 消费者vo.setEnqueueCount(queueViewMBean.getEnqueueCount());// 入列消息vo.setDequeueCount(queueViewMBean.getDequeueCount());// 出列消息result.add(vo);}return result;}
