如何使用 web 插件将 JSON 有效载荷发送到 RabbitMQ?

How to send JSON payload to RabbitMQ using the web plugin?

我有一个 RabbitMQ 3.4.2 instance 安装了网络管理插件。

当我使用 Python 的 kombu queue 包将消息 {'operationId': 194} 推送到 queue 时,消息会在另一端读取以字典结尾。

但是,当我使用网络控制台发送消息时:

我在接收端收到以下错误:

operation_id = payload['operationId']
TypeError: string indices must be integers

我尝试添加 content-type header 和 属性,但没有成功。

由于reader代码是相同的,这意味着网络发送者没有将发送的消息标记为JSON/字典有效负载,因此在另一端。

知道如何使用 RabbitMQ 网络控制台将消息标记为 JSON 消息吗?

你需要de-serialize输出。

import json
payload = json.loads(payload)
operation_id = payload['operationId']

此外 {'operationId': 194} 无效 JSON。虽然看起来你在屏幕截图中使用了双引号,但请确保将单引号替换为双引号。

编辑: 所以你是对的,kombu 应该处理这个。查看代码,header 很可能是 case-sensitive。将属性 header 从 Content-Type 更改为 content-type

我不得不使用 content_type 而不是 content-type(下划线而不是连字符)。

这是一个非常有问题的设计决定,因为每个人都知道的标准是 content-type