2016-03-28 23:04:01 +08:00
# RabbitMQ CLI Tools
2016-02-03 02:54:36 +08:00
2019-01-23 11:44:23 +08:00
This repository contains [RabbitMQ CLI tools ](https://rabbitmq.com/cli.html ) ([rabbitmqctl](https://www.rabbitmq.com/man/rabbitmqctl.1.man.html) and
others).
2016-02-03 02:54:36 +08:00
2019-01-23 11:44:23 +08:00
This generation of CLI tools first shipped with RabbitMQ `3.7.0` .
2016-02-04 00:13:02 +08:00
2016-11-04 22:03:33 +08:00
## Goals
Team RabbitMQ wanted a set of tools that
* Was extensible from/with plugins
* Supported pluggable output formats (in particular machine-friendly ones)
* Had good test coverage
* Wasn't as coupled to the server repository
2019-03-20 16:13:07 +08:00
* Could be used as a low risk vehicle for [Elixir ](https://elixir-lang.org ) evaluation
2016-11-04 22:03:33 +08:00
2016-05-26 06:32:20 +08:00
## Supported RabbitMQ Versions
2019-01-23 11:44:23 +08:00
Long lived branches in this repository track the same branch in RabbitMQ core and related
2022-06-05 20:36:53 +08:00
repositories. So `master` tracks `master` in rabbitmq-server, `v3.10.x` tracks branch `v3.10.x` in
2019-01-23 11:44:23 +08:00
rabbitmq-server and so on.
2016-05-26 06:32:20 +08:00
2019-01-23 11:44:23 +08:00
Please use the version of CLI tools that come with the RabbitMQ distribution version installed.
2016-05-26 06:32:20 +08:00
2016-02-04 00:13:02 +08:00
2016-03-28 23:04:01 +08:00
## Building
2016-03-04 00:34:13 +08:00
### Requirements
2019-01-23 11:44:23 +08:00
Building this project requires
2022-06-05 20:36:53 +08:00
* Erlang/OTP 23.3 (or later)
* [Elixir ](https://elixir-lang.org/ ) 1.12.0 (or later).
2016-03-04 00:34:13 +08:00
2016-11-03 20:27:29 +08:00
Command line tools depend on [rabbitmq-common ](https://github.com/rabbitmq/rabbitmq-common ).
Dependencies are being resolved by `erlang.mk`
2016-03-04 00:34:13 +08:00
2016-05-24 17:41:15 +08:00
### Building Standalone Executables
2016-03-04 00:34:13 +08:00
2017-04-08 17:07:03 +08:00
This repo produces a `rabbitmqctl` executable which can be used as different tools
2020-03-17 01:30:14 +08:00
(`rabbitmq-plugins`, `rabbitmq-diagnostics` , `rabbitmq-queues` , `rabbitmq-streams` , `rabbitmq-upgrade` ) by copying or symlinking it with different names.
2017-06-30 15:27:56 +08:00
Depending on the name, a different set of commands will be loaded and available, including
for `--help` .
2016-11-03 20:27:29 +08:00
To generate the executable, run
2016-03-04 00:34:13 +08:00
```
2016-11-04 22:03:33 +08:00
make
2016-03-04 00:34:13 +08:00
```
2016-12-14 19:27:53 +08:00
## Usage
2016-03-04 00:34:13 +08:00
2016-05-24 17:41:15 +08:00
### `rabbitmqctl`
2019-04-01 18:54:04 +08:00
See `rabbitmqctl help` and [rabbitmqctl man page ](https://www.rabbitmq.com/man/rabbitmqctl.1.man.html ) for details.
2019-01-23 11:44:23 +08:00
### `rabbitmq-plugins`
2019-04-01 18:54:04 +08:00
See `rabbitmq-plugins help` and [rabbitmq-plugins man page ](https://www.rabbitmq.com/man/rabbitmq-plugins.1.man.html ) for details.
2016-03-04 00:34:13 +08:00
2019-01-23 11:44:23 +08:00
### `rabbitmq-diagnostics`
2019-04-01 18:54:04 +08:00
See `rabbitmq-diagnostics help` and [rabbitmq-diagnostics man page ](https://www.rabbitmq.com/rabbitmq-diagnostics.8.html ).
2016-03-04 00:34:13 +08:00
2016-03-28 23:04:01 +08:00
## Testing
2016-02-04 00:13:02 +08:00
2016-12-14 19:27:53 +08:00
See [CONTRIBUTING.md ](CONTRIBUTING.md ).
2016-02-04 00:13:02 +08:00
2016-02-03 23:01:32 +08:00
2016-03-28 23:04:01 +08:00
## Developing
2016-11-15 06:00:50 +08:00
2016-05-05 07:14:55 +08:00
### Adding a New Command
2016-03-02 06:48:32 +08:00
2016-07-11 01:01:00 +08:00
#### Conventions
2016-03-02 06:48:32 +08:00
2016-07-11 01:01:00 +08:00
RabbitMQ CLI tools use module name conventions to match the command-line
actions (commands) to modules. The convention is outlined in the `CommandBehaviour` module.
2016-03-02 06:48:32 +08:00
2016-07-11 01:01:00 +08:00
#### Command Module Interface
Each command module must implement the `RabbitMQ.CLI.CommandBehaviour` behaviour,
which includes the following functions:
2016-03-09 02:41:53 +08:00
2016-11-15 06:05:45 +08:00
* `validate(args, opts)` , which returns either `:ok` or a tuple of `{:validation_failure, failure_detail}` where failure detail is typically one of: `:too_many_args` , `:not_enough_args` or `{:bad_argument, String.t}` .
2016-05-28 00:03:55 +08:00
2016-11-15 06:05:45 +08:00
* `merge_defaults(args, opts)` , which is used to return updated arguments and/or options.
2016-05-28 00:03:55 +08:00
2016-11-15 06:05:45 +08:00
* `run(args, opts)` , where the actual command is implemented. Here, `args` is a list of command-specific parameters and `opts` is a Map containing option flags.
2016-03-09 02:41:53 +08:00
2016-11-15 06:05:45 +08:00
* `usage` , which returns a string describing the command, its arguments and its optional flags.
* `banner(args, opts)` , which returns a string to be printed before the command output.
2016-05-05 07:14:55 +08:00
2017-04-08 17:07:03 +08:00
There are also a number of optional callbacks:
2016-05-05 07:14:55 +08:00
2016-12-13 22:59:50 +08:00
* `switches` , which returns command specific switches.
2017-04-08 17:07:03 +08:00
* `aliases` , which returns a list of command aliases (if any).
2016-11-15 06:05:45 +08:00
* `formatter` : what output formatter should be used by default.
* `usage_additional` : extra values appended to the `usage` output
to provide additional command-specific documentation.
* `scopes` : what scopes this command appears in. Scopes associate
2020-03-17 01:30:14 +08:00
tools (e.g. `rabbitmqctl` , `rabbitmq-diagnostics` , `rabbitmq-queues` , `rabbitmq-streams` ) with commands.
2017-12-07 02:10:11 +08:00
* `distribution` : control erlang distribution.
Can be `:cli` (default), `:none` or `{:fun, fun}`
2016-05-28 00:03:55 +08:00
2016-11-30 23:26:15 +08:00
### Tutorial
2016-05-28 00:03:55 +08:00
2016-12-01 00:35:18 +08:00
We have [a tutorial ](./COMMAND_TUTORIAL.md ) that demonstrates how to add a CLI
2016-11-30 23:26:15 +08:00
command that deletes a queue.
2016-03-05 06:36:49 +08:00
2016-11-30 23:26:15 +08:00
### Examples
2016-03-02 06:48:32 +08:00
2019-01-23 11:44:23 +08:00
See `lib/rabbitmq/cli/ctl/commands/status_command.ex` and `test/status_command_test.exs` for minimalistic
but not entirely trivial examples.
2016-03-02 06:48:32 +08:00
2016-07-11 01:01:00 +08:00
## Copyright and License
2016-02-03 23:37:07 +08:00
2016-03-28 23:04:01 +08:00
The project is [licensed under the MPL ](LICENSE-MPL-RabbitMQ ), the same license
as RabbitMQ.
2016-07-11 01:01:00 +08:00
2024-02-06 01:26:25 +08:00
(c) 2007-2024 Broadcom. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
2019-01-23 11:44:23 +08:00