发布时间:2019-09-26 07:25:30编辑:auto阅读(1852)
在使用 pika 连接 RabbitMQ 的过程中,发现只能获取 ready 状态的消息数量,只好用 http 请求来实现目的。
#encoding: utf-8 #author: walker #date: 2018-03-06 #summary: 获取 RabbitMQ 中3种状态消息的数量 import os, sys, time import requests import json class RabbitMQTool(object): def __init__(self, host, vhost, queue, user, passwd): self.host = host self.vhost = vhost self.queue = queue self.user = user self.passwd = passwd # 返回3种消息数量:ready, unacked, total def getMessageCount(self): url = 'http://%s:15672/api/queues/%s/%s' % (self.host, self.vhost, self.queue) r = requests.get(url, auth=(self.user, self.passwd)) print(r) if r.status_code != 200: return -1 dic = json.loads(r.text) return dic['messages_ready'], dic['messages_unacknowledged'], dic['messages'] if __name__ == '__main__': mqTool = RabbitMQTool(host = '192.168.0.xx', vhost = 'vhost_walker', queue = 'queue_walker', user = 'walker', passwd = 'walker') ready, unacked, total = mqTool.getMessageCount() print('ready: %d' % ready) print('unacked: %d' % unacked) print('total: %d' % total)
*** walker ***
上一篇: Python3下不要版本号批量编译.py
下一篇: python3 安装mysql-cl
47756
46264
37145
34652
29241
25899
24769
19873
19435
17928
5725°
6330°
5847°
5898°
7000°
5836°
5856°
6370°
6325°
7691°