Is it possible to consume from every queue with pika?
<p>I'm trying to set up a program that will consume from every queue in RabbitMQ and depending on certain messages it will run certain scripts. Unfortunately while adding consumers if it runs into a single error (i.e. timeout or queue not found) the entire channel is dead. Additionally queues come and go so it has to refresh the queues list quite often. Is this even possible?
Here is my code so far.</p>

<pre><code>import pika
import requests
import sys

try:
    host = sys.argv[1]
except:
    host = "localhost"

def get_queues(host="localhost", port=15672, user="guest", passwd="guest", virtual_host=None):
    url = 'http://%s:%s/api/queues/%s' % (host, port, virtual_host or '')
    response = requests.get(url, auth=(user, passwd))
    return response.json()

queues = get_queues(host)

def get_on_message(queue):
    def on_message(channel, method_frame, header_frame, body):
        print("message from", queue)
        channel.basic_ack(delivery_tag=method_frame.delivery_tag)
    return on_message

connection = pika.BlockingConnection(pika.ConnectionParameters(host))
channel = connection.channel()

for queue in queues:
    print(channel.is_open)
    try:
        channel.basic_consume(get_on_message(queue["name"]), queue["name"])
        print("queue added",queue["name"])
    except Exception as e:
        print("queue failed",queue["name"])
        sys.exit()

try:
    channel.start_consuming()
except KeyboardInterrupt:
    channel.stop_consuming()
connection.close()
</code></pre>

<p>Is there a right way to do this or is doing this not right at all?</p>

<p>It possible to consume from every queue in any language. It's also wrong and if this is something that is required, then the whole design/setup should be re-thought.</p>

<p>EDIT after comments:</p>

<p>Basically, you'd need to get the names of all existing queues which can be programmatically done via the <a href="http://hg.rabbitmq.com/rabbitmq-management/raw-file/rabbitmq_v3_3_4/priv/www/api/index.html" rel="nofollow">rest api</a> (potentially even by calling rabbitmqctl and parsing the output). Once you have the names of the queues, you can simply consume from them as it is explained in <a href="http://www.rabbitmq.com/tutorials/tutorial-one-python.html" rel="nofollow">the tutorial</a>.</p>

<p>Once again, I don't think that this the right way to go, and perhaps you should consider using topic exchange - I'm guessing this since you wrote <code>queues come and go</code>.</p>

python rabbitmq pika