Skip to content

Instantly share code, notes, and snippets.

@Pliner
Last active October 8, 2022 15:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Runs 5 nodes rabbitmq cluster locally in docker-compose
services:
rabbit_1: &rmq
image: rabbitmq:management
hostname: rabbit_1
ports:
- "15673:15672"
- "5673:5672"
environment:
- RABBITMQ_ERLANG_COOKIE='mysecret'
healthcheck:
test: rabbitmq-diagnostics -q ping
interval: 10s
timeout: 5s
retries: 5
rabbit_2:
<<: *rmq
hostname: rabbit_2
ports:
- "15674:15672"
- "5674:5672"
rabbit_3:
<<: *rmq
hostname: rabbit_3
ports:
- "15675:15672"
- "5675:5672"
rabbit_4:
<<: *rmq
hostname: rabbit_4
ports:
- "15676:15672"
- "5676:5672"
rabbit_5:
<<: *rmq
hostname: rabbit_5
ports:
- "15677:15672"
- "5677:5672"
rabbit_cluster:
image: rabbitmq:management
hostname: rabbit_cluster
depends_on:
rabbit_1:
condition: service_healthy
rabbit_2:
condition: service_healthy
rabbit_3:
condition: service_healthy
rabbit_4:
condition: service_healthy
rabbit_5:
condition: service_healthy
environment:
- RABBITMQ_ERLANG_COOKIE='mysecret'
command:
- /bin/sh
- -c
- |
echo "Waiting 20s to ensure the nodes initialized"
sleep 20
echo "Joining rabbit_2 to rabbit_1"
rabbitmqctl -n rabbit@rabbit_2 stop_app
rabbitmqctl -n rabbit@rabbit_2 join_cluster rabbit@rabbit_1
rabbitmqctl -n rabbit@rabbit_2 start_app
echo "Joining rabbit_3 to rabbit_1"
rabbitmqctl -n rabbit@rabbit_3 stop_app
rabbitmqctl -n rabbit@rabbit_3 join_cluster rabbit@rabbit_1
rabbitmqctl -n rabbit@rabbit_3 start_app
echo "Joining rabbit_4 to rabbit_1"
rabbitmqctl -n rabbit@rabbit_4 stop_app
rabbitmqctl -n rabbit@rabbit_4 join_cluster rabbit@rabbit_1
rabbitmqctl -n rabbit@rabbit_4 start_app
echo "Joining rabbit_5 to rabbit_1"
rabbitmqctl -n rabbit@rabbit_5 stop_app
rabbitmqctl -n rabbit@rabbit_5 join_cluster rabbit@rabbit_1
rabbitmqctl -n rabbit@rabbit_5 start_app
@foobarbazmeow
Copy link

services:
    rabbit_1: &rmq
        image: rabbitmq:management
        hostname: rabbit_1
        ports:
            - "15673:15672"
            - "5673:5672"
        environment:
            - RABBITMQ_ERLANG_COOKIE='mysecret'
        healthcheck:
          test: rabbitmq-diagnostics -q ping
          interval: 10s
          timeout: 5s
          retries: 5

    rabbit_2:
        <<: *rmq
        hostname: rabbit_2
        ports:
            - "15674:15672"
            - "5674:5672"

    rabbit_3:
        <<: *rmq
        hostname: rabbit_3
        ports:
            - "15675:15672"
            - "5675:5672"

    rabbit_4:
        <<: *rmq
        hostname: rabbit_4
        ports:
            - "15676:15672"
            - "5676:5672"


    rabbit_5:
        <<: *rmq
        hostname: rabbit_5
        ports:
            - "15677:15672"
            - "5677:5672"

    rabbit_cluster:
        image: rabbitmq:management
        hostname: rabbit_cluster
        depends_on:
            rabbit_1:
                condition: service_healthy
            rabbit_2:
                condition: service_healthy
            rabbit_3:
                condition: service_healthy
            rabbit_4:
                condition: service_healthy
            rabbit_5:
                condition: service_healthy
        environment:
          - RABBITMQ_ERLANG_COOKIE='mysecret'
        command:
          - /bin/sh
          - -c
          - |
            echo "Waiting 20s to ensure the nodes initialized"
            sleep 20
            echo "Joining rabbit_2 to rabbit_1"
            rabbitmqctl -n rabbit@rabbit_2 stop_app
            rabbitmqctl -n rabbit@rabbit_2 join_cluster rabbit@rabbit_1
            rabbitmqctl -n rabbit@rabbit_2 start_app
            echo "Joining rabbit_3 to rabbit_1"
            rabbitmqctl -n rabbit@rabbit_3 stop_app
            rabbitmqctl -n rabbit@rabbit_3 join_cluster rabbit@rabbit_1
            rabbitmqctl -n rabbit@rabbit_3 start_app
            echo "Joining rabbit_4 to rabbit_1"
            rabbitmqctl -n rabbit@rabbit_4 stop_app
            rabbitmqctl -n rabbit@rabbit_4 join_cluster rabbit@rabbit_1
            rabbitmqctl -n rabbit@rabbit_4 start_app
            echo "Joining rabbit_5 to rabbit_1"
            rabbitmqctl -n rabbit@rabbit_5 stop_app
            rabbitmqctl -n rabbit@rabbit_5 join_cluster rabbit@rabbit_1
            rabbitmqctl -n rabbit@rabbit_5 start_app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment