In the process of connecting RabbitMQ with Pika, it is found that only the number of messages in the ready state can be obtained, as long as HTTP requests are used to achieve the purpose.
#encoding: utf-8#author: walker#date: 2018-03-06#summary: Get RabbitMQ The number of 3 status messages in Import os, sys, timeimport requestsimport jsonclass rabbitmqtool ( Object):d ef __init__ (self, host, vhost, queue, user, passwd): self.host = hostself.vhost = vhostself.queue = queueself.user = userself.passwd = passwd# returns 3 messages: Ready, unacked, totaldef 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 -1dic = 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 * * *
Get the number of RabbitMQ queue messages by HTTP (python3)