Learn Labs
Foundations

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 / guest

The -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-3

Each node mounts the same three files from config/:

rabbitmq.confclustering, default queue type, alarms, loggingenabled_pluginsmanagement, prometheus, stream, stream_managementdefinitions.jsonusers, vhosts, permissions, exchanges, queues, bindings, policies
config/rabbitmq.conf (key settings)
cluster_formation.peer_discovery_backend = classic_configjoin the listed nodes at first bootcluster_formation.classic_config.nodes.1 = rabbit@rabbit-1cluster_formation.target_cluster_size_hint = 3wait for 3 nodes (see below)quorum_queue.continuous_membership_reconciliation.enabled = truequorum_queue.continuous_membership_reconciliation.target_group_size = 3definitions.local.path = /etc/rabbitmq/definitions.jsontopology as code, loaded at bootdefault_queue_type = quorumreplicated queues unless asked otherwisevm_memory_high_watermark.relative = 0.6block publishers at 60% of RAMdisk_free_limit.absolute = 1GBblock publishers below 1 GB free disk
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:

ObjectNamePurpose
Topic exchangeordersRouting keys like order.created.eu
Fanout exchangenotificationsBroadcast to every bound queue
Direct exchangedlxDead letters
Quorum queueorders.billingBound with order.*.*; dead-letters to dlx after 3 failed deliveries
Quorum queueorders.shipping.euBound with order.*.eu
Quorum queueorders.deadWhere billing's dead letters go
Streamevents.stream7-day replayable log
Policylab-limitsCaps 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

PortUse
5672 / 5673 / 5674AMQP on rabbit-1 / 2 / 3
15672Management UI and HTTP API (rabbit-1)
15692 / 15693 / 15694Prometheus metrics
5552Stream 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.py

The 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

On this page