java activemq jmx_activemq的jmx监控以及死消息的处理

在我使用activemq过程中,遇到两个问题,一个就是有与消费者挂掉,导致磁盘存储满了,使得activemq不能提供服务,第二个是由于消费者异常,导致死消息太多

一、针对第一个问题,我们通过jmx进行监控,监控他的内存使用率,储存使用率,未消费的消息数量

1、在win上开启jmx

修改conf/activemq.xml

connectorPath="/jmxrmi" jmxDomainName="org.apache.activemq"/>

这样就开启了jmx

还有设置用户名密码

2、linux上开启jmx(自己没有试验过)

3、监控代码

public class StateMonitor {

private static final String connectorPort = "1099";

private static final String connectorPath = "/jmxrmi";

public static void main(String[] args) throws Exception {

JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + connectorPort + connectorPath);

JMXConnector connector = JMXConnectorFactory.connect(url);

connector.connect();

MBeanServerConnection connection = connector.getMBeanServerConnection();

ObjectName name = new ObjectName("org.apache.activemq:brokerName=localhost,type=Broker"); //这里面的localhost就是节点名称

BrokerViewMBean mBean = MBeanServerInvocationHandler.newProxyInstance(connection, name, BrokerViewMBean.class, true);

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

QueueViewMBean queueMBean = MBeanServerInvocationHandler.newProxyInstance(connection, queueName, QueueViewMBean.class, true);

System.out.println("\n------------------------------\n");

// 消息队列名称

System.out.println("Queue Name --- " + queueMBean.getName());

// 队列中剩余的消息数

System.out.println("Queue Size --- " + queueMBean.getQueueSize());

// 消费者数

System.out.println("Number of Consumers --- " + queueMBean.getConsumerCount());

// 出队数

System.out.println("Number of Dequeue ---" + queueMBean.getDequeueCount());

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值