I want to be able to detect whether an exchange does not exist when submitting a message to AMQP.
Consider following example.
#!/usr/bin/python
import amqp
from time import sleep
conn = amqp.Connection(host="localhost:5672", userid="guest", password="guest", virtual_host="/")
outgoing = conn.channel()
message = amqp.Message("x")
while True:
print "publish message."
outgoing.basic_publish(message,exchange="non-existing",routing_key="fubar")
sleep(1)
This script keeps publishing to the exchange but does not raise any errors if the exchange does not exist. When the exchange exists, the messages arrive.
#!/usr/bin/python
import amqp
from time import sleep
conn = amqp.Connection(host="localhost:5672", userid="guest", password="guest", virtual_host="/")
outgoing = conn.channel()
message = amqp.Message("x")
while True:
print "publish message."
outgoing.basic_publish(message,exchange="non-existing",routing_key="fubar")
outgoing.wait()
sleep(1)
When I add outgoing.wait() a amqp.exceptions.NotFound is raised which is what I want. The problem is however that if in this case the exchange exists, the message arrives but outgoing.wait() blocks my loop. (I could run outgoing.wait() in a separate thread but that I do not want to do.)
How to deal with this?
Any advice tips pointers welcome
Thanks,
Jay