Based on: https://github.com/pardahlman/docker-rabbitmq-cluster
git clone https://github.com/mentels/docker-rabbitmq-cluster.git
cd docker-rabbitmq-cluster
docker-compose upMost things will be how you expect:
- The default username and password are
guest/guest - The broker accepts connections on
localhost:5672 - The Management interface is found at
localhost:15672
Additionally each container exposes the broker AMQP and MGMT interface port at:
- 5672+(container no)
- 15672+(container no) respectively.
E.g. rabbitmq1 can be reached at 5673 (5672+1) for AMQP and 15673 (15672+1) for the Management interface.
The .env file contains:
RABBITMQ_ERLANG_COOKIEenvironment variable that can be used to change the Erlang cookie.RABBITMQ_DOCKER_TAGenvironment variable that can be used to change the RabbitMQ Docker image tag. By default it is set to3.8-management.
Configuration of the broker is exposed via this file.
Advanced configuration of the broker is exposed by this file (empty by default).
Enabled plugins can be changed via this file.
First make sure the RabbitMQ cluster is running:
docker-compose exec rabbitmq1 rabbitmqctl cluster_status
# ....
# Running Nodes
# rabbit@rabbitmq1
# rabbit@rabbitmq2
# rabbit@rabbitmq3Get the rabbitmqadmin tool:
curl http://localhost:15672/cli/rabbitmqadmin -o rabbitmqadmin
chmod u+x rabbitmqadminThen declare a queue, publish some message and get that message from a queue:
./rabbitmqadmin declare queue name=my_queue
./rabbitmqadmin publish routing_key=my_queue payload=szkolarabbita
./rabbitmqadmin get queue=my_queue ackmode=ack_requeue_false
# from: http://localhost:15672/api/index.html
# ackmode determines whether the messages will be removed from the queue. If ackmode is ack_requeue_true or reject_requeue_true they will be requeued - if ackmode is ack_requeue_false or reject_requeue_false they will be removed.
Now using the Management Plugin one can see stats for the my_queue to see that the message really went through it: http://localhost:15672/#/queues/%2F/my_queue
NOTE: When using the
rabbitmqadminall the interactions with broker go through the HTTP API exposed by the Management Plugin.
Install python dependencies:
NOTE: For this to work you need to have pipenv installed.
cd python/ && pipenv installThen once you are in the python/ directory start a consumer and attach it to a
another_queue:
pipenv run python consume.py --queue another_queue
# => [*] Waiting for messages. To exit press CTRL+CThen publish a message to our queue:
pipenv run python send.py --queue another_queue --message hello
# => [x] Sent 'hello'Finally, you can check the another_queue stats at http://localhost:15672/#/queues/%2F/another_queue.
The stats for a queue can also be obtained with an HTTP request, e.g.
curl -u guest:guest http://localhost:15672/api/queues/%2F/another_queue | jq '.message_stats'See HTTP API Stats section in the HTTP API documentation.
To stop and remove the containers run:
docker-compose down