RabbitMQ 从命令行创建队列和绑定
如果我的机器上安装了 RabbitMQ,有没有办法从命令行创建消息队列并将其绑定到某个交换而不使用客户端?
我认为这是不可能的,但我想确定一下。
If I have RabbitMQ installed on my machine, is there a way to create a message queue from the command line and bind it to a certain exchange without using a client?
I think it is not possible, but I want to be sure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
摘要:
其他答案是所要求答案的很好替代方案。以下是您可以从命令行使用的命令。
首先,做好所有必要的准备工作,例如安装rabbit、rabbitmqadmin 和rabbitctl。这个想法是使用来自
rabbitmqctl
和rabbitmqadmin
的命令。您可以看到一些命令示例: https://www.rabbitmq.com/management-cli.html< /a>示例命令/设置:
以下命令应该为您提供大部分(如果不是全部)所需的内容:
添加用户和权限
创建虚拟主机并设置权限
进行交换
创建队列
进行绑定
使用 Python 进行绑定的替代方法
以下是命令行绑定的替代方案,因为我有时会遇到问题,并发现以下 python 代码更可靠。
上面的代码可以作为使用 python 的脚本的一部分运行。请注意,我将传出的内容放入数组中,这将允许您迭代它们。这应该会使部署变得容易。
最后的想法
我认为上述内容应该让您朝着正确的方向前进,如果任何特定命令没有意义,请使用谷歌或使用
rabbitmqadmin help subcommands
阅读更多内容。我尝试使用能够解释自身的变量。Summary:
Other answers are good alternatives to what was asked for. Below are commands you can use from the command line.
First, do all the necessary prep work, e.g. install rabbit,
rabbitmqadmin
, andrabbitctl
. The idea is to use commands fromrabbitmqctl
andrabbitmqadmin
. You can see some command examples: https://www.rabbitmq.com/management-cli.htmlExample Commands/Setup:
The following commands should give you the majority if not all of what you need:
Add a user and permissions
Make a virtual host and Set Permissions
Make an Exchange
Make a Queue
Make a Binding
Alternative Way to Bind with Python
The following is an alternative to command line binding, as I've had issues with it sometimes and found the following python code to be more reliable.
The above can be run as part of a script using python. Notice I put the outgoing stuff into arrays, which will allow you to iterate through them. This should make things easy for deploys.
Last Thoughts
I think the above should get you moving in the right direction, use google if any specific commands don't make sense or read more with
rabbitmqadmin help subcommands
. I tried to use variables that explain themselves.安装RabbitMQ 管理插件。它附带了一个命令行工具,您可以使用它来配置所有队列/交换器等。
Install the RabbitMQ management plugin. It comes with a command line tool which you can use to configure all of your queues/exchanges/etc.
创建Exchange:
创建队列:
将队列绑定到Exchange:
Create Exchange:
Create Queue:
Bind Queue to Exchange:
也许有点晚了,但我已经使用 CURL 做到了。
对于队列:
对于绑定
注意 192.168.99.100:15672 指向我的 RMQ 管理
Maybe a little late to the party but I've done so using CURL.
For queues:
And for bindings
Note 192.168.99.100:15672 points to my RMQ Management
如果您使用的是 Linux Debian,则有一个名为 amqp-tools 的软件包。安装它
然后您可以使用命令行(例如 amqp-publish)将消息发送到您的队列
从队列中收集消息
然后您可以使用或
还有来自 rabbitmq-c 包/库。构建后,您可以通过命令行发送消息,例如
Have fun ...
If you are using Linux Debian, there's a package called amqp-tools. Install it with
You can then use command line such as amqp-publish to send messages to your queue
Then you can collect message(s) from the queue using
or
There are also (command line) examples from rabbitmq-c package / library. After you build it, you can send messages through command line such as
Have fun ...
提供的命令行界面rabbitmqctl 不公开创建队列并绑定它的功能。
然而,使用快速脚本来完成此操作非常简单,RabbitMQ 入门指南在发布者和消费者方面都显示了几个示例。
我掩盖了连接,但它实际上是创建队列的一个衬垫。该操作也是幂等的,这意味着您可以将该语句包含在脚本中并且安全,因为知道它不会不断重新创建队列或清除现有的同名队列。
rabbitmqctl
, the provided command line interface, doesn't expose the ability to create a queue and bind it.It, however, is quite trivial to do it with a quick script though, and the RabbitMQ getting started guide shows several examples of it, both on the publisher as well as the consumer side.
I'm glossing over connecting, but it's a literal one liner to create a queue. The operation is also idempotent, meaning you can include the statement in a script and be safe, knowing that it won't keep recreating the queue or blowing out an existing one of the same name.
从 Windows 上的 CLI 动态创建 RabbitMq 交换、队列和绑定
我已经安装了 RabbitMQ 服务器并运行多个队列和交换,现在想从命令行动态创建它。我知道这是一个老问题,但我认为提供这些信息会有所帮助。
以下是我所做的:
安装
例如:C:\Python26
C:\Python26\python
C:\Python26\rabbitmqadmin.exe
代码:在批处理文件中使用以下命令
通过执行rabbitmqadmin.exe -help -subcommands 它列出了所有可用的命令,
例如:c:\python26\python .exerabbitmqadmin.exe-help-子命令
Create RabbitMq Exchange, Queue and Bindings dynamically from CLI on Windows
I already had a RabbitMQ Server installed and running with multiple queue and exchange and now wanted to create it on the fly from command line. I know it is an old question but I thought giving out this information will be helpful.
Following is what I did:
Setup
eg: C:\Python26
C:\Python26\python
C:\Python26\rabbitmqadmin.exe
Code:in a batch file used the below commands
by executing rabbitmqadmin.exe -help -subcommands it lists all the available commands
eg: c:\python26\python.exe rabbitmqadmin.exe -help -subcommands
对我来说,我的 RabbitMQ 管理交易一直试图重定向到 https 版本...我的设置中的所有内容都是普通的,我什至没有配置文件...无论如何,我的解决方法是手动创建rabbitmqadmin .py 在
sbin
文件夹中,然后填充 https://raw.githubusercontent.com/rabbitmq/rabbitmq-management/v3.8.1/bin/rabbitmqadmin然后,确保
python
位于例如,您的PATH
并运行它来添加交换:For me, my RabbitMQ Management deal kept trying to redirect to the https version... everything in my setup is vanilla, I don't even have a config file... anyways, my work around was to manually create
rabbitmqadmin.py
in thesbin
folder, then fill it with https://raw.githubusercontent.com/rabbitmq/rabbitmq-management/v3.8.1/bin/rabbitmqadminThen, make sure that
python
is in yourPATH
and run this to, for example, add an exchange:这是一个更简单的 Python 示例,取自 RabbitMQ Python 教程 。
首先,安装 pika:
这就是向本地主机发送消息所需的全部内容:
Here is a more minimal Python example, taken from the RabbitMQ Python tutorial.
First, install pika:
This is all you need to send a message to localhost:
如果任何 Windows 用户正在寻找基于 powershell 的解决方案,那么这里有我编写的函数。
将其保存到 helper.ps1 文件中并将其包含到您的脚本中,如下所示
If any windows user looking for powershell based solution then there is the function I have written.
Save this into helper.ps1 file and include it into your script like this
在 RabbitMQ 中创建和删除队列的演练:
我找不到执行此操作的命令行命令。这是我用 java 代码实现的方法。
Ubuntu 上的 Rabbitmq-server 版本
3.3.5
。列出队列,还没有队列:
将其放入 CreateQueue.java
提供您的rabbitmq安装附带的jar文件:
我正在使用rabbitmq-client.jar版本0.9.1,使用您的rabbitmq版本附带的版本。
编译并运行:
它应该顺利完成,现在检查您的队列:
kowalski 队列存在。
Walkthrough to Create and delete a queue in RabbitMQ:
I couldn't find a commandline command to do it. Here is how I did it in code with java.
Rabbitmq-server version
3.3.5
on Ubuntu.List the queues, no queues yet:
Put this in CreateQueue.java
Supply the jar file that came with your rabbitmq installation:
I'm using rabbitmq-client.jar version 0.9.1, use the one that comes with your version of rabbitmq.
Compile and run:
It should finish without errors, check your queues now:
the kowalski queue exists.
有助于在您进行交换时绑定交换:
C-;
helps to bind the exchange while you're at it:
C-;