Python Can';t使用pika清除rabbitmq队列

Python Can';t使用pika清除rabbitmq队列,python,rabbitmq,flask-socketio,pika,purge,Python,Rabbitmq,Flask Socketio,Pika,Purge,我的制作人代码: conn_params = pika.ConnectionParameters('localhost', 5672, '/') connection = pika.BlockingConnection(conn_params) channel = connection.channel() channel.exchange_declare(exchange='direct_exchange', exchange_type='di

我的制作人代码:

conn_params = pika.ConnectionParameters('localhost', 5672,  '/')
connection = pika.BlockingConnection(conn_params)
channel = connection.channel()
channel.exchange_declare(exchange='direct_exchange',
                         exchange_type='direct')
channel.queue_declare(queue='my_queue')

@socketIo.on("clean")
def clean(msg):
    print("cleaning")
    channel.queue_purge('my_queue')
我的消费者代码:

conn_params = pika.ConnectionParameters('localhost', 5672, '/')
connection = pika.BlockingConnection(conn_params)
channel = connection.channel()
channel.exchange_declare(exchange='direct_exchange', exchange_type='direct')
result = channel.queue_declare(queue='my_queue')
channel.queue_bind(exchange='direct_exchange', queue='my_queue', routing_key='my_queue')


def callback(ch, method, properties, body):
    ...
    channel.basic_ack(delivery_tag=method.delivery_tag)

channel.basic_consume('my_queue', callback, auto_ack=False )
channel.basic_qos(prefetch_count=1)
我尝试了我能找到的一切,但消息仍然留在队列中。我还尝试检查队列中的消息数,但在producer和performer中始终显示0:

res = channel.queue_declare(
        queue="my_queue",
        passive=True
    )
print('Messages in queue {}'.format(res.method.message_count)

很抱歉发布此消息,但这可能会对某些人有所帮助。这是我在开始使用队列之前连接到队列并清除它所做的操作(它可以正常工作):


根据您的需要调整变量
rabbit\u host
rabbit\u queue

很抱歉,这可能会对您有所帮助。这是我在开始使用队列之前连接到队列并清除它所做的操作(它可以正常工作):

根据需要调整变量
rabbit\u主机
rabbit\u队列

from pika import URLParameters, BlockingConnection

rabbit_host = 'amqp://localhost:5672'
rabbit_queue = 'my_fantastic_queue'

rabbit_connection = BlockingConnection(URLParameters(rabbit_host))
rabbit_channel = rabbit_connection.channel()
rabbit_channel.queue_purge(rabbit_queue)