[英]How to Get all the pending tasks and purge queue in Pika RabbitMQ
[英]Can't purge rabbitmq queue with pika
我的制作人代码:
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)
我尝试了我能找到的一切,但消息仍然留在队列中。 而且我还尝试检查队列中的消息数量,但它在生产者和执行者中始终显示为 0:
res = channel.queue_declare(
queue="my_queue",
passive=True
)
print('Messages in queue {}'.format(res.method.message_count)
抱歉发布了 necroposting,但这可能会对某人有所帮助。 这是我在开始使用它之前连接到队列并清除它的方法(并且有效):
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)
根据您的需要调整变量rabbit_host
和rabbit_queue
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.