RabbitMQ学习之队列监控
来源:互联网 发布:java中isnotempty 编辑:程序博客网 时间:2024/06/05 16:01
对于RabbitMQ的监控,除了服务器基本信息(硬盘、CPU、内存、IO等)以及MQ的进程和端口,我们也可以通过请求url访问管理页面监控其集群和队列的情况。在java api 3.6.0以后,channel接口为我们提供了如下接口:
/** * Returns the number of messages in a queue ready to be delivered * to consumers. This method assumes the queue exists. If it doesn't, * an exception will be closed with an exception. * @param queue the name of the queue * @return the number of messages in ready state * @throws IOException Problem transmitting method. */ long messageCount(String queue) throws IOException; /** * Returns the number of consumers on a queue. * This method assumes the queue exists. If it doesn't, * an exception will be closed with an exception. * @param queue the name of the queue * @return the number of consumers * @throws IOException Problem transmitting method. */ long consumerCount(String queue) throws IOException;
messageCount:查询队列未消费的消息数,可以监控消息堆积的情况。
consumerCount:队列的消费者个数,可以对消费者进行监控
java实例:
public class JavaAPIMonitor { private static String queue_name = "test_queue"; public static void main(String[] args) throws Exception { ConnectionFactory factory = new ConnectionFactory(); // amqp://userName:password@hostName:portNumber/virtualHost factory.setUri("amqp://test:test@10.1.199.169:5672/test"); Connection conn = factory.newConnection(); // System.out.println(conn.getChannelMax()); Channel channel = conn.createChannel(); // System.out.println(channel.getChannelNumber()); System.out.println(channel.messageCount(queue_name)); System.out.println(channel.consumerCount(queue_name)); channel.close(); conn.close(); }}运行结果:2777823
除此之外,也可以通过连接的状态变化,进行监控,如:连接被阻塞(内存,CPU等不足)
ConnectionFactory factory = new ConnectionFactory(); Connection connection = factory.newConnection(); connection.addBlockedListener(new BlockedListener() { public void handleUnblocked() throws IOException { // 连接取消阻塞 } public void handleBlocked(String reason) throws IOException { // 连接阻塞 } }); connection.addShutdownListener(new ShutdownListener() { public void shutdownCompleted(ShutdownSignalException cause) { //连接关闭 } });
先关监控参考文章:
1.RabbitMQ之管理与监控
2.REST API监控RabbitMQ
3.如何监控RabbitMQ
0 0
- RabbitMQ学习之队列监控
- RabbitMQ学习之延时队列
- RabbitMQ学习之延时队列
- RabbitMQ学习之工作队列(java)
- RabbitMQ学习之二: 工作队列实践
- RabbitMQ之监控
- RabbitMQ之监控(2)
- RabbitMQ之监控(3)
- RabbitMQ之工作队列
- RabbitMQ之死信队列
- RabbitMQ之队列优先级
- 队列工厂之RabbitMQ
- RabbitMQ之队列
- RabbitMQ学习(二)之工作队列(java)
- RabbitMQ之管理与监控
- 消息队列 rabbitmq 学习 记录
- 消息队列之--kafka ----rabbitMQ
- 2.rabbitmq之工作队列
- python学习笔记-类和实例
- Swift笔记-让你2小时学会Swift
- 【目标跟踪: 相关滤波器 四】相关滤波
- 数据结构-模式匹配串算法(KMP)
- 用C++画矩形
- RabbitMQ学习之队列监控
- maven 光速入门攻略03
- JavaScript的Date()对象中的方法
- 提个问题:从技术到人生
- 自定义功能模块设计
- 数据结构-多项式计算(栈实现)
- 胡适资助林语堂出国留学的故事
- 帧同步
- 关键字 解读tomcat服务器