Skip to content

Commit 8256f13

Browse files
committed
wip: Boilerplate structure for testing auto-discovery
1 parent 7a8d5fe commit 8256f13

11 files changed

Lines changed: 295 additions & 10 deletions

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
elixir 1.15.7-otp-26
1+
elixir 1.17.2-otp-26
22
erlang 26.1.2

CONTRIBUTING.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,17 @@ Make sure the tests pass:
3535
Make your change. Add tests for your change. Make the tests pass:
3636

3737
mix test
38+
39+
To run the Clustered test, run:
40+
41+
# Start the cluster
42+
docker compose --project-directory services/cluster up -d
43+
# or for proxied
44+
docker compose --project-directory services/proxied-cluster up -d
45+
46+
# Run the tests
47+
mix test --exclude test --include v3_13_proxied_cluster
48+
49+
docker run --network proxied-cluster_rabbitmq -v "${PWD}:/home/rabbitmq-stream" -P elixir:1.17.2-otp-26 /bin/sh -c 'cd /home/rabbitmq-stream; ./services/cluster/test.sh'
50+
51+
<!-- docker run --network proxied-cluster_rabbitmq -v "${PWD}:/home/rabbitmq-stream" --rm -it --entrypoint bash elixir:1.17.2-otp-26-->

mix.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
%{
22
"amqp": {:hex, :amqp, "3.3.0", "056d9f4bac96c3ab5a904b321e70e78b91ba594766a1fc2f32afd9c016d9f43b", [:mix], [{:amqp_client, "~> 3.9", [hex: :amqp_client, repo: "hexpm", optional: false]}], "hexpm", "8d3ae139d2646c630d674a1b8d68c7f85134f9e8b2a1c3dd5621616994b10a8b"},
3-
"amqp10_common": {:hex, :amqp10_common, "3.12.12", "501d769078031f3f39e787620a8cd771815e74e493000f0768b448258d3d90ee", [:make, :rebar3], [], "hexpm", "d38133676450a1128d83a66b06bbb39a1c8c6cb65f7d4e33885786ce8e96022a"},
4-
"amqp_client": {:hex, :amqp_client, "3.12.12", "e7065dc769e2ddec11b66422b131377e656bf656125e526b8fece72d8b4e6fe9", [:make, :rebar3], [{:credentials_obfuscation, "3.4.0", [hex: :credentials_obfuscation, repo: "hexpm", optional: false]}, {:rabbit_common, "3.12.12", [hex: :rabbit_common, repo: "hexpm", optional: false]}], "hexpm", "8b4d591ae0dc8938dcbb49c77df9b19e63e7c3c92d69844babc4fcf7c3184a9d"},
3+
"amqp10_common": {:hex, :amqp10_common, "3.13.6", "4aa7bce71522f6f56898218e013a7bba52600185a84b8c3066e950c84549154e", [:make, :rebar3], [], "hexpm", "defd497445e8bd6ac31f968b9aea68b54ec619ce92686fca9eec59fd76c4b32c"},
4+
"amqp_client": {:hex, :amqp_client, "3.12.14", "2b677bc3f2e2234ba7517042b25d72071a79735042e91f9116bd3c176854b622", [:make, :rebar3], [{:credentials_obfuscation, "3.4.0", [hex: :credentials_obfuscation, repo: "hexpm", optional: false]}, {:rabbit_common, "3.12.14", [hex: :rabbit_common, repo: "hexpm", optional: false]}], "hexpm", "5f70b6c3b1a739790080da4fddc94a867e99f033c4b1edc20d6ff8b8fb4bd160"},
55
"credentials_obfuscation": {:hex, :credentials_obfuscation, "3.4.0", "34e18b126b3aefd6e8143776fbe1ceceea6792307c99ac5ee8687911f048cfd7", [:rebar3], [], "hexpm", "738ace0ed5545d2710d3f7383906fc6f6b582d019036e5269c4dbd85dbced566"},
6-
"earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"},
7-
"ex_doc": {:hex, :ex_doc, "0.31.1", "8a2355ac42b1cc7b2379da9e40243f2670143721dd50748bf6c3b1184dae2089", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "3178c3a407c557d8343479e1ff117a96fd31bafe52a039079593fb0524ef61b0"},
8-
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},
9-
"makeup": {:hex, :makeup, "1.1.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"},
6+
"earmark_parser": {:hex, :earmark_parser, "1.4.41", "ab34711c9dc6212dda44fcd20ecb87ac3f3fce6f0ca2f28d4a00e4154f8cd599", [:mix], [], "hexpm", "a81a04c7e34b6617c2792e291b5a2e57ab316365c2644ddc553bb9ed863ebefa"},
7+
"ex_doc": {:hex, :ex_doc, "0.31.2", "8b06d0a5ac69e1a54df35519c951f1f44a7b7ca9a5bb7a260cd8a174d6322ece", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "317346c14febaba9ca40fd97b5b5919f7751fb85d399cc8e7e8872049f37e0af"},
8+
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
9+
"makeup": {:hex, :makeup, "1.1.2", "9ba8837913bdf757787e71c1581c21f9d2455f4dd04cfca785c70bbfff1a76a3", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cce1566b81fbcbd21eca8ffe808f33b221f9eee2cbc7a1706fc3da9ff18e6cac"},
1010
"makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"},
1111
"makeup_erlang": {:hex, :makeup_erlang, "0.1.5", "e0ff5a7c708dda34311f7522a8758e23bfcd7d8d8068dc312b5eb41c6fd76eba", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "94d2e986428585a21516d7d7149781480013c56e30c6a233534bedf38867a59a"},
1212
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
13-
"rabbit_common": {:hex, :rabbit_common, "3.12.12", "b87525eb02bcd738463d9c64b00f380c30825b6dcfb93c2e1d9168cad239012c", [:make, :rebar3], [{:credentials_obfuscation, "3.4.0", [hex: :credentials_obfuscation, repo: "hexpm", optional: false]}, {:recon, "2.5.3", [hex: :recon, repo: "hexpm", optional: false]}, {:thoas, "1.0.0", [hex: :thoas, repo: "hexpm", optional: false]}], "hexpm", "027b5bf9de22d04198b1c02bc82fc01c9ed4129673218365d728db93a982f424"},
13+
"rabbit_common": {:hex, :rabbit_common, "3.12.14", "466123ee7346a3cdac078c0c302bcd36da4523e8acd678c1b992f7b4df1f7914", [:make, :rebar3], [{:credentials_obfuscation, "3.4.0", [hex: :credentials_obfuscation, repo: "hexpm", optional: false]}, {:recon, "2.5.3", [hex: :recon, repo: "hexpm", optional: false]}, {:thoas, "1.0.0", [hex: :thoas, repo: "hexpm", optional: false]}], "hexpm", "70c31a51f7401cc0204ddef2745d98680c2e0df67e3b0c9e198916881fde3293"},
1414
"recon": {:hex, :recon, "2.5.3", "739107b9050ea683c30e96de050bc59248fd27ec147696f79a8797ff9fa17153", [:mix, :rebar3], [], "hexpm", "6c6683f46fd4a1dfd98404b9f78dcabc7fcd8826613a89dcb984727a8c3099d7"},
1515
"thoas": {:hex, :thoas, "1.0.0", "567c03902920827a18a89f05b79a37b5bf93553154b883e0131801600cf02ce0", [:rebar3], [], "hexpm", "fc763185b932ecb32a554fb735ee03c3b6b1b31366077a2427d2a97f3bd26735"},
1616
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Get hostname from enviromant variable
6+
HOSTNAME=`env hostname`
7+
echo "Starting RabbitMQ Server For host: " $HOSTNAME
8+
9+
if [ -z "$JOIN_CLUSTER_HOST" ]; then
10+
/usr/local/bin/docker-entrypoint.sh rabbitmq-server &
11+
sleep 5
12+
rabbitmqctl wait /var/lib/rabbitmq/mnesia/rabbit\@$HOSTNAME.pid
13+
else
14+
/usr/local/bin/docker-entrypoint.sh rabbitmq-server -detached
15+
sleep 5
16+
rabbitmqctl wait /var/lib/rabbitmq/mnesia/rabbit\@$HOSTNAME.pid
17+
rabbitmqctl stop_app
18+
rabbitmqctl join_cluster rabbit@$JOIN_CLUSTER_HOST
19+
rabbitmqctl start_app
20+
fi
21+
22+
# Keep foreground process active ...
23+
tail -f /dev/null
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Based on https://github.com/serkodev/rabbitmq-cluster-docker
2+
# Same as 'services/proxied-cluster/docker-compose.yaml' but without the load balancer.
3+
services:
4+
rabbitmq1:
5+
image: rabbitmq:3.13-management
6+
hostname: rabbitmq1
7+
environment:
8+
- RABBITMQ_DEFAULT_USER=guest
9+
- RABBITMQ_DEFAULT_PASS=guest
10+
- RABBITMQ_DEFAULT_VHOST=/
11+
- RABBITMQ_ERLANG_COOKIE=12345678
12+
volumes:
13+
- ./cluster-entrypoint.sh:/usr/local/bin/cluster-entrypoint.sh
14+
- ../enabled_plugins:/etc/rabbitmq/enabled_plugins
15+
- ../rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf
16+
- ../cert:/etc/rabbitmq/cert
17+
entrypoint: /usr/local/bin/cluster-entrypoint.sh
18+
networks:
19+
- rabbitmq
20+
21+
rabbitmq2:
22+
image: rabbitmq:3.13-management
23+
hostname: rabbitmq2
24+
depends_on:
25+
- rabbitmq1
26+
environment:
27+
- JOIN_CLUSTER_HOST=rabbitmq1
28+
- RABBITMQ_ERLANG_COOKIE=12345678
29+
volumes:
30+
- ./cluster-entrypoint.sh:/usr/local/bin/cluster-entrypoint.sh
31+
- ../enabled_plugins:/etc/rabbitmq/enabled_plugins
32+
- ../rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf
33+
- ../cert:/etc/rabbitmq/cert
34+
entrypoint: /usr/local/bin/cluster-entrypoint.sh
35+
networks:
36+
- rabbitmq
37+
38+
rabbitmq3:
39+
image: rabbitmq:3.13-management
40+
hostname: rabbitmq3
41+
depends_on:
42+
- rabbitmq1
43+
environment:
44+
- JOIN_CLUSTER_HOST=rabbitmq1
45+
- RABBITMQ_ERLANG_COOKIE=12345678
46+
volumes:
47+
- ./cluster-entrypoint.sh:/usr/local/bin/cluster-entrypoint.sh
48+
- ../enabled_plugins:/etc/rabbitmq/enabled_plugins
49+
- ../rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf
50+
- ../cert:/etc/rabbitmq/cert
51+
entrypoint: /usr/local/bin/cluster-entrypoint.sh
52+
networks:
53+
- rabbitmq
54+
55+
networks:
56+
rabbitmq:

services/cluster/test.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
mix local.rebar --force
3+
mix local.hex --force
4+
mix deps.unlock --all
5+
mix deps.get
6+
mix deps.compile
7+
mix compile
8+
9+
# Run
10+
mix test --exclude test --include v3_13_cluster

services/docker-compose.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: "3"
21
services:
32
rabbitmq_stream_3_13:
43
container_name: rabbitmq_stream
@@ -50,4 +49,4 @@ services:
5049
- 15672:15672
5150
environment:
5251
- RABBITMQ_DEFAULT_USER=guest
53-
- RABBITMQ_DEFAULT_PASS=guest
52+
- RABBITMQ_DEFAULT_PASS=guest
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Get hostname from enviromant variable
6+
HOSTNAME=`env hostname`
7+
echo "Starting RabbitMQ Server For host: " $HOSTNAME
8+
9+
if [ -z "$JOIN_CLUSTER_HOST" ]; then
10+
/usr/local/bin/docker-entrypoint.sh rabbitmq-server &
11+
sleep 5
12+
rabbitmqctl wait /var/lib/rabbitmq/mnesia/rabbit\@$HOSTNAME.pid
13+
else
14+
/usr/local/bin/docker-entrypoint.sh rabbitmq-server -detached
15+
sleep 5
16+
rabbitmqctl wait /var/lib/rabbitmq/mnesia/rabbit\@$HOSTNAME.pid
17+
rabbitmqctl stop_app
18+
rabbitmqctl join_cluster rabbit@$JOIN_CLUSTER_HOST
19+
rabbitmqctl start_app
20+
fi
21+
22+
# Keep foreground process active ...
23+
tail -f /dev/null
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Based on https://github.com/serkodev/rabbitmq-cluster-docker
2+
# This defines a rabbitmq cluster that stands behind a load balancer. It is mainly used to test
3+
# the auto-discovery feature of the main Client Module.
4+
services:
5+
rabbitmq1:
6+
image: rabbitmq:3.13-management
7+
hostname: rabbitmq1
8+
environment:
9+
- RABBITMQ_DEFAULT_USER=guest
10+
- RABBITMQ_DEFAULT_PASS=guest
11+
- RABBITMQ_DEFAULT_VHOST=/
12+
- RABBITMQ_ERLANG_COOKIE=12345678
13+
volumes:
14+
- ./cluster-entrypoint.sh:/usr/local/bin/cluster-entrypoint.sh
15+
- ../enabled_plugins:/etc/rabbitmq/enabled_plugins
16+
- ../rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf
17+
- ../cert:/etc/rabbitmq/cert
18+
entrypoint: /usr/local/bin/cluster-entrypoint.sh
19+
networks:
20+
- rabbitmq
21+
22+
rabbitmq2:
23+
image: rabbitmq:3.13-management
24+
hostname: rabbitmq2
25+
depends_on:
26+
- rabbitmq1
27+
environment:
28+
- JOIN_CLUSTER_HOST=rabbitmq1
29+
- RABBITMQ_ERLANG_COOKIE=12345678
30+
volumes:
31+
- ./cluster-entrypoint.sh:/usr/local/bin/cluster-entrypoint.sh
32+
- ../enabled_plugins:/etc/rabbitmq/enabled_plugins
33+
- ../rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf
34+
- ../cert:/etc/rabbitmq/cert
35+
entrypoint: /usr/local/bin/cluster-entrypoint.sh
36+
networks:
37+
- rabbitmq
38+
39+
rabbitmq3:
40+
image: rabbitmq:3.13-management
41+
hostname: rabbitmq3
42+
depends_on:
43+
- rabbitmq1
44+
environment:
45+
- JOIN_CLUSTER_HOST=rabbitmq1
46+
- RABBITMQ_ERLANG_COOKIE=12345678
47+
volumes:
48+
- ./cluster-entrypoint.sh:/usr/local/bin/cluster-entrypoint.sh
49+
- ../enabled_plugins:/etc/rabbitmq/enabled_plugins
50+
- ../rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf
51+
- ../cert:/etc/rabbitmq/cert
52+
entrypoint: /usr/local/bin/cluster-entrypoint.sh
53+
networks:
54+
- rabbitmq
55+
56+
haproxy:
57+
image: haproxy:2.7
58+
volumes:
59+
- ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
60+
depends_on:
61+
- rabbitmq1
62+
- rabbitmq2
63+
- rabbitmq3
64+
ports:
65+
- 5551:5551
66+
- 5552:5552
67+
- 5672:5672
68+
- 15672:15672
69+
networks:
70+
- rabbitmq
71+
72+
networks:
73+
rabbitmq:
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
global
2+
log 127.0.0.1 local1
3+
maxconn 4096
4+
5+
defaults
6+
log global
7+
mode tcp
8+
option tcplog
9+
retries 3
10+
option redispatch
11+
maxconn 2000
12+
timeout connect 5000
13+
timeout client 50000
14+
timeout server 50000
15+
16+
listen rabbitmq
17+
bind *:5672
18+
mode tcp
19+
balance roundrobin
20+
timeout client 3h
21+
timeout server 3h
22+
option clitcpka
23+
server rabbitmq1 rabbitmq1:5672 check inter 5s rise 2 fall 3
24+
server rabbitmq2 rabbitmq2:5672 check inter 5s rise 2 fall 3
25+
server rabbitmq3 rabbitmq3:5672 check inter 5s rise 2 fall 3
26+
27+
listen ssl-stream
28+
bind *:5551
29+
mode tcp
30+
balance roundrobin
31+
timeout client 3h
32+
timeout server 3h
33+
option clitcpka
34+
server rabbitmq1 rabbitmq1:5551 check inter 5s rise 2 fall 3
35+
server rabbitmq2 rabbitmq2:5551 check inter 5s rise 2 fall 3
36+
server rabbitmq3 rabbitmq3:5551 check inter 5s rise 2 fall 3
37+
38+
39+
listen stream
40+
bind *:5552
41+
mode tcp
42+
balance roundrobin
43+
timeout client 3h
44+
timeout server 3h
45+
option clitcpka
46+
server rabbitmq1 rabbitmq1:5552 check inter 5s rise 2 fall 3
47+
server rabbitmq2 rabbitmq2:5552 check inter 5s rise 2 fall 3
48+
server rabbitmq3 rabbitmq3:5552 check inter 5s rise 2 fall 3
49+
50+
listen management
51+
bind *:15672
52+
mode tcp
53+
balance roundrobin
54+
timeout client 3h
55+
timeout server 3h
56+
option clitcpka
57+
server rabbitmq1 rabbitmq1:15672 check inter 5s rise 2 fall 3
58+
server rabbitmq2 rabbitmq2:15672 check inter 5s rise 2 fall 3
59+
server rabbitmq3 rabbitmq3:15672 check inter 5s rise 2 fall 3

0 commit comments

Comments
 (0)