Search code examples
pythonpika

Using pika in asynchronous mode, how do I get the name of a server-named queue?


I'm following the asynchronous consumer example, and I want to declare a server-named queue as follows:

channel.queue_declare(on_queue_declareok, '')

My callback looks like this:

def on_queue_declareok(frame):
    queue_name = ????    # What goes here?
    channel.queue_bind(on_bindok, queue_name, EXCHANGE_NAME, ROUTING_KEY)

How do I get the server-generated name from the frame parameter. If I print it out, it looks like this:

<METHOD(['frame_type=1', 'channel_number=1',
    "method=<Queue.DeclareOk(['queue=amq.gen-NqdbEFHZdrtC4iLNdJpbjQ',
        'message_count=0', 'consumer_count=0'])>"])>

The queue name is in there. What is this thing? How do I get the queue name out?


Solution

  • You can declare a unique name using frame.method.queue.