[英]Using pika, is it possible to read rabbitmq binding arguments?
看下面的截图
我的队列与一个名为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}
)。 这有可能吗?
这是不可能的,因为AMQP不会在basic.consume
的响应中提供该信息。 只要启用了rabbitmq_management
插件,就可以使用HTTP API来检索该信息(如果rabbitmq_management
了该屏幕截图,则必须这样做)。
注意: RabbitMQ团队监视rabbitmq-users
邮件列表 ,仅在某些情况下回答关于StackOverflow的问题。
您可以使用我的RabbitMQ库amqpstorm来获取此类信息。
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"
}
]
此处提供更多示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.