This is a simple Go application designed to benchmark consumer performance for RabbitMQ streams. It connects to one or more streams, consumes messages, and logs consumption statistics (total messages, messages per second, and average entries per message) to the standard output.
- Go (version 1.18 or later)
- A running RabbitMQ instance with the
streamplugin enabled.
First, build the executable:
go build .This will create an executable file named rmq-bench in the project directory.
You can run the application with default settings or customize its behavior using command-line flags or environment variables.
To run with default settings (connects to localhost:5552, stream stream1):
./rmq-benchPress Ctrl+C to gracefully shut down the application.
The application can be configured via command-line flags or environment variables. If both are present, command-line flags take precedence.
| Flag | Environment Variable | Description | Default |
|---|---|---|---|
--streams |
RMQ_STREAMS |
Comma-separated list of streams to consume from | stream1 |
--host |
RMQ_HOST |
RabbitMQ host | localhost |
--vhost |
RMQ_VHOST |
RabbitMQ vhost | / |
--port |
RMQ_PORT |
RabbitMQ stream port | 5552 |
--user |
RMQ_USER |
RabbitMQ user | guest |
--password |
RMQ_PASSWORD |
RabbitMQ password | guest |
--max-consumers |
RMQ_MAX_CONSUMERS |
Max consumers per stream | 5 |
--timeout |
RMQ_TIMEOUT |
Producer timeout | 10s |
--initial-credits |
RMQ_INITIAL_CREDITS |
Initial credits | 100 |
--log-interval |
LOG_INTERVAL |
Log interval in seconds | 5 |
--crc-check |
RMQ_CRC_CHECK |
Enable CRC check for consumers | true |
This command connects to a stream named stream1 on localhost:5552.
./rmq-benchTo consume from stream-a and stream-b:
./rmq-bench --streams stream-a,stream-bBy default, the CRC check is enabled. To disable it:
./rmq-bench --crc-check=false./rmq-bench --host my-rabbit.example.com --port 5553To log statistics every 1 second instead of the default 5 seconds:
./rmq-bench --log-interval 1You can also configure the application using environment variables, which is useful in containerized environments.
export RMQ_HOST="rabbitmq.example.com"
export RMQ_USER="admin"
export RMQ_PASSWORD="super-secret-password"
export RMQ_STREAMS="telemetry,logs"
export LOG_INTERVAL="10"
export RMQ_CRC_CHECK="false"
./rmq-bench