Below is a bit of code that I found somewhere on how to query Rabbit using Python to get the queue message count. I have a process that uses this and tries to determine when the queues are clear, then it powers off the servers (only runs on dev servers). Before this runs, the process that adds new messages is shut off, we've verified no new messages are being added. The problem I'm having is it "seems" to be getting the correct message count, but I've had a complaint that a few times the server was shutdown with a possible unack'd message.
Does message_count show *all* messages, or only ready messages?
servername = "mq001"
params = pika.ConnectionParameters(
host=servername,
port=port,
virtual_host=virtual_host,
credentials=pika.PlainCredentials(username,password),
)
connection = pika.BlockingConnection(params)
channel = connection.channel()
status = channel.queue_declare(queue=queue_name, durable=True)
count = status.method.message_count