[rabbitmq-discuss] How to not publish messages, if queue is full?

Emile Joubert emile at rabbitmq.com
Tue Jul 16 12:05:04 BST 2013


On 15/07/13 15:14, sergey at openbridge.com wrote:

> What are the possible ways to not drop the messages? 

There's no simple answer to this question. If you don't want messages to
be dropped then you should consider using a different solution.
Determine what you hope to achieve by limiting queue length and check
whether the same aims can be achieved in another way.

> Ideally I would like to throw an Exception if queue is full.

You can notify publishers that the queue was full after the fact, by
configuring a dead-letter-exchange for overflow messages. Publishers can
bind a private queue to the DLX and consume from it. Publishers can
treat it as an exception when messages they sent reach them via that
subscription.

However this does not prevent messages from being dropped in the first
place.

> First I was thinking to check the queue size, and if it's full than
> stop. But for example if I have 5 producers and queue limit size is set
> to 10, and I already have 9 messages in the queue, than all 5 producers
> will check the size, and publish their messages and 4 messages will be lost.

That won't work well if many publishers monitor the same queue. You
could craft a solution around the same idea if each publisher published
to a separate length-limited queue.



-Emile






More information about the rabbitmq-discuss mailing list