使用HTTP API发布到默认RabbitMQ交换 [英] Publishing to the default rabbitmq exchange using the http api

查看:377
本文介绍了使用HTTP API发布到默认RabbitMQ交换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在使用rabbitmqs http api在rabbit中执行一些非常基本的操作.它在大多数情况下都很好用,但是我在弄清楚如何使用它将消息发布到默认的rabbitmq交换时遇到了问题.此交换始终存在,不能删除,并且具有与每个队列名称相同的路由密钥的每个队列绑定.

So I am using rabbitmqs http api to do some very basic actions in rabbit. It works great in most situations but I am having an issue figuring out how to use it to publish a message to the default rabbitmq exchange. This exchange is always present, cannot be deleted and has a binding to every queue with a routing key equal to the queue name.

我的问题是此队列没有名称,或者,它的名称是空字符串".我必须使用URL来通过HTTP api发布此消息,其中包括交换的名称.

My problem is that this queue does not have a name, or rather, it's name is an empty string "". And the URL I have to use to publish this message with the HTTP api includes the name of the exchange.

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中表示默认交换.

The same article mentions that in order to use the default vhost which has a name of "/", you must use %2f in place of the vhost name. This makes me think there should be a similar way to represent the deafault exchange in the url.

我尝试了几种不同的方法,但都无济于事:

I tried a few different things and none of them worked:

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

我确定我不是唯一遇到此问题的人.任何帮助将非常感激.

I'm sure I can't be the only person that has run into this issue. any help would be much appreciated.

谢谢, 汤姆

推荐答案

这是将消息发布到amq.default的方法:

This is the way to publish a message to amq.default:

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

有这个身体

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

routing_key是您将在其中发布消息的队列.

routing_key is the queue where you will publish the message.

以下是使用chrome插件的示例:

Following an example using a chrome plug-in:

这篇关于使用HTTP API发布到默认RabbitMQ交换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆