title: How to detect a exchange already bind with a queue or not in rabbitmq with pika?
body: <p><strong>receiver.py:</strong></p>
  
  <pre><code>#!/usr/bin/env python3
  import pika
  import sys
  
  connection = pika.BlockingConnection(
      pika.ConnectionParameters(host='localhost'))
  channel = connection.channel()
  
  channel.exchange_declare(exchange='device', exchange_type='direct')
  
  result = channel.queue_declare(queue='', exclusive=True)
  queue_name = result.method.queue
  
  channel.queue_bind(
      exchange='device', queue=queue_name, routing_key='abc')
  
  print(' [*] Waiting for logs. To exit press CTRL+C')
  
  
  def callback(ch, method, properties, body):
      print(" [x] %r:%r" % (method.routing_key, body))
      connection.close()
  
  channel.basic_consume(
      queue=queue_name, on_message_callback=callback, auto_ack=True)
  
  channel.start_consuming()
  </code></pre>
  
  <p><strong>sender.py:</strong></p>
  
  <pre><code>#!/usr/bin/env python3
  import pika
  import sys
  
  connection = pika.BlockingConnection(
      pika.ConnectionParameters(host='localhost'))
  channel = connection.channel()
  
  channel.exchange_declare(exchange='device', exchange_type='direct')
  
  message = 'Hello World!'
  channel.basic_publish(
      exchange='device', routing_key='abc', body=message)
  print(" [x] Sent %r:%r" % ('abc', message))
  connection.close()
  </code></pre>
  
  <p>I have above <code>receiver</code> &amp; <code>sender</code> which works well:</p>
  
  <pre><code>// first bash session
  # python3 receive1.py
   [*] Waiting for logs. To exit press CTRL+C
   [x] 'abc':b'Hello World!'
  
  // second bash session
  # python3 send1.py
   [x] Sent 'abc':'Hello World!'
  </code></pre>
  
  <p><strong>My problem is:</strong></p>
  
  <p>If I call <code>sender.py</code> first, then call <code>receiver.py</code>, the <code>receiver.py</code> will not receive the message. I know this because when <code>sender.py</code> send the message, the exchange in fact did not bind to any queue, so per rabbitmq's design, it will drop all message without queue bind to exchange.</p>
  
  <p>One solution is to use a named queue, and also declare/bind it in <code>sender.py</code>. But if I do this, if last time the consumer did not fetch the message from last sender, this time's new consumer may have chance to receive the old message from last sender.</p>
  
  <p>And for me, the time gap between <code>receiver</code> &amp; <code>sender</code> to be ready is very small. So I just wonder if possible for <code>pika</code> to detect in <code>sender.py</code> that the <code>exchange</code> already bind with a <code>queue</code> or not? If not bind, I will sleep some time then send.</p>
  
  <p>Anyone have suggestion?</p>