********************** rabbitmq ********************** .. toctree:: :maxdepth: 2 :caption: 相关阅读 exchange、route、queue的关系以及发布订阅模式 三种Exchange模式(fanout,direct,topic)简介 获取队列消息数量 =============================================== rabbitmq有提供api可以查询 .. code-block:: python 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__': host = '10.0.12.10' vhost = '%2F' # 若队列所在默认虚拟主机,即主机名为"/",请求时需将"/"url转码后("%2f")请求 mqTool = RabbitMQTool(host=host, vhost=vhost, queue='group32110', user='user', passwd='password') ready, unacked, total = mqTool.getMessageCount() print('ready: %d' % ready) print('unacked: %d' % unacked) print('total: %d' % total) * https://www.jianshu.com/p/4f620fa28073 * https://www.cnblogs.com/macT/p/11983068.html