Delay (pause) consumption #12380
-
I want to pause queue consumption (i.e. stop performing tasks at all and keep remaining in queue). But how is it done properly? I searched for pausing and delaying queue, but all I found was dead letter method and delayed message plugin. Which requires posting to queue with predefined execution delay, so no way to delay entries that are already in queue. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
It is not possible to "pause" a subscription per-se. However, you can decide when to acknowledge a message, and therefore "pause" acknowledging messages to RabbitMQ. By not acknowledging messages to RabbitMQ, there will be a point where RabbitMQ will stop dispatching messages to your consumer, see the pre-fetch guide. Then, your consumer could hold onto the failed task (message) without acknowledging, retry after X seconds, and acknowledge the message once the remote server has successfully completed the task. In this approach, you don't need to return the failed task back into queue. If you really want to "pause" consumption, you will have to unsubscribe your consumer and close the channel. After closing the channel, any message in-flight (i.e. not acknowledged by the consumer) will be automatically re-queued. Alternatively, you could "nack" the message to put it back in the queue and wait in your application; however, this will not pause the delivery of messages from RabbitMQ. |
Beta Was this translation helpful? Give feedback.
-
@Arctomachine you can cancel your consumer at any moment and re-register it. In addition to the suggestions by @Zerpet, you can
Note that RabbitMQ will enforce an acknowledgement timeout so such pauses should not last for more than a few minutes. |
Beta Was this translation helpful? Give feedback.
-
Thanks. I played with it in meantime, I found that prefetch 1 is good solution for my use case. But info about timeouts is good to know |
Beta Was this translation helpful? Give feedback.
Thanks. I played with it in meantime, I found that prefetch 1 is good solution for my use case. But info about timeouts is good to know