py_rmq_client
A flexible RabbitMQ client for publishing and consuming messages with customizable flow
330
Publish and consume messages with customizable flow. Ideal for testing or experimenting with RabbitMQ configurations. Configurable via CLI arguments and environment variables.
Source code is available on GitHub.
When running the RabbitMQ client, you can specify options through CLI arguments to customize its behavior. Here's a summary of available CLI options:
| Argument | Description | Default | Choices |
|---|---|---|---|
--mode | Client's behavior (publish or consume) | consumer | consumer, publisher |
--message | Message to publish (required in publisher mode) | None | - |
--delay | Delay between operations in seconds | 1.0 | - |
--count | Number of messages to publish (0 for infinite) | 0 | - |
--log-level | Set the log verbosity | debug | critical, error, warning, info, debug |
--verbose | Enable detailed output | True | True, False |
Note: If you're in
publishermode, the--messageargument is required.
Note #2: It's better to set
log-levelto "warning" or higher so that you won't see too many messages regarding connection info
Alternatively, you can configure RabbitMQ using environment variables. Here's the list of supported variables and their default values:
| Environment Variable | Description | Default |
|---|---|---|
RABBITMQ_HOST | The RabbitMQ server hostname | localhost |
RABBITMQ_PORT | The port RabbitMQ is running on | 5672 |
RABBITMQ_DEFAULT_USER | Username for connecting to RabbitMQ | guest |
RABBITMQ_DEFAULT_PASS | Password for the user | guest |
RABBITMQ_QUEUE_NAME | Name of the queue to consume/publish messages to | my_queue |
RABBITMQ_SSL_ENABLED | Whether to enable SSL for the connection | False |
RABBITMQ_SSL_CA_CERTS | Path to the SSL CA certificate | None |
EXCHANGE_NAME | RabbitMQ exchange name | "" |
EXCHANGE_TYPE | Exchange type (e.g., direct, fanout, topic, headers) | direct |
RABBITMQ_ROUTING_KEY | Routing key for binding queue to exchange | Value of RABBITMQ_QUEUE_NAME |
In the docker-compose.yml, you can customize the entrypoint to control how the client runs.
Below are two examples to configure the entrypoint.
Publisher mode:
services:
rmq:
image: fouriermourier/py_rmq_client:latest
## if you need to build from scratch:
# build:
# context: ./
# dockerfile: Dockerfile
env_file:
- .env
entrypoint:
- rmq
- --mode=publisher
- --message="hello there"
- --delay=0.6
- --count=10
- --log-level=warning
- --verbose=True
Consumer mode:
services:
rmq:
image: fouriermourier/py_rmq_client:latest
## if you need to build from scratch:
# build:
# context: ./
# dockerfile: Dockerfile
env_file:
- .env
entrypoint:
- rmq
- --mode=consumer
- --delay=0.3
- --log-level=warning
- --verbose=True
You can run the publisher mode with a custom message, delay, and count of messages to send:
docker-compose -f docker-compose.yaml run consumer --mode=publisher --message="hello world" --delay=1 --count=5 --log-level=warning
The client will publish "hello world" 5 times with a 1-second delay between each message.
To run the consumer:
docker-compose -f docker-compose.yaml run consumer --mode=publisher --message="hello world" --delay=1 --count=5 --log-level=warning
The consumer will process messages with a 1.5-second delay between each one.
By default, the client uses the values below:
5672""directlocalhostguestguestmy_queueFalseNoneRABBITMQ_QUEUE_NAME if specified, otherwise - value of the my_queue parameterFeel free to adjust .env file or ConfigMap in case of running in k8s to your specific credentials.
Content type
Image
Digest
sha256:faba9eeaa…
Size
23.3 MB
Last updated
almost 2 years ago
docker pull fouriermourier/py_rmq_client