0

I'm trying to receive multiple queues, I tried the code: https://stackoverflow.com/a/42351395/3303330

But it's necessary declare the "queue_declare". Hope you can help me guys, it's my code:

import pika
import time

from zeep import Client

parameters = pika.URLParameters('amqp://user:pass@theurl:5672/%2F')

connection = pika.BlockingConnection(parameters)
channel = connection.channel()

channel.queue_declare(queue='queue1', passive=True, durable=True, exclusive=False, auto_delete=False)
print(' [*] Waiting for messages. To exit press CTRL+C')

def callback(ch, method, header, body):
    print(" [x] Received %r" % body)
    time.sleep(body.count(b'.'))
    ch.basic_ack(delivery_tag = method.delivery_tag)

channel.basic_consume(callback, queue='queue1')

channel.start_consuming()
zamora322
  • 27
  • 5
  • Does this answer your question? [Consume multiple queues in python / pika](https://stackoverflow.com/questions/24510310/consume-multiple-queues-in-python-pika) – Trevor Boyd Smith Sep 01 '22 at 18:58

1 Answers1

3

It is not necessary to declare a queue more than once as long as you delcare it to be durable. You can declare more than one queue in your client code or using the RabbitMQ admin interface.

You can use your channel to consume messages from more than one queue. Just execute channel.basic_consume more than once using different queue parameter values.