这是从鼠兔中提取队列的最简单方法
Which is the easiest way to extract queue from pika
好的人。
我对 Python 有点生疏,所以请放轻松。
我有一个连接到的 RabbitMQ 服务器,我正在构建一个简单的完整性检查界面,我正在使用 pika。
我的代码看起来很简单:
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)
log.info("Credentials are being set")
self._parameters = pika.ConnectionParameters(Config.HOST, credentials=self._credentials)
log.info("Connection parameters are being set")
self._connection = pika.BlockingConnection(self._parameters)
self._channel = self._connection.channel()
# We pass an empty string into the queue so we can get the random queue name
self._replyQueue = self._channel.queue_declare(queue='')
log.info("Reply queue name has been initialized %s" % self._replyQueue)
log.info("Connection initialized")
Config.time.sleep(5)
log.info("[x] System is fully initialized, and ready to accept RabbitMQ connections")
def connect(self):
pass
def disconnect(self):
pass
但是当我调用这个方法时:
log.info("Reply queue name has been initialized %s" % self._replyQueue)
我的回复是这样的:
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'])>"])>
而我唯一想向用户显示的实际上是这个队列
queue=amq.gen-8GVTfmr8noMB5slpXnFRHQ
从上述方法中提取此变量的最简单方法是什么?
谢谢你。
p/s:log
只是logger的别名,而Config.USERNAME
和Config.PASSWORD
只是'user'和'localhost'
来自 3rd rabbitmq tutorial,接收者代码:
result = channel.queue_declare(exclusive=True)
queue_name = result.method.queue
引自上述link(标题临时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.
好的人。 我对 Python 有点生疏,所以请放轻松。 我有一个连接到的 RabbitMQ 服务器,我正在构建一个简单的完整性检查界面,我正在使用 pika。
我的代码看起来很简单:
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)
log.info("Credentials are being set")
self._parameters = pika.ConnectionParameters(Config.HOST, credentials=self._credentials)
log.info("Connection parameters are being set")
self._connection = pika.BlockingConnection(self._parameters)
self._channel = self._connection.channel()
# We pass an empty string into the queue so we can get the random queue name
self._replyQueue = self._channel.queue_declare(queue='')
log.info("Reply queue name has been initialized %s" % self._replyQueue)
log.info("Connection initialized")
Config.time.sleep(5)
log.info("[x] System is fully initialized, and ready to accept RabbitMQ connections")
def connect(self):
pass
def disconnect(self):
pass
但是当我调用这个方法时:
log.info("Reply queue name has been initialized %s" % self._replyQueue)
我的回复是这样的:
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'])>"])>
而我唯一想向用户显示的实际上是这个队列
queue=amq.gen-8GVTfmr8noMB5slpXnFRHQ
从上述方法中提取此变量的最简单方法是什么? 谢谢你。
p/s:log
只是logger的别名,而Config.USERNAME
和Config.PASSWORD
只是'user'和'localhost'
来自 3rd rabbitmq tutorial,接收者代码:
result = channel.queue_declare(exclusive=True)
queue_name = result.method.queue
引自上述link(标题临时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.