Skip to content

Commit

Permalink
Merge pull request #1 from tmikulin/develop
Browse files Browse the repository at this point in the history
creating the first 1.0.0-rc.1 release
  • Loading branch information
tmikulin authored Aug 5, 2020
2 parents f476eec + 3ad4bb7 commit 4d7163f
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RABBIT_VERSION=3.8.1
RABBIT_COOKIE=asdflw23r2kemcald
RABBIT_USER=guest
RABBIT_PASS=guest
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Tomislav Mikulin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
56 changes: 55 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,55 @@
awesome rabbitmq in cluster docker-compose
## Description

This docker-compose file allows you to create an **rabbitmq cluster** for local development or testing

It uses the [official rabbitmq docker image](https://hub.docker.com/_/rabbitmq?tab=description) :rocket:


### * Note on features

The default version is the **rabbitmq version 3.8.1** because of its [SAC capability](https://www.cloudamqp.com/blog/2019-04-23-rabbitmq-3-8-feature-focus-single-active-consumer.html), namely having multiple consumers on one particular queue but with only one active at a time.

The compose file is setup with sane defaults that you can change (.env file), and the `bash script + advanced.config` with the added modifications for the cluster configuration:

- `ha policy` (mirroring of queues on all nodes)
- `pause minority` as the partition handling strategy (because s*** happens :fire: and you need to be prepared)


## General Instructions

Just clone this repo, and run the following commands:

```
chmod +x ./create_cluster.sh
docker-compose up -d && ./create_cluster.sh
or
docker-compose up
./create_cluster.sh
```

The bash script joins the slave nodes to the cluster and it just needs to `run once` :warning:,
on every other usage just run the compose file.

My intent was not to change the original rabbitmq docker image, but just boost it a little to create a `practical rabbitmq cluster`.

Tested on macOS Sierra (version 10.12.6) and Ubuntu/Kubuntu 18
```
docker version 19.03.8/11
docker-compose 1.22.0/1.25.5
```


## Release Notes

### Latest Changes

### 1.0.0-rc.1

2020-08-05:

* The starting point is with the rabbitmq version 3.8.1

## License

This project is licensed under the terms of the MIT license.
8 changes: 8 additions & 0 deletions advanced.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{ rabbit,
[
{cluster_partition_handling, pause_minority}
]
}
].

38 changes: 38 additions & 0 deletions create_cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

set -e

# define all the slave nodes here
# just make sure you always have an quorum
# 3,5,7... of nodes including the master node (rabbit1)
rabbits=(rabbit1 rabbit2 rabbit3)

for rabbit in ${rabbits[*]}; do
while :
do
echo "Checking rabbit nodes for connectivity.."
if docker exec -it "$rabbit" rabbitmqctl -q node_health_check;
then
echo "$rabbit is up and ready for the incoming commands..."
if [ "$rabbit" == "rabbit1" ];
then
sleep 2
# setup the HA mode on the rabbit1 (master) node
docker exec -it "$rabbit" rabbitmqctl set_policy ha-all ".*" '{"ha-mode":"all", "ha-sync-mode":"automatic"}'
break
else
# join the slave nodes to the cluster
docker exec -it "$rabbit" rabbitmqctl stop_app
sleep 1
docker exec -it "$rabbit" rabbitmqctl reset
sleep 1
docker exec -it "$rabbit" rabbitmqctl join_cluster rabbit@rabbit1
sleep 2
docker exec -it "$rabbit" rabbitmqctl start_app
break
fi
else
sleep 1
fi
done
done
52 changes: 39 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,58 @@
version: 3.7
version: '3.7'
services:
rabbit1:
image: rabbitmq:3.8.1-management
image: rabbitmq:${RABBIT_VERSION}-management
hostname: rabbit1
container_name: rabbit1
user: rabbitmq
volumes:
- $PWD/rabbitmq-data:/var/lib/rabbitmq/mnesia/
- rabbitmq-data:/var/lib/rabbitmq/mnesia/
- type: bind
source: $PWD/advanced.config
target: /etc/rabbitmq/advanced.config
environment:
- RABBITMQ_DEFAULT_USER=guest
- RABBITMQ_DEFAULT_PASS=guest
- RABBITMQ_DEFAULT_USER=${RABBIT_USER}
- RABBITMQ_DEFAULT_PASS=${RABBIT_PASS}
- RABBITMQ_ERLANG_COOKIE=${RABBIT_COOKIE}
ports:
- "5672:5672"
- "15672:15672"
rabbit2:
image: rabbitmq:3.8.1-management
image: rabbitmq:${RABBIT_VERSION}-management
hostname: rabbit2
container_name: rabbit2
volumes:
- $PWD/rabbitmq-data:/var/lib/rabbitmq/mnesia/
- rabbitmq-data:/var/lib/rabbitmq/mnesia/
- type: bind
source: $PWD/advanced.config
target: /etc/rabbitmq/advanced.config
environment:
- RABBITMQ_DEFAULT_USER=guest
- RABBITMQ_DEFAULT_PASS=guest
- RABBITMQ_DEFAULT_USER=${RABBIT_USER}
- RABBITMQ_DEFAULT_PASS=${RABBIT_PASS}
- RABBITMQ_ERLANG_COOKIE=${RABBIT_COOKIE}
ports:
- "5673:5672"
- "15673:15672"
depends_on:
- rabbit1
rabbit3:
image: rabbitmq:3.8.1-management
image: rabbitmq:${RABBIT_VERSION}-management
hostname: rabbit3
container_name: rabbit3
volumes:
- $PWD/rabbitmq-data:/var/lib/rabbitmq/mnesia/
- rabbitmq-data:/var/lib/rabbitmq/mnesia/
- type: bind
source: $PWD/advanced.config
target: /etc/rabbitmq/advanced.config
environment:
- RABBITMQ_DEFAULT_USER=guest
- RABBITMQ_DEFAULT_PASS=guest
- RABBITMQ_DEFAULT_USER=${RABBIT_USER}
- RABBITMQ_DEFAULT_PASS=${RABBIT_PASS}
- RABBITMQ_ERLANG_COOKIE=${RABBIT_COOKIE}
ports:
- "5674:5672"
- "15674:15672"
depends_on:
- rabbit1

volumes:
rabbitmq-data:

0 comments on commit 4d7163f

Please sign in to comment.