My producer code:
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')
My consumer code:
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)
I tried everything I could find but still the messages stay in the queue. And also I tried to check number of messages in the queue but it always shows 0 both in producer and performer:
res = channel.queue_declare(
queue="my_queue",
passive=True
)
print('Messages in queue {}'.format(res.method.message_count)
Sorry for the necroposting, but this might help someone. This is what I do to connect to a queue and purge it, before start using it (and it works):
Tune variables
rabbit_host
andrabbit_queue
according to your needs.