Skip to main content

amqp-client-cli

PyPI Version Supported Versions

A simple CLI tool for sending amqp messages to exchanges.

What is the purpose of amqp-client-cli?

The purpose of this command line tool is to make sending messages to exchanges as simple as possible. Uses include:

  • In cron scripts that periodically send simple messages to an ampq server for workers to pick up.
  • Unit testing during implementation of an amqp system into a workflow.
  • Simple one-off queue messages where anything more than a simple command line tool is a hassle to use.

What does amqp-client-cli not do?

This tool is not intended for configuration. It assumes your entire infrastructure is already in place. It can only send to existing exchanges and vhosts and provide a routing key.

It is up to you to configure your infrastructure elsewhere before using this tool (i.e. through your queue workers, through something like rabbitmqadmin, through a web management console. etc).

How do I get it?

Install via pip:

pip install amqp_client_cli

How do I use it?

amqp-client-cli is run via the amqpcli command. Run the help subcommand to see the list of options:

$ amqpcli --help
usage: amqpcli [-h] {send,config} ...

A command line interface for interacting with amqp exchanges

positional arguments:
  {send,config}
    send         Send a message to an exchange.
    config       Configure the amqpcli client.

optional arguments:
  -h, --help     show this help message and exit

Let's send a message!

Sending messages can be done using the amqpcli send command.

$amqpcli send --help
usage: amqpcli send [-h] [-n] (-m MESSAGE | -f FILE_PATH) [-p] [-s] [-u USER] [-v VHOST]
                    host port exchange routing_key

positional arguments:
  host                  Address of the amqp server.
  port                  Port of the amqp server.
  exchange              Name of the exchange being sent to.
  routing_key           The routing key for the message.

optional arguments:
  -h, --help            show this help message and exit
  -n, --nocolor         Do not colorize output.
  -m MESSAGE, --message MESSAGE
                        String to use as the message body.
  -f FILE_PATH, --file-path FILE_PATH
                        Path of a file to use as the message body.
  -p, --persistent      Make the message persistent if routed to a durable queue.
  -s, --ssl             Use ssl/tls as the connection protocol.
  -u USER, --user USER  User to connect to the queue as.
  -v VHOST, --vhost VHOST
                        The vhost to connect to.

Let's assume we have a RabbitMQ server listening at localhost:5671 with an exchange we would like to send a message to named exchange_a on a vhost my_vhost with a routing key of simple_message. We are going to send via the guest user.

Let's define our message on the command line!

$ amqpcli send localhost 5671 exchange_a simple_message -m "Hello there" -v my_vhost -s
User: guest
Password:
Connecting to queue @ localhost:5671... SUCCESS!
Message successfully published to exchange [exchange_a]!

Let's define our message as a file!

The message body can also be a file. It will be interpreted as binary.

Warning: Although any binary content can be sent, it is not recommended to insert large payloads into the queue for performance reasons.

$ echo "I'm a message in a file" > my_message.txt
$ amqpcli send localhost 5671 exchange_a simple_message -f my_message.txt -v my_vhost -s
User: guest
Password:
Connecting to queue @ localhost:5671... SUCCESS!
Message successfully published to exchange [exchange_a]!

How can I specify credentials/configurations for a script?

You can optionally add user credentials to a config file for use with the tool (~/.amqpclirc). There is no limit to the number of users that can be added.

Configuration options can be seen from the command line.

$ amqpcli config --help
usage: amqpcli config [-h] {add_user,delete_user,list_users} ...

positional arguments:
  {add_user,delete_user,list_users}
    add_user            Add a new queue user to config or edit an existing one.
    delete_user         Delete an existing user from the config.
    list_users          List existing users in config.

optional arguments:
  -h, --help            show this help message and exit

With add_user, you will be prompted for a username, password, and vhost (default is /).

A user can also be specified in the environment variables by defining AMQP_USER, AMQP_PASSWORD, and AMQP_VHOST.

$ amqpcli config add_user
User: guest
Password:
vhost? [/]: my_vhost
$ amqpcli send localhost 5671 exchange_a simple_message -m "Hello there" -u guest
Connecting to queue @ localhost:5671... SUCCESS!
Message successfully published to exchange [exchange_a]!

Metadata

Release files for amqp-client-cli 0.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for amqp-client-cli 0.4.1
File Size Uploaded
amqp_client_cli-0.4.1.tar.gz 6.5 kB Details

Release files / amqp_client_cli-0.4.1.tar.gz

Download URL amqp_client_cli-0.4.1.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
65d5ac995339578b102c45a0155e02d8f799b7f022c233acdda0e162a75c1153
BLAKE2b-256 checksum
How to use checksums
c0ce2ee88bfad27311881b045d9bb3f29d92d2bb5a1c112c2d92b436e1382b08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

Release history Release notifications | RSS feed

This release

0.4.1 This release

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page