Should an exchange or queue be declared multiple times in RabbitMQ?

I am discussing design RabbitMQ

with my colleague in between Server A

and Server B

, here is the flowchart as shown below.

enter image description here

Server A

sends messages Server B

through exchange A

and Queue B

and receives messages from Server B

to Queue A

. on the contrary, for Server B

.

In Server A

implemented two classes with C++

; one - the sender

other - receiver

. The same code structure is Server B

implemented with JavaScript

.

For sender

and receiver

in Server A

. My colleague idea:

  • Initialization in the sender:
    • create a connection with RabbitMQ

    • to announce exchange A

    • to announce Queue B

    • bind key to Queue B

  • Initialization in the receiver:
    • create a connection with RabbitMQ

    • to announce exchange B

    • to announce Queue A

    • bind the key to Queue A

The same logic in Server B

.

However, I do NOT think that Queue B

u exchange B

should be declared in Server A

. They must be declared in Server B

.

Finally, I am implementing this after my colleague's idea, due to the fact that he did some related work before.


Today Server A

hang in the module amqp_queue_declare

in sender

during the test, but it works well after restart RabbitMQ

. So I doubt my colleague's idea for initialization sender

.

My thought:

  • Server A

    • Initialization in Sender
      • create a connection with RabbitMQ

      • to announce exchange A

    • Receiver initialization
      • create a connection with RabbitMQ

      • create Queue A

      • bind the key to Queue A

  • Server B

    • Initialization in Sender
      • create a connection with RabbitMQ

      • to announce exchange B

    • Receiver initialization
      • create a connection with RabbitMQ

      • create Queue B

      • bind key to Queue B

Can anyone tell me there is something wrong with my thought? or is there a better solution?


Edit : answer questions from @Sigismondo

  • all messages have to be delivered to consumer A / B?

    Not

  • Is user A / B notification required if some messages are lost?

    Not. I want to know how consumer A could know that the message was lost?

  • What is the intentional behavior when the A / B consumer is not available?

    If consumer A is not available, then producer B will not send any message to and vice versa. How does B know that consumer A is not available?

    I currently have a message on my system for every message. so B does not receive a response from A in the previous case, then B will not send a message to A.

  • What is the intentional behavior in case the A / B manufacturer is down?

    If producer B is down then A will not receive any message from B. So A will not send message to BB

+3


source to share


1 answer


It is quite true that both servers declare a queue and exchange, and this is generally the preferred approach when dealing with named queues: usually you want producers and consumers to be decoupled, and letting declare (i.e.: create if absent) queues and exchange, you allow both to work correctly, and you have the guarantee that no messages will be lost if the other partner is not already running, even with a fresh RabbitMQ installation.

In particular, it is important that:

  • the consumer declares the queues from which they should consume messages (or they won't be able to use them).

  • the producer announces the queues and exchanges it produces before creating messages (or they will be lost if no user created the queues).

This is the typical approach used when using named queues, which seems to be what you are doing here.

Now if you want messages to be forgotten if the consumer does not exist, the producer will not declare any queue: the consumer can create a temporary queue and bind it to the exchange.



Finally, if this is the case and you want to be notified in case there are no consumers (and no queues associated with an exchange), you can use alternate exchanges .

So you see: there are some options that you can use, but for each there is a rationale: you have to choose which one to use based on a specific problem - and that is not qualified enough in your explanation: even if it is very detailed, it misses some aspects:

  • all messages have to be delivered to consumer A / B?
  • Is consumer A / B notification required if some messages are lost?
  • What is the intentional behavior when the A / B consumer is not available?
  • What is the intentional behavior in case the A / B manufacturer is down?

However, amqp_queue_declare

it should not hang at all if this is the case, you encounter an error or I do not know that, but it is not expected behavior for him, as far as I know.

+3


source







All Articles