我们知道ActiveMQ broker的管理接口是通过JMX方式提供的。

一个简单的访问方式就是通过jconsole,输入

  1. service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi

需要注意的是:

1、默认JMX功能是没有打开的,需要在activemq.xml的broker配置上添加useJmx="true"

2、需要在managementContext里,修改为createConnector="true",(同时这里也可以修改jmx的端口和domain)

(参见http://activemq.apache.org/jmx.html

通过jconsole来操作还是不太方便。特别是某些时候我们需要把对broker和queue的管理集成到我们的管理系统中去。

这时候我们就需要通过JMX的编程接口来与broker进行交互了。

可以先写一个小程序,看看broker的jmx中都提供了什么东西。

  1. package kk;
  2.  
  3. import java.util.Iterator;
  4. import java.util.Set;
  5.  
  6. import javax.management.MBeanAttributeInfo;
  7. import javax.management.MBeanInfo;
  8. import javax.management.MBeanOperationInfo;
  9. import javax.management.MBeanServerConnection;
  10. import javax.management.ObjectInstance;
  11. import javax.management.ObjectName;
  12. import javax.management.remote.JMXConnector;
  13. import javax.management.remote.JMXConnectorFactory;
  14. import javax.management.remote.JMXServiceURL;
  15.  
  16. public class TestJMX {
  17.  
  18. public static void main(String[] args) throws Exception {
  19.  
  20. String surl = "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi";
  21.  
  22. JMXServiceURL url = new JMXServiceURL(surl);
  23. JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
  24. MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
  25.  
  26. System.out.println("Domains:---------------");
  27. String domains[] = mbsc.getDomains();
  28. for (int i = 0; i < domains.length; i++) {
  29. System.out.println("\tDomain[" + i + "] = " + domains[i]);
  30. }
  31.  
  32. System.out.println("all ObjectName:---------------");
  33. Set<ObjectInstance> set = mbsc.queryMBeans(null, null);
  34. for (Iterator<ObjectInstance> it = set.iterator(); it.hasNext();) {
  35. ObjectInstance oi = (ObjectInstance) it.next();
  36. System.out.println("\t" + oi.getObjectName());
  37. }
  38.  
  39. System.out.println("org.apache.activemq:BrokerName=localhost,Type=Broker:---------------");
  40. ObjectName mbeanName = new ObjectName("org.apache.activemq:BrokerName=localhost,Type=Broker");
  41. MBeanInfo info = mbsc.getMBeanInfo(mbeanName);
  42. System.out.println("Class: " + info.getClassName());
  43. if (info.getAttributes().length > 0){
  44. for(MBeanAttributeInfo m : info.getAttributes())
  45. System.out.println("\t ==> Attriber:" + m.getName());
  46. }
  47. if (info.getOperations().length > 0){
  48. for(MBeanOperationInfo m : info.getOperations())
  49. System.out.println("\t ==> Operation:" + m.getName());
  50. }
  51.  
  52. jmxc.close();
  53.  
  54. }
  55.  
  56. }

输出结果:

  1. Domains:---------------
  2. Domain[0] = JMImplementation
  3. Domain[1] = com.sun.management
  4. Domain[2] = java.lang
  5. Domain[3] = org.apache.activemq
  6. Domain[4] = java.util.logging
  7. all ObjectName:---------------
  8. java.lang:type=OperatingSystem
  9. java.lang:type=MemoryPool,name=Perm Gen
  10. java.lang:type=Memory
  11. JMImplementation:type=MBeanServerDelegate
  12. org.apache.activemq:BrokerName=localhost,Type=Producer,destinationType=Queue,destinationName=kk.qq,clientId=ID_bsb3-1381-1372146822218-0_1,producerId=ID_bsb3-1381-1372146822218-1_1_1_1
  13. org.apache.activemq:BrokerName=localhost,Type=Connection,ConnectorName=openwire,Connection=ID_bsb3-1381-1372146822218-0_1
  14. org.apache.activemq:BrokerName=localhost,Type=Subscription,persistentMode=Non-Durable,destinationType=Queue,destinationName=kk.qq,clientId=ID_bsb3-1381-1372146822218-0_1,consumerId=ID_bsb3-1381-1372146822218-1_1_1_1
  15. org.apache.activemq:BrokerName=localhost,Type=Connection,ConnectorName=openwire,ViewType=address,Name=tcp_//127.0.0.1_1347
  16. java.lang:type=GarbageCollector,name=MarkSweepCompact
  17. org.apache.activemq:BrokerName=localhost,Type=Broker
  18. org.apache.activemq:BrokerName=localhost,Type=Topic,Destination=ActiveMQ.Advisory.Producer.Topic.kk.dp
  19. org.apache.activemq:BrokerName=localhost,Type=Topic,Destination=ActiveMQ.Advisory.Topic
  20. java.lang:type=MemoryManager,name=CodeCacheManager
  21. org.apache.activemq:BrokerName=localhost,Type=Topic,Destination=ActiveMQ.Advisory.Connection
  22. org.apache.activemq:BrokerName=localhost,Type=Topic,Destination=ActiveMQ.Advisory.Queue
  23. org.apache.activemq:BrokerName=localhost,Type=Topic,Destination=ActiveMQ.Advisory.Consumer.Topic.kk.dp
  24. org.apache.activemq:BrokerName=localhost,Type=Connection,ConnectorName=openwire,Connection=ID_bsb3-1346-1372146798953-0_1
  25. java.lang:type=Compilation
  26. org.apache.activemq:BrokerName=localhost,Type=Connection,ConnectorName=openwire,ViewType=address,Name=tcp_//127.0.0.1_1382
  27. java.util.logging:type=Logging
  28. java.lang:type=MemoryPool,name=Tenured Gen
  29. org.apache.activemq:BrokerName=localhost,Type=Subscription,persistentMode=Non-Durable,destinationType=Topic,destinationName=ActiveMQ.Advisory.TempQueue_ActiveMQ.Advisory.TempTopic,clientId=ID_bsb3-1346-1372146798953-0_1,consumerId=ID_bsb3-1346-1372146798953-1_1_-1_1
  30. java.lang:type=MemoryPool,name=Survivor Space
  31. java.lang:type=Runtime
  32. org.apache.activemq:BrokerName=localhost,Type=Topic,Destination=ActiveMQ.Advisory.Producer.Queue.kk.qq
  33. java.lang:type=GarbageCollector,name=Copy
  34. org.apache.activemq:BrokerName=localhost,Type=Queue,Destination=kk.qq
  35. org.apache.activemq:BrokerName=localhost,Type=Subscription,persistentMode=Durable,subscriptionID=kk-dp-dc,destinationType=Topic,destinationName=kk.dp,clientId=kk-dp
  36. java.lang:type=MemoryPool,name=Eden Space
  37. org.apache.activemq:BrokerName=localhost,Type=Topic,Destination=ActiveMQ.Advisory.Consumer.Queue.kk.qq
  38. java.lang:type=Threading
  39. org.apache.activemq:BrokerName=localhost,Type=Topic,Destination=kk.dp
  40. com.sun.management:type=HotSpotDiagnostic
  41. java.lang:type=ClassLoading
  42. org.apache.activemq:BrokerName=localhost,Type=Subscription,persistentMode=Non-Durable,destinationType=Topic,destinationName=ActiveMQ.Advisory.TempQueue_ActiveMQ.Advisory.TempTopic,clientId=ID_bsb3-1381-1372146822218-0_1,consumerId=ID_bsb3-1381-1372146822218-1_1_-1_1
  43. java.lang:type=MemoryPool,name=Code Cache
  44. org.apache.activemq:BrokerName=localhost,Type=Connector,ConnectorName=openwire
  45. org.apache.activemq:BrokerName=localhost,Type=Broker:---------------
  46. Class: org.apache.activemq.broker.jmx.BrokerView
  47. ==> AttriberUptime
  48. ==> AttriberBrokerVersion
  49. ==> AttriberSlave
  50. ==> AttriberBrokerName
  51. ==> AttriberPersistent
  52. ==> AttriberTransportConnectors
  53. ==> AttriberBrokerId
  54. ==> AttriberTopics
  55. ==> AttriberQueues
  56. ==> AttriberTemporaryTopics
  57. ==> AttriberTemporaryQueues
  58. ==> AttriberTopicSubscribers
  59. ==> AttriberDurableTopicSubscribers
  60. ==> AttriberQueueSubscribers
  61. ==> AttriberTemporaryTopicSubscribers
  62. ==> AttriberTemporaryQueueSubscribers
  63. ==> AttriberInactiveDurableTopicSubscribers
  64. ==> AttriberTopicProducers
  65. ==> AttriberQueueProducers
  66. ==> AttriberTemporaryTopicProducers
  67. ==> AttriberTemporaryQueueProducers
  68. ==> AttriberDynamicDestinationProducers
  69. ==> AttriberTotalEnqueueCount
  70. ==> AttriberTotalDequeueCount
  71. ==> AttriberTotalConsumerCount
  72. ==> AttriberTotalProducerCount
  73. ==> AttriberTotalMessageCount
  74. ==> AttriberMemoryPercentUsage
  75. ==> AttriberMemoryLimit
  76. ==> AttriberStoreLimit
  77. ==> AttriberStorePercentUsage
  78. ==> AttriberTempLimit
  79. ==> AttriberTempPercentUsage
  80. ==> AttriberStatisticsEnabled
  81. ==> AttriberOpenWireURL
  82. ==> AttriberStompURL
  83. ==> AttriberSslURL
  84. ==> AttriberStompSslURL
  85. ==> AttriberVMURL
  86. ==> AttriberDataDirectory
  87. ==> AttriberJMSJobScheduler
  88. ==> Operationgc
  89. ==> Operationstop
  90. ==> OperationenableStatistics
  91. ==> OperationaddConnector
  92. ==> OperationremoveConnector
  93. ==> OperationaddNetworkConnector
  94. ==> OperationremoveNetworkConnector
  95. ==> OperationstopGracefully
  96. ==> OperationresetStatistics
  97. ==> OperationdisableStatistics
  98. ==> OperationterminateJVM
  99. ==> OperationaddTopic
  100. ==> OperationaddQueue
  101. ==> OperationremoveTopic
  102. ==> OperationremoveQueue
  103. ==> OperationcreateDurableSubscriber
  104. ==> OperationdestroyDurableSubscriber
  105. ==> OperationreloadLog4jProperties
  106. ==> OperationgetTransportConnectorByType
  107. ==> Operationstart

上面只是拿到了broker的属性和操作,同理也可以拿到其它对象的属性和操作列表。
根据这些,我们就可以拿到broker,connector,producer,consumer,queue,topic,Subscription等等的Object对象,进一步的操作他们。

待续。

JMX操作ActiveMQ(1)的更多相关文章

  1. JMX操作ActiveMQ(2)

    默认情况下,ActiveMQ使用useJmx后,jmx的url为 service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi 这时,jmx的MBean se ...

  2. cassandra高级操作之JMX操作

    需求场景 项目中有这么个需求:统计集群中各个节点的数据量存储大小,不是记录数. 一开始有点无头绪,后面查看cassandra官方文档看到Monitoring章节,里面说到:Cassandra中的指标使 ...

  3. 消息中间件系列之Java API操作ActiveMQ

    一.依赖 <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activem ...

  4. JMX操作实例--做一回技术控

    我来做一回技术控,这部分内容也是简单的API调用例子而已,做一回技术控,发点小骚文,不过你看了,也许知道JConsole是怎么做出来的了,呵呵! 先不用管他干什么,代码运行后,自己改改自然知道做什么的 ...

  5. ActiveMQ in Action(1) - JMS

    关键字: activemq 1 JMS    在介绍ActiveMQ之前,首先简要介绍一下JMS规范.1.1 JMS的基本构件1.1.1 连接工厂    连接工厂是客户用来创建连接的对象,例如Acti ...

  6. ActiveMQ 基于zookeeper的主从(levelDB Master/Slave)搭建以及Spring-boot下使用

    0:说明 ActiveMQ 5.9.0新推出的主从实现,基于zookeeper来选举出一个master,其他节点自动作为slave实时同步消息.因为有实时同步数据的slave的存在,master不用担 ...

  7. ActiveMQ (一):安装启动及测试

    1. 预备知识 1.1 JMS JMS(Java Messaging Service)是Java平台上有关面向消息中间件(MOM)的技术规范.<百科> 1.2 JMX JMX(Java M ...

  8. activemq用户手册

    1 JMS 在介绍ActiveMQ之前,首先简要介绍一下JMS规范. 1.1 JMS的基本构件 1.1.1 连接工厂 连接工厂是客户用来创建连接的对象,例如ActiveMQ提供的ActiveMQCon ...

  9. 转--activemq的官方中文文档

    1 JMS 在介绍ActiveMQ之前,首先简要介绍一下JMS规范. 1.1 JMS的基本构件 1.1.1 连接工厂 连接工厂是客户用来创建连接的对象,例如ActiveMQ提供的ActiveMQCon ...

随机推荐

  1. SQL Server 2008中文企业版下载地址和序列号[转]

    SQLSERVER2008下载链接http://sqlserver.dlservice.microsoft.com/dl/download/B/8/0/B808AF59-7619-4A71-A447- ...

  2. 总结NHibernate 中删除数据的几种方法

    今天下午有人在QQ群上问在NHibernate上如何根据条件删除多条数据,于是我自己就写了些测试代码,并总结了一下NHibernate中删除数据的方式,做个备忘.不过不能保证囊括所有的方式,如果还有别 ...

  3. 前端project师,确定你的目标吧!无能的人才管他叫命运

    导语: 你为自己定过一个不靠谱的目标,是20年前的事了吧. 长大你想干什么?你的回答是什么?现在实现了吗? 如今,你每天都坐在同一个格子间的同一个电脑前,会不会感到每天都像是在复印,感到前途是模糊的, ...

  4. [课堂实践与项目]NavigationController与TabBarController的综合使用及易错点分析(包含消息提醒,app更新)

    陈述:我们在使用tabbarController的时候,我们总会和NavagationController联合起来.但是不联合的时候又是什么样的一种pool的情况呢?我们就单单的 TabBarCont ...

  5. MEAN栈开发

    Nodejs之MEAN栈开发(二)----视图与模型 2016-06-02 08:30 by stoneniqiu, 92 阅读, 2 评论, 收藏, 编辑 上一节做了对Express做了简单的介绍, ...

  6. Delphi - XP扫雷外挂制作

    技术交流,DH讲解. 本来之前就在写这个文章,还写了War3挂的教程,后来因为一些事就没有弄了.现在过年在家又没有事就继续把这个写完吧.哈哈.不要以为写个挂很容易,要想写个挂肯定要了解游戏呀.我们现在 ...

  7. perl 循环类选择器 ,爬取内容

    jrhmpt01:/root/lwp/0526# cat 0526.txt <div class="TXD_sy_title"><span class=" ...

  8. uvc摄像头代码解析5

    8.初始化uvc控制 8.1 重要结构体 struct uvc_control { //uvc控制 struct uvc_entity *entity; //uvc实体 struct uvc_cont ...

  9. vs2012 不显示最近项目

    visual studio起始页不显示最近使用项目的解决办法方法一 1.开始 → 运行 → 输入 regedit 回车,打开注册表编辑器. 2.定位到 HKEY_CURRENT_USER/Softwa ...

  10. WinExec函数,启动其他应用程序

    WinExec The WinExec function runs the specified application. Note  This function is provided only fo ...