JMX操作ActiveMQ(1)
我们知道ActiveMQ broker的管理接口是通过JMX方式提供的。
一个简单的访问方式就是通过jconsole,输入
- 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中都提供了什么东西。
- package kk;
- import java.util.Iterator;
- import java.util.Set;
- import javax.management.MBeanAttributeInfo;
- import javax.management.MBeanInfo;
- import javax.management.MBeanOperationInfo;
- import javax.management.MBeanServerConnection;
- import javax.management.ObjectInstance;
- import javax.management.ObjectName;
- import javax.management.remote.JMXConnector;
- import javax.management.remote.JMXConnectorFactory;
- import javax.management.remote.JMXServiceURL;
- public class TestJMX {
- public static void main(String[] args) throws Exception {
- String surl = "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi";
- JMXServiceURL url = new JMXServiceURL(surl);
- JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
- MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
- System.out.println("Domains:---------------");
- String domains[] = mbsc.getDomains();
- for (int i = 0; i < domains.length; i++) {
- System.out.println("\tDomain[" + i + "] = " + domains[i]);
- }
- System.out.println("all ObjectName:---------------");
- Set<ObjectInstance> set = mbsc.queryMBeans(null, null);
- for (Iterator<ObjectInstance> it = set.iterator(); it.hasNext();) {
- ObjectInstance oi = (ObjectInstance) it.next();
- System.out.println("\t" + oi.getObjectName());
- }
- System.out.println("org.apache.activemq:BrokerName=localhost,Type=Broker:---------------");
- ObjectName mbeanName = new ObjectName("org.apache.activemq:BrokerName=localhost,Type=Broker");
- MBeanInfo info = mbsc.getMBeanInfo(mbeanName);
- System.out.println("Class: " + info.getClassName());
- if (info.getAttributes().length > 0){
- for(MBeanAttributeInfo m : info.getAttributes())
- System.out.println("\t ==> Attriber:" + m.getName());
- }
- if (info.getOperations().length > 0){
- for(MBeanOperationInfo m : info.getOperations())
- System.out.println("\t ==> Operation:" + m.getName());
- }
- jmxc.close();
- }
- }
输出结果:
- Domains:---------------
- Domain[0] = JMImplementation
- Domain[1] = com.sun.management
- Domain[2] = java.lang
- Domain[3] = org.apache.activemq
- Domain[4] = java.util.logging
- all ObjectName:---------------
- java.lang:type=OperatingSystem
- java.lang:type=MemoryPool,name=Perm Gen
- java.lang:type=Memory
- JMImplementation:type=MBeanServerDelegate
- 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
- org.apache.activemq:BrokerName=localhost,Type=Connection,ConnectorName=openwire,Connection=ID_bsb3-1381-1372146822218-0_1
- 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
- org.apache.activemq:BrokerName=localhost,Type=Connection,ConnectorName=openwire,ViewType=address,Name=tcp_//127.0.0.1_1347
- java.lang:type=GarbageCollector,name=MarkSweepCompact
- org.apache.activemq:BrokerName=localhost,Type=Broker
- org.apache.activemq:BrokerName=localhost,Type=Topic,Destination=ActiveMQ.Advisory.Producer.Topic.kk.dp
- org.apache.activemq:BrokerName=localhost,Type=Topic,Destination=ActiveMQ.Advisory.Topic
- java.lang:type=MemoryManager,name=CodeCacheManager
- org.apache.activemq:BrokerName=localhost,Type=Topic,Destination=ActiveMQ.Advisory.Connection
- org.apache.activemq:BrokerName=localhost,Type=Topic,Destination=ActiveMQ.Advisory.Queue
- org.apache.activemq:BrokerName=localhost,Type=Topic,Destination=ActiveMQ.Advisory.Consumer.Topic.kk.dp
- org.apache.activemq:BrokerName=localhost,Type=Connection,ConnectorName=openwire,Connection=ID_bsb3-1346-1372146798953-0_1
- java.lang:type=Compilation
- org.apache.activemq:BrokerName=localhost,Type=Connection,ConnectorName=openwire,ViewType=address,Name=tcp_//127.0.0.1_1382
- java.util.logging:type=Logging
- java.lang:type=MemoryPool,name=Tenured Gen
- 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
- java.lang:type=MemoryPool,name=Survivor Space
- java.lang:type=Runtime
- org.apache.activemq:BrokerName=localhost,Type=Topic,Destination=ActiveMQ.Advisory.Producer.Queue.kk.qq
- java.lang:type=GarbageCollector,name=Copy
- org.apache.activemq:BrokerName=localhost,Type=Queue,Destination=kk.qq
- org.apache.activemq:BrokerName=localhost,Type=Subscription,persistentMode=Durable,subscriptionID=kk-dp-dc,destinationType=Topic,destinationName=kk.dp,clientId=kk-dp
- java.lang:type=MemoryPool,name=Eden Space
- org.apache.activemq:BrokerName=localhost,Type=Topic,Destination=ActiveMQ.Advisory.Consumer.Queue.kk.qq
- java.lang:type=Threading
- org.apache.activemq:BrokerName=localhost,Type=Topic,Destination=kk.dp
- com.sun.management:type=HotSpotDiagnostic
- java.lang:type=ClassLoading
- 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
- java.lang:type=MemoryPool,name=Code Cache
- org.apache.activemq:BrokerName=localhost,Type=Connector,ConnectorName=openwire
- org.apache.activemq:BrokerName=localhost,Type=Broker:---------------
- Class: org.apache.activemq.broker.jmx.BrokerView
- ==> Attriber:Uptime
- ==> Attriber:BrokerVersion
- ==> Attriber:Slave
- ==> Attriber:BrokerName
- ==> Attriber:Persistent
- ==> Attriber:TransportConnectors
- ==> Attriber:BrokerId
- ==> Attriber:Topics
- ==> Attriber:Queues
- ==> Attriber:TemporaryTopics
- ==> Attriber:TemporaryQueues
- ==> Attriber:TopicSubscribers
- ==> Attriber:DurableTopicSubscribers
- ==> Attriber:QueueSubscribers
- ==> Attriber:TemporaryTopicSubscribers
- ==> Attriber:TemporaryQueueSubscribers
- ==> Attriber:InactiveDurableTopicSubscribers
- ==> Attriber:TopicProducers
- ==> Attriber:QueueProducers
- ==> Attriber:TemporaryTopicProducers
- ==> Attriber:TemporaryQueueProducers
- ==> Attriber:DynamicDestinationProducers
- ==> Attriber:TotalEnqueueCount
- ==> Attriber:TotalDequeueCount
- ==> Attriber:TotalConsumerCount
- ==> Attriber:TotalProducerCount
- ==> Attriber:TotalMessageCount
- ==> Attriber:MemoryPercentUsage
- ==> Attriber:MemoryLimit
- ==> Attriber:StoreLimit
- ==> Attriber:StorePercentUsage
- ==> Attriber:TempLimit
- ==> Attriber:TempPercentUsage
- ==> Attriber:StatisticsEnabled
- ==> Attriber:OpenWireURL
- ==> Attriber:StompURL
- ==> Attriber:SslURL
- ==> Attriber:StompSslURL
- ==> Attriber:VMURL
- ==> Attriber:DataDirectory
- ==> Attriber:JMSJobScheduler
- ==> Operation:gc
- ==> Operation:stop
- ==> Operation:enableStatistics
- ==> Operation:addConnector
- ==> Operation:removeConnector
- ==> Operation:addNetworkConnector
- ==> Operation:removeNetworkConnector
- ==> Operation:stopGracefully
- ==> Operation:resetStatistics
- ==> Operation:disableStatistics
- ==> Operation:terminateJVM
- ==> Operation:addTopic
- ==> Operation:addQueue
- ==> Operation:removeTopic
- ==> Operation:removeQueue
- ==> Operation:createDurableSubscriber
- ==> Operation:destroyDurableSubscriber
- ==> Operation:reloadLog4jProperties
- ==> Operation:getTransportConnectorByType
- ==> Operation:start
上面只是拿到了broker的属性和操作,同理也可以拿到其它对象的属性和操作列表。
根据这些,我们就可以拿到broker,connector,producer,consumer,queue,topic,Subscription等等的Object对象,进一步的操作他们。
待续。
JMX操作ActiveMQ(1)的更多相关文章
- JMX操作ActiveMQ(2)
默认情况下,ActiveMQ使用useJmx后,jmx的url为 service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi 这时,jmx的MBean se ...
- cassandra高级操作之JMX操作
需求场景 项目中有这么个需求:统计集群中各个节点的数据量存储大小,不是记录数. 一开始有点无头绪,后面查看cassandra官方文档看到Monitoring章节,里面说到:Cassandra中的指标使 ...
- 消息中间件系列之Java API操作ActiveMQ
一.依赖 <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activem ...
- JMX操作实例--做一回技术控
我来做一回技术控,这部分内容也是简单的API调用例子而已,做一回技术控,发点小骚文,不过你看了,也许知道JConsole是怎么做出来的了,呵呵! 先不用管他干什么,代码运行后,自己改改自然知道做什么的 ...
- ActiveMQ in Action(1) - JMS
关键字: activemq 1 JMS 在介绍ActiveMQ之前,首先简要介绍一下JMS规范.1.1 JMS的基本构件1.1.1 连接工厂 连接工厂是客户用来创建连接的对象,例如Acti ...
- ActiveMQ 基于zookeeper的主从(levelDB Master/Slave)搭建以及Spring-boot下使用
0:说明 ActiveMQ 5.9.0新推出的主从实现,基于zookeeper来选举出一个master,其他节点自动作为slave实时同步消息.因为有实时同步数据的slave的存在,master不用担 ...
- ActiveMQ (一):安装启动及测试
1. 预备知识 1.1 JMS JMS(Java Messaging Service)是Java平台上有关面向消息中间件(MOM)的技术规范.<百科> 1.2 JMX JMX(Java M ...
- activemq用户手册
1 JMS 在介绍ActiveMQ之前,首先简要介绍一下JMS规范. 1.1 JMS的基本构件 1.1.1 连接工厂 连接工厂是客户用来创建连接的对象,例如ActiveMQ提供的ActiveMQCon ...
- 转--activemq的官方中文文档
1 JMS 在介绍ActiveMQ之前,首先简要介绍一下JMS规范. 1.1 JMS的基本构件 1.1.1 连接工厂 连接工厂是客户用来创建连接的对象,例如ActiveMQ提供的ActiveMQCon ...
随机推荐
- SQL Server 2008中文企业版下载地址和序列号[转]
SQLSERVER2008下载链接http://sqlserver.dlservice.microsoft.com/dl/download/B/8/0/B808AF59-7619-4A71-A447- ...
- 总结NHibernate 中删除数据的几种方法
今天下午有人在QQ群上问在NHibernate上如何根据条件删除多条数据,于是我自己就写了些测试代码,并总结了一下NHibernate中删除数据的方式,做个备忘.不过不能保证囊括所有的方式,如果还有别 ...
- 前端project师,确定你的目标吧!无能的人才管他叫命运
导语: 你为自己定过一个不靠谱的目标,是20年前的事了吧. 长大你想干什么?你的回答是什么?现在实现了吗? 如今,你每天都坐在同一个格子间的同一个电脑前,会不会感到每天都像是在复印,感到前途是模糊的, ...
- [课堂实践与项目]NavigationController与TabBarController的综合使用及易错点分析(包含消息提醒,app更新)
陈述:我们在使用tabbarController的时候,我们总会和NavagationController联合起来.但是不联合的时候又是什么样的一种pool的情况呢?我们就单单的 TabBarCont ...
- MEAN栈开发
Nodejs之MEAN栈开发(二)----视图与模型 2016-06-02 08:30 by stoneniqiu, 92 阅读, 2 评论, 收藏, 编辑 上一节做了对Express做了简单的介绍, ...
- Delphi - XP扫雷外挂制作
技术交流,DH讲解. 本来之前就在写这个文章,还写了War3挂的教程,后来因为一些事就没有弄了.现在过年在家又没有事就继续把这个写完吧.哈哈.不要以为写个挂很容易,要想写个挂肯定要了解游戏呀.我们现在 ...
- perl 循环类选择器 ,爬取内容
jrhmpt01:/root/lwp/0526# cat 0526.txt <div class="TXD_sy_title"><span class=" ...
- uvc摄像头代码解析5
8.初始化uvc控制 8.1 重要结构体 struct uvc_control { //uvc控制 struct uvc_entity *entity; //uvc实体 struct uvc_cont ...
- vs2012 不显示最近项目
visual studio起始页不显示最近使用项目的解决办法方法一 1.开始 → 运行 → 输入 regedit 回车,打开注册表编辑器. 2.定位到 HKEY_CURRENT_USER/Softwa ...
- WinExec函数,启动其他应用程序
WinExec The WinExec function runs the specified application. Note This function is provided only fo ...