Skip to content

mentels/docker-rabbitmq-cluster

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cluster RabbitMQ 🐰

Based on: https://github.com/pardahlman/docker-rabbitmq-cluster

Install

git clone https://github.com/mentels/docker-rabbitmq-cluster.git
cd docker-rabbitmq-cluster
docker-compose up

Most 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.

Customize

The .env file

The .env file contains:

  1. RABBITMQ_ERLANG_COOKIE environment variable that can be used to change the Erlang cookie.
  2. RABBITMQ_DOCKER_TAG environment variable that can be used to change the RabbitMQ Docker image tag. By default it is set to 3.8-management.

The config/rabbitmq.conf

Configuration of the broker is exposed via this file.

The config/advanced.config

Advanced configuration of the broker is exposed by this file (empty by default).

The config/enabled_plugins

Enabled plugins can be changed via this file.

Use

First make sure the RabbitMQ cluster is running:

docker-compose exec rabbitmq1 rabbitmqctl cluster_status
# ....
# Running Nodes
# rabbit@rabbitmq1
# rabbit@rabbitmq2
# rabbit@rabbitmq3

With rabbitmqadmin tool

Get the rabbitmqadmin tool:

curl http://localhost:15672/cli/rabbitmqadmin -o rabbitmqadmin
chmod u+x rabbitmqadmin

Then 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 rabbitmqadmin all the interactions with broker go through the HTTP API exposed by the Management Plugin.

With Python snippets

Install python dependencies:

NOTE: For this to work you need to have pipenv installed.

cd python/ && pipenv install

Then 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+C

Then 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.

Curling stats

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.

Clean-up

To stop and remove the containers run:

docker-compose down

About

Cluster RabbitMQ (official docker image)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 64.4%
  • Shell 35.6%