Consuming multiple queues breaks when one queue does not exists

Viewed 12

I have a rabbitMQ server, which has two queues [hello, other].
If I push anything to one of the queues it will be consumed as desired.

The problem occurs when the first queue does not exist (lets say [fail, other]). The second queue is now not consumed even though it exists.
It does not throw any errors either, the procces keeps running, but when pushing new items to the queue it wont show up in the consumer.

I have tried queue_declare with passive=True, but this just freezes everything (if the queue does not exists)

import pika

class QueueConsumer:

    def __init__(
        self,
        host: str,
        queues: list,
        callback,
    ):
        self.host = host
        self.queues = queues
        self.callback = callback

    def on_open(self, connection):
        connection.channel(on_open_callback=self.on_channel_open)

    def on_channel_open(self, channel):
        for queue in self.queues:
            channel.basic_consume(queue=queue, on_message_callback=self.callback, auto_ack=True)

    def start_listening(self):
        connection_params = pika.ConnectionParameters(
            host=self.host,
            port=5672,
        )
        connection = pika.SelectConnection(parameters=connection_params,
                                           on_open_callback=self.on_open)
        connection.ioloop.start()


def callback(channel, method, properties, body):
    print(body)

consumer = QueueConsumer('test','test',callback=callback,queues=['hello','other'], host="localhost")
consumer.start_listening()

I would like to check if the queue exists. If not ignore it, otherwise consume it

0 Answers
Related