Domanda

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?

È stato utile?

Soluzione

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).

Altri suggerimenti

Depending on your ultimate goal, you might be able to solve this issue by using a temporary queue.

To make things more clear, lets give things some names. Call your current queue (the one you want to purge) Queue A, and assume it is 1-1 bound to Exchange A.

If you create a new queue (Queue B) and bind it to Exchange A in the same way that Queue A is bound, Queue B will now get all of the messages (from the time of binding) that Queue A gets.

You can now safely purge Queue A without loosing any of the messages that got sent in after Queue B was bound.

Re-bind Queue A to Exchange A and you are back up and running.

You can then deal with the "interim" messages in Queue B however you might need to.

This has the advantage of having a very well defined behavior and doesn't get you into any race conditions because you can completely blow Queue A away and re-create it instead of purging.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top