使用 http api 发布到默认的 rabbitmq 交换器

Publishing to the default rabbitmq exchange using the http api

所以我正在使用 rabbitmqs http api 在 rabbit 中执行一些非常基本的操作。它在大多数情况下都很好用,但我在弄清楚如何使用它向默认的 rabbitmq 交换器发布消息时遇到了问题。这个交换总是存在的,不能被删除,并且绑定到每个队列,路由键等于队列名称。

我的问题是这个队列没有名字,或者更确切地说,它的名字是一个空字符串“”。 URL 我必须使用 HTTP api 发布此消息,其中包括交换的名称。

http://localhost:15672/api/exchanges/vhost/name/publish (来源:http://hg.rabbitmq.com/rabbitmq-management/raw-file/rabbitmq_v3_3_4/priv/www/api/index.html

同一篇文章提到,为了使用名称为“/”的默认虚拟主机,您必须使用 %2f 代替虚拟主机名称。这让我觉得应该有一种类似的方式来表示 url.

中的默认交换

我尝试了一些不同的东西,其中 none 成功了:

/api/exchanges/vhost//publish
/api/exchanges/vhost/""/publish
/api/exchanges/vhost/''/publish
/api/exchanges/vhost/ /publish
/api/exchanges/vhost/%00/publish

我敢肯定我不是唯一 运行 这个问题的人。任何帮助将非常感激。

谢谢, 汤姆

这是向amq.default发布消息的方式:

http://localhost:15672/api/exchanges/%2f/amq.default/publish

有了这个身材

{"properties":{},
 "routing_key":"queue_test",
 "payload":"message test ",
 "payload_encoding":"string"}

routing_key 是您要发布消息的队列。

以下使用 chrome 插件的示例:

这里是curl发布消息:

curl -4vvv -u admin:admin \
'localhost:15672/api/exchanges/%2F/amq.default/publish' \
-H 'Content-Type: text/plain;charset=UTF-8' \
--data-binary '{"vhost":"/","name":"amq.default","properties":{"delivery_mode":1,"headers":{}},"routing_key":"MY-QUEUE-NAME","delivery_mode":"1","payload":"TEST","headers":{},"props":{},"payload_encoding":"string"}'

我的样品申请:

用户名:admin
密码:admin
路由键:sample.load.work(我的队列)

    curl --location --request POST 'localhost:15672/api/exchanges/%2F/amq.default/publish' \
--header 'Content-Type: text/plain;charset=UTF-8' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--data-raw '{"vhost":"/","name":"amq.default","properties":{"delivery_mode":1,"headers":{}},"routing_key":"sample.load.work","delivery_mode":"1","payload":"TEST","headers":{},"props":{},"payload_encoding":"string"}'

邮递员片段: