Skip to content

Commit 4d7163f

Browse files
authored
Merge pull request #1 from tmikulin/develop
creating the first 1.0.0-rc.1 release
2 parents f476eec + 3ad4bb7 commit 4d7163f

File tree

6 files changed

+165
-14
lines changed

6 files changed

+165
-14
lines changed

.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RABBIT_VERSION=3.8.1
2+
RABBIT_COOKIE=asdflw23r2kemcald
3+
RABBIT_USER=guest
4+
RABBIT_PASS=guest

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Tomislav Mikulin
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,55 @@
1-
awesome rabbitmq in cluster docker-compose
1+
## Description
2+
3+
This docker-compose file allows you to create an **rabbitmq cluster** for local development or testing
4+
5+
It uses the [official rabbitmq docker image](https://hub.docker.com/_/rabbitmq?tab=description) :rocket:
6+
7+
8+
### * Note on features
9+
10+
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.
11+
12+
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:
13+
14+
- `ha policy` (mirroring of queues on all nodes)
15+
- `pause minority` as the partition handling strategy (because s*** happens :fire: and you need to be prepared)
16+
17+
18+
## General Instructions
19+
20+
Just clone this repo, and run the following commands:
21+
22+
```
23+
chmod +x ./create_cluster.sh
24+
25+
docker-compose up -d && ./create_cluster.sh
26+
or
27+
docker-compose up
28+
./create_cluster.sh
29+
```
30+
31+
The bash script joins the slave nodes to the cluster and it just needs to `run once` :warning:,
32+
on every other usage just run the compose file.
33+
34+
My intent was not to change the original rabbitmq docker image, but just boost it a little to create a `practical rabbitmq cluster`.
35+
36+
Tested on macOS Sierra (version 10.12.6) and Ubuntu/Kubuntu 18
37+
```
38+
docker version 19.03.8/11
39+
docker-compose 1.22.0/1.25.5
40+
```
41+
42+
43+
## Release Notes
44+
45+
### Latest Changes
46+
47+
### 1.0.0-rc.1
48+
49+
2020-08-05:
50+
51+
* The starting point is with the rabbitmq version 3.8.1
52+
53+
## License
54+
55+
This project is licensed under the terms of the MIT license.

advanced.config

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{ rabbit,
3+
[
4+
{cluster_partition_handling, pause_minority}
5+
]
6+
}
7+
].
8+

create_cluster.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# define all the slave nodes here
6+
# just make sure you always have an quorum
7+
# 3,5,7... of nodes including the master node (rabbit1)
8+
rabbits=(rabbit1 rabbit2 rabbit3)
9+
10+
for rabbit in ${rabbits[*]}; do
11+
while :
12+
do
13+
echo "Checking rabbit nodes for connectivity.."
14+
if docker exec -it "$rabbit" rabbitmqctl -q node_health_check;
15+
then
16+
echo "$rabbit is up and ready for the incoming commands..."
17+
if [ "$rabbit" == "rabbit1" ];
18+
then
19+
sleep 2
20+
# setup the HA mode on the rabbit1 (master) node
21+
docker exec -it "$rabbit" rabbitmqctl set_policy ha-all ".*" '{"ha-mode":"all", "ha-sync-mode":"automatic"}'
22+
break
23+
else
24+
# join the slave nodes to the cluster
25+
docker exec -it "$rabbit" rabbitmqctl stop_app
26+
sleep 1
27+
docker exec -it "$rabbit" rabbitmqctl reset
28+
sleep 1
29+
docker exec -it "$rabbit" rabbitmqctl join_cluster rabbit@rabbit1
30+
sleep 2
31+
docker exec -it "$rabbit" rabbitmqctl start_app
32+
break
33+
fi
34+
else
35+
sleep 1
36+
fi
37+
done
38+
done

docker-compose.yml

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,58 @@
1-
version: 3.7
1+
version: '3.7'
22
services:
33
rabbit1:
4-
image: rabbitmq:3.8.1-management
4+
image: rabbitmq:${RABBIT_VERSION}-management
5+
hostname: rabbit1
6+
container_name: rabbit1
7+
user: rabbitmq
58
volumes:
6-
- $PWD/rabbitmq-data:/var/lib/rabbitmq/mnesia/
9+
- rabbitmq-data:/var/lib/rabbitmq/mnesia/
10+
- type: bind
11+
source: $PWD/advanced.config
12+
target: /etc/rabbitmq/advanced.config
713
environment:
8-
- RABBITMQ_DEFAULT_USER=guest
9-
- RABBITMQ_DEFAULT_PASS=guest
14+
- RABBITMQ_DEFAULT_USER=${RABBIT_USER}
15+
- RABBITMQ_DEFAULT_PASS=${RABBIT_PASS}
16+
- RABBITMQ_ERLANG_COOKIE=${RABBIT_COOKIE}
1017
ports:
1118
- "5672:5672"
1219
- "15672:15672"
1320
rabbit2:
14-
image: rabbitmq:3.8.1-management
21+
image: rabbitmq:${RABBIT_VERSION}-management
22+
hostname: rabbit2
23+
container_name: rabbit2
1524
volumes:
16-
- $PWD/rabbitmq-data:/var/lib/rabbitmq/mnesia/
25+
- rabbitmq-data:/var/lib/rabbitmq/mnesia/
26+
- type: bind
27+
source: $PWD/advanced.config
28+
target: /etc/rabbitmq/advanced.config
1729
environment:
18-
- RABBITMQ_DEFAULT_USER=guest
19-
- RABBITMQ_DEFAULT_PASS=guest
30+
- RABBITMQ_DEFAULT_USER=${RABBIT_USER}
31+
- RABBITMQ_DEFAULT_PASS=${RABBIT_PASS}
32+
- RABBITMQ_ERLANG_COOKIE=${RABBIT_COOKIE}
2033
ports:
2134
- "5673:5672"
2235
- "15673:15672"
36+
depends_on:
37+
- rabbit1
2338
rabbit3:
24-
image: rabbitmq:3.8.1-management
39+
image: rabbitmq:${RABBIT_VERSION}-management
40+
hostname: rabbit3
41+
container_name: rabbit3
2542
volumes:
26-
- $PWD/rabbitmq-data:/var/lib/rabbitmq/mnesia/
43+
- rabbitmq-data:/var/lib/rabbitmq/mnesia/
44+
- type: bind
45+
source: $PWD/advanced.config
46+
target: /etc/rabbitmq/advanced.config
2747
environment:
28-
- RABBITMQ_DEFAULT_USER=guest
29-
- RABBITMQ_DEFAULT_PASS=guest
48+
- RABBITMQ_DEFAULT_USER=${RABBIT_USER}
49+
- RABBITMQ_DEFAULT_PASS=${RABBIT_PASS}
50+
- RABBITMQ_ERLANG_COOKIE=${RABBIT_COOKIE}
3051
ports:
3152
- "5674:5672"
3253
- "15674:15672"
54+
depends_on:
55+
- rabbit1
56+
57+
volumes:
58+
rabbitmq-data:

0 commit comments

Comments
 (0)