使用pika,可以读取rabbitmq绑定参数吗?

klh5stk1  于 12个月前  发布在  RabbitMQ
关注(0)|答案(2)|浏览(114)

看看下面的截图

我的队列与名为foo的交换机绑定,只接收路由键为bar的消息。我还定义了一对参数{baz: qux}。现在我有一个如下代码:

credentials = pika.PlainCredentials(...)
parameters = pika.ConnectionParameters(...)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.basic_qos(prefetch_count=1)
channel.basic_consume(callback, queue='this_queue')

回调函数具有以下签名:

def callback(channel, method, properties, body):
    ....

现在的问题是:如何访问回调函数中的参数({baz: qux})。这可能吗?

iecba09b

iecba09b1#

您可以使用我的RabbitMQamqpstorm来获取这类信息。

from amqpstorm.management import ManagementApi

API = ManagementApi('http://127.0.0.1:15672', 'guest', 'guest')
print(API.queue.bindings('simple_queue', virtual_host='/'))

结果看起来像这样。

[
    {
        "source": "",
        "vhost": "/",
        "destination": "simple_queue",
        "destination_type": "queue",
        "routing_key": "simple_queue",
        "arguments": {},
        "properties_key": "simple_queue"
    },
    {
        "source": "amq.direct",
        "vhost": "/",
        "destination": "simple_queue",
        "destination_type": "queue",
        "routing_key": "test",
        "arguments": {},
        "properties_key": "test"
    }
]

更多示例here

sulc1iza

sulc1iza2#

这是不可能的,因为AMQP不会在对basic.consume的响应中提供该信息。只要您启用了rabbitmq_management插件(如果您拍摄了该屏幕截图,则必须启用),就可以使用HTTP API检索该信息。

相关问题