T
T
topuserman2019-11-11 18:02:38
RabbitMQ
topuserman, 2019-11-11 18:02:38

RabbitMQ: what is exchange, and where does it belong?

The usual scheme of an application on rabbitmq looks like this:
1. The producer sends messages to exchange.
2. Depending on the Exchange type, the message is routed to the queue.
3. The consumer listens to the queue, reads the message, and acknowledges that the message has been received.
I don't understand the first layer - sending an exchange message.
What is exchange?
Usually, in all examples and documentation, exchange is just a few extra lines of code in the producer code.
Do I need to put it in a separate exchange file, and knock on it when sending a message, or can it be left in the producer code? How is it done on combat projects?
Where can I see real examples?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Romashkan, 2019-11-11
@EvgeniiR

Exchange is just an intermediary that decides how to route the messages in the queue, thereby decoupling the producer a bit from knowing how and by whom the messages will be processed.
What means "to take out exchange in a separate file"? Exchange it in the broker.
The producer only needs to know the exchange name in order to post messages there, and the Routing Key, if necessary.
It is better to create exchange certainly not in the producer.
To play it safe and make sure that exchange exists, of course, you can send a message with an exchange declaration with the passive flag ( https://www.rabbitmq.com/amqp-0-9-1-reference.html... )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question