title: Should exchange or queue be declared multiple times in RabbitMQ?
body: <p>I discuss the <code>RabbitMQ</code> design with my colleague between <code>Server A</code> and <code>Server B</code>, here is the flow chart as following.</p>
  
  <p><img src="https://i.stack.imgur.com/O1Ih3.png" alt="enter image description here"></p>
  
  <p><code>Server A</code> sends messages to <code>Server B</code> through <code>exchange A</code> and <code>Queue B</code>, and receives messages from <code>Server B</code> through <code>Queue A</code>. vice versa for <code>Server B</code>.</p>
  
  <p>There are two classes in <code>Server A</code> implemented with <code>C++</code>; one is <code>sender</code>, the other is <code>receiver</code>. The same code structure is for <code>Server B</code> implemented with <code>JavaScript</code>.</p>
  
  <p>For the <code>sender</code> and <code>receiver</code> in <code>Server A</code>. My colleague's idea is:</p>
  
  <ul>
  <li>The initialization in Sender:
  
  <ul>
  <li>create connection with <code>rabbitmq</code></li>
  <li>declare the <code>exchange A</code></li>
  <li>declare the <code>Queue B</code></li>
  <li>bind the key to <code>Queue B</code></li>
  </ul></li>
  <li>The initialization in Receiver:
  
  <ul>
  <li>create connection with <code>rabbitmq</code></li>
  <li>declare the <code>exchange B</code></li>
  <li>declare the <code>Queue A</code></li>
  <li>bind the key to <code>Queue A</code></li>
  </ul></li>
  </ul>
  
  <p>The same logic in <code>Server B</code>.</p>
  
  <p>However, I <strong>do NOT think <code>Queue B</code> and <code>Exchange B</code> should be declared in <code>Server A</code>. They are should be declared in <code>Server B</code>.</strong></p>
  
  <p>Finally, I implement it following my colleague's idea, due to he has done some  related work before. </p>
  
  <hr>
  
  <p>Today, the <code>Server A</code> <strong>hang</strong> at the function <code>amqp_queue_declare</code> in <code>Sender</code> module during test, but it works well after restarting <code>RabbitMQ</code>. So I doubt the my colleague's idea for the initialization of <code>Sender</code>.  </p>
  
  <p>My thought:</p>
  
  <ul>
  <li><code>Server A</code>
  
  <ul>
  <li>The initialization in Sender
  
  <ul>
  <li>create connection with <code>rabbitmq</code></li>
  <li>declare the <code>Exchange A</code></li>
  </ul></li>
  <li>The initialization in Receiver
  
  <ul>
  <li>create connection with <code>rabbitmq</code></li>
  <li>create the <code>Queue A</code></li>
  <li>bind the key to <code>Queue A</code></li>
  </ul></li>
  </ul></li>
  <li><code>Server B</code>
  
  <ul>
  <li>The initialization in Sender
  
  <ul>
  <li>create connection with <code>rabbitmq</code></li>
  <li>declare the <code>Exchange B</code></li>
  </ul></li>
  <li>The initialization in Receiver
  
  <ul>
  <li>create connection with <code>rabbitmq</code></li>
  <li>create the <code>Queue B</code></li>
  <li>bind the key to <code>Queue B</code></li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>Could someone tell me is there anything wrong with my thought? or is there better solution?</p>
  
  <hr>
  
  <p><strong>Edit</strong>: answer questions from @Sigismondo</p>
  
  <ul>
  <li><p><em>do all the messages need to be delivered to the consumer A/B?</em></p>
  
  <p>No</p></li>
  <li><p><em>does the consumer A/B need to be notified in case some messages are lost?</em></p>
  
  <p>No. I want to know how could consumer A know there is message lost?</p></li>
  <li><p><em>what is the intended behavior in case the consumer A/B is not reachable?</em></p>
  
  <p>If consumer A is not reachable, then producer B will not sent any message to A, and vise versa. <strong>How could B know the consumer A is not reachable??</strong></p>
  
  <p>Currently, in my system, there is ack for every message. so B does not get ack from A in the previous case, then B will not sent message to A.</p></li>
  <li><p><em>what is the intended behavior in case the producer A/B is down?</em></p>
  
  <p>If producer B is down, then A will not receive any message from B. So A will not send any message to B. </p></li>
  </ul>