1
RabbitMQ:  version 3.11.2

I wish to configure a fanout exchange for which there will be two consumers and a single producer. Each of the two consumers can go offline for several minutes at a time; in the worst case scenario, one of the consumers could go offline for hours.

QUESTION: how should the fanout exchange and/or consumer queues be configured such that no message is ever lost, even if and when one of the consumers goes offline for several minutes or hours?

Kode Charlie
  • 1,297
  • 16
  • 32

1 Answers1

0

It is enough to bind queues to your exchange.

See here for more details https://www.rabbitmq.com/tutorials/tutorial-three-python.html

result = channel.queue_declare(queue='') At this point result.method.queue contains a random queue name. For example it may look like amq.gen-JzTY20BRgKO-HjmUJj0wLg.

Secondly, once the consumer connection is closed, the queue should be deleted. There's an exclusive flag for that:

result = channel.queue_declare(queue='', exclusive=True) channel.queue_bind(exchange='logs', queue=result.method.queue)

Note: If you need to handle the offline consumers, you need persistent queues and persistent messages instead of exclusive and auto-delete queues

Gabriele Santomaggio
  • 21,656
  • 4
  • 52
  • 52
  • I will be using the pub/sub pattern, and not worker-task queues or any kind of filtering. That is, every subscriber _MUST SEE_ every message. In that case, is what you are saying still true? – Kode Charlie Nov 17 '22 at 17:37
  • thx. My queues will be both exclusive and durable, while exchange will be durable. As well, for both queue and exchange, I've set `auto-delete=false`. I believe this configuration will persist messages across both broker _AND_ client restarts. – Kode Charlie Nov 17 '22 at 22:16
  • Sorry, if you want to handle the offline status you need persistent queues and persistent messages. One queue for each single consumer and then bind the exchange fan out to the queues. – Gabriele Santomaggio Nov 18 '22 at 07:42