1

看下面的截图

在此处输入图像描述

foo我的队列与一个名为仅接收带有 Routing key的消息的交换绑定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}在回调中访问参数 ()。这可能吗?

4

2 回答 2

0

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


注意: RabbitMQ 团队会监控邮件列表rabbitmq-users有时只会在 StackOverflow 上回答问题。

于 2018-10-23T15:04:55.703 回答
0

您可以使用我的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"
    }
]

此处提供更多示例。

于 2018-10-29T01:14:07.723 回答