Search code examples
pythonrabbitmqamqppika

RabbitMQ: purge queue


I have some queue, for etc:

online_queue = self._channel.queue_declare(
                                   durable = True,
                                   queue = 'online'
                                   )

At the moment, I need to flush all content in this queue. But, at this moment, another process, probably, may publish to this queue. If I use channel.queue_purge(queue='online'), what will happened with messages, published, while queue_purge still working?


Solution

  • You're describing a race condition. Some might remain in the queue and some others might get purged. Or all of them will get purged. Or none of them will get purged.

    There's just no way to tell, because it's a time-dependent situation. You should re-examine your need to purge a queue which is still active, or build a more robust consumer that can live with the fact that there might be messages in the queue it is connecting to (which is basically what consumers have to live with, anyway).