D
D
deadsquirrel932020-10-02 10:37:55
PHP
deadsquirrel93, 2020-10-02 10:37:55

Types of exchangers in rabbitmq and storing a message with an inactive recipient?

In office The rabbitmq doc says that there are several types of exchanges, one of them is fanout - distributes messages to all queues, ignores routing_key.
Task model: there are n messages, there are three recipients (consumer), each message must go to each recipient.
Either https://github.com/php-amqplib/php-amqplib

is used What I do:
Sender (producer): declare a fanout type exchanger, do basic_publish of all messages
Receiver (consumer): declare a fanout type exchanger declare a queue with a random name (from docks list($queue_name, ,) = $channel->queue_declare("", false, false, true, false);), do basic_consume of all messages

Problem:
If the recipients are already running, then everything happens correctly, all recipients received for each message, but if the recipients are not started, and the messages are sent, then nothing happens when the recipients are started, the messages are simply lost.
If you declare a queue in the sender, then the messages are not lost, but then, without being attached to this queue in the recipient, I will not be able to receive messages and the whole meaning of fanout is lost. I played with different flags (durable, delivery_mode) and nothing helped.

Question: how to save messages without being attached to the queue in the sender, so that when the recipients are started, they begin to receive these messages? If the way is only to declare a queue in the sender, then what is the point of exchanger fanout?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2020-10-02
@deadsquirrel93

If you want to create an exchanger on an empty RabbitMQ, throw messages into it and later connect queues to this exchanger in the hope of receiving previously sent messages, then this will not work for you. The exchanger does not store messages, but scatters incoming messages as soon as they are received, if at the moment it does not have queues for sending, the message is simply discarded. You need to start consumers before sending messages. If you want messages to accumulate at the moment when the consumer falls off, then you need to make the name of the queue predictable / known to the consumer (if necessary, make it durable).
If you need something to create queues and exchangers when RabbitMQ starts, then this can be arranged through the management plugin(they say that in the latest versions it is even possible to do this without the plugin management).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question