2

在以下教程中:http://www.rabbitmq.com/tutorials/tutorial-three-python.html,有以下代码。

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

Pika 的“结果”对象记录在哪里?我想知道我可以从中获得的一切。

4

1 回答 1

2

我忘记了昨晚显而易见的事情。Python 通常是自我记录的,尤其是使用“dir”函数。在 python 内部运行 this,然后result.__class__在结果对象上运行 " " 表明这是 Pika 中的 METHOD 对象。

>>> r
<METHOD(['frame_type=1', 'channel_number=1', 'method=<Exchange.DeclareOk>'])>
>>> r.__class__
<class 'pika.frame.Method'>
>>> dir(r)
['INDEX', 'NAME', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_marshal', 'channel_number', 'frame_type', 'marshal', 'method']

一些谷歌搜索将我带到这些文档:https ://pika.readthedocs.org/en/latest/frame.html#method

很遗憾...

This class level documentation is not intended for use by those using Pika in their applications. This documentation is for those who are extending Pika or otherwise working on the driver itself.

因此,RabbitMQ 网站上的这个特定示例似乎使用了 Pika 的未记录功能。结果,我最终只是在我的应用程序中生成了我自己的唯一名称。

于 2012-12-12T02:41:13.473 回答