0
votes

I'm trying to write a method that creates new queues with arguments of an existing exchange name, new queue name and routing key. The exchange might be in different types (direct, fanout, topic).

Is there a way to make and bind the queue without knowing the exchange type?

def my_queue(self, exchange_name, queue_name, routing_key):
    with connection.acquire(block=True) as conn:
        ex = Exchange(exchange_name, type='topic')
        queue = Queue(name="my_queue", routing_key="my_key", exchange=ex)
        queue.maybe_bind(conn)
        queue.declare()
1

1 Answers

0
votes

Considering that Celery typically automatically creates queue for you, all you have to do is to call add_consumer() to subscribe (during runtime) one or more workers to the particular queue. As mentioned, if the queue does not exist, Celery will make it for you. Similarly, you may want to unsubscribe from the queue, in which case you call cancel_consumer().