JMX监控ActiveMq消息队列剩余数量

activemq.xml

是否使用jmx

<broker xmlns="http://activemq.apache.org/schema/core" brokerName="activemq-jf" dataDirectory="${activemq.data}" useJmx="true">

配置连接端口,jmxDomainName

<managementContext>

            <managementContext createConnector="true" connectorPort="11091"  connectorPath="/jmxrmi" jmxDomainName="org.apache.activemq"/>

          </managementContext>

 

启动参数添加:

ACTIVEMQ_SUNJMX_START="-Dcom.sun.management.jmxremote.port=11091 "

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"

 

Java代码

String urlStr =" service:jmx:rmi:///jndi/rmi://10.1.0.206:11091/jmxrmi";

JMXServiceURL urls = new JMXServiceURL(urlStr);

        JMXConnector connector = JMXConnectorFactory.connect(urls, null);

        connector.connect();

        MBeanServerConnection conn = connector.getMBeanServerConnection();

        //这里brokerName的b要小些,大写会报错

        ObjectName name = new ObjectName("org.apache.activemq:brokerName=activemq-jf,type=Broker");

        BrokerViewMBean mBean = (BrokerViewMBean) MBeanServerInvocationHandler.newProxyInstance

                (conn, name, BrokerViewMBean.class, true);

        for (ObjectName na : mBean.getQueues()) {

            QueueViewMBean queueBean = (QueueViewMBean) MBeanServerInvocationHandler.newProxyInstance

                    (conn, na, QueueViewMBean.class, true);

            if (queueBean.getName().equals(queueName)) {

                if(logger.isDebugEnabled()){

                    logger.debug(GlobalFunc.strCat(queueName,"的积压量:",queueBean.getQueueSize()));

                }

                return queueBean.getQueueSize();

            }

        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值