发布时间:2019-09-26 07:25:30编辑:auto阅读(2218)
在使用 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
51145
50549
41170
38004
32467
29369
28236
23088
23052
21374
1424°
2123°
1762°
1687°
1984°
1762°
2437°
4101°
3979°
2840°