mutantkeyboard mutantkeyboard - 11 months ago 99
Python Question

Which is the easiest way to extract queue from pika

Ok people.
I'm bit rusty with Python so please go easy on me.
I have a RabbitMQ server that I connect to, and I'm building a simple interface for sanity check, and I'm using pika.

My code looks very simple:

class RabbitMQConnector(object):
""" Class that instantiates the connection, and the test interface for
the RabbitMQ services.

def __init__(self):
self._credentials = pika.PlainCredentials(Config.USERNAME, Config.PASSWORD)"Credentials are being set")
self._parameters = pika.ConnectionParameters(Config.HOST, credentials=self._credentials)"Connection parameters are being set")
self._connection = pika.BlockingConnection(self._parameters)
self._channel =
# We pass an empty string into the queue so we can get the random queue name
self._replyQueue = self._channel.queue_declare(queue='')"Reply queue name has been initialized %s" % self._replyQueue)"Connection initialized")
Config.time.sleep(5)"[x] System is fully initialized, and ready to accept RabbitMQ connections")

def connect(self):

def disconnect(self):

But when I call this method:"Reply queue name has been initialized %s" % self._replyQueue)

My reply gets like:

Reply queue name has been initialized <METHOD(['channel_number=1', 'frame_type=1', "method=<Queue.DeclareOk(['consumer_count=0', 'message_count=0', 'queue=amq.gen-8GVTfmr8noMB5slpXnFRHQ'])>"])>

And the only thing I want to display to user is actually this queue


What would be the easiest way to extract this variable from the above method?
Thank you.

is just an alias for logger, whilst
are just 'user' and 'localhost'

Answer Source

From the 3rd rabbitmq tutorial, code for receiver:

result = channel.queue_declare(exclusive=True)
queue_name = result.method.queue

Quote from the aforementioned link (under title Temporary queues):

...we could create a queue with a random name, or, even better - let the server choose a random queue name for us. We can do this by not supplying the queue parameter to queue_declare:

result = channel.queue_declare()
At this point result.method.queue contains a random queue name.