Docker & Setup
A 3-node cluster, definitions as code, and the lab profile
Two compose files in rabbitmq/, as in every module.
The minimal stack
services:
rabbitmq:
image: rabbitmq:4.3.6-management
ports:
- "5672:5672" # AMQP
- "15672:15672" # management UI
volumes:
- rabbitmq_data:/var/lib/rabbitmq
volumes:
rabbitmq_data:cd rabbitmq
docker compose up -d
open http://localhost:15672 # guest / guestThe -management image includes the web UI and HTTP API. The built-in
guest user can only log in from localhost, a deliberate safety default
that trips up everyone who tries it from another container.
The cluster
docker compose down
docker compose -f compose_prod.yaml up -d
docker exec rabbit-1 rabbitmqctl cluster_status
Running Nodes
rabbit@rabbit-1
rabbit@rabbit-2
rabbit@rabbit-3Each node mounts the same three files from config/:
The first version of this setup omitted target_cluster_size_hint and the
reconciliation settings. rabbit-1 booted first, imported
definitions.json on its own, and created every quorum queue and stream
with one member: members [rabbit@rabbit-1]. Queues that look
replicated (type quorum) weren't, and losing that node would have lost
them. Always check rabbitmqctl list_queues name type members after
building a cluster.
docker exec rabbit-1 rabbitmqctl -q list_queues -p shop name type leader members
orders.billing quorum rabbit@rabbit-2 [rabbit@rabbit-2, rabbit@rabbit-1, rabbit@rabbit-3]
orders.shipping.eu quorum rabbit@rabbit-2 [rabbit@rabbit-2, rabbit@rabbit-1, rabbit@rabbit-3]
orders.dead quorum rabbit@rabbit-2 [rabbit@rabbit-2, rabbit@rabbit-1, rabbit@rabbit-3]
events.stream stream rabbit@rabbit-2 [rabbit@rabbit-2, rabbit@rabbit-1, rabbit@rabbit-3]The Erlang cookie. Nodes authenticate to each other with a shared
secret, RABBITMQ_ERLANG_COOKIE in the compose file. Nodes with different
cookies can't cluster. Anyone with the cookie and network access can
control the node, so in production it's a secret.
Hostnames matter. A node's name is rabbit@<hostname>, and it's
recorded in the data directory. Change the hostname and the node no longer
recognises its own data. That's why each service has a fixed hostname.
What's pre-loaded
definitions.json creates a small shop topology in vhost shop:
| Object | Name | Purpose |
|---|---|---|
| Topic exchange | orders | Routing keys like order.created.eu |
| Fanout exchange | notifications | Broadcast to every bound queue |
| Direct exchange | dlx | Dead letters |
| Quorum queue | orders.billing | Bound with order.*.*; dead-letters to dlx after 3 failed deliveries |
| Quorum queue | orders.shipping.eu | Bound with order.*.eu |
| Quorum queue | orders.dead | Where billing's dead letters go |
| Stream | events.stream | 7-day replayable log |
| Policy | lab-limits | Caps lab.* queues at 100k messages |
And three users: admin (everything), app (messaging in shop, can
only declare lab.*, tmp.*, and server-named queues), and
monitoring (read-only UI).
Ports
| Port | Use |
|---|---|
| 5672 / 5673 / 5674 | AMQP on rabbit-1 / 2 / 3 |
| 15672 | Management UI and HTTP API (rabbit-1) |
| 15692 / 15693 / 15694 | Prometheus metrics |
| 5552 | Stream protocol (rabbit-1) |
The labs
docker compose -f compose_prod.yaml --profile labs build labs
docker compose -f compose_prod.yaml run --rm labs python exchanges.pyThe labs connect as app with all three nodes' addresses, and try each in
turn (labs/common.py), so they keep working when a node is down.
Everyday commands
docker exec rabbit-1 rabbitmq-diagnostics status
docker logs -f rabbit-1
docker compose -f compose_prod.yaml stop # keep data
docker compose -f compose_prod.yaml down -v # delete everything