Skip to content

Commit

Permalink
test: configure emqx cluster and load balancer in docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
BEagle1984 committed Nov 27, 2023
1 parent 9482fb3 commit 2eef9e7
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 11 deletions.
59 changes: 48 additions & 11 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:

### Database ###
mssql:
container_name: s8k-mssql
container_name: silverback-mssql
image: mcr.microsoft.com/mssql/server:2019-latest
environment:
ACCEPT_EULA: "Y"
Expand All @@ -14,15 +14,15 @@ services:

### Apache Kafka ###
zookeeper:
container_name: s8k-zookeeper
container_name: silverback-zookeeper
image: confluentinc/cp-zookeeper:latest
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ports:
- "2181:2181"
kafka:
container_name: s8k-kafka
container_name: silverback-kafka
depends_on:
- zookeeper
image: confluentinc/cp-kafka:latest
Expand All @@ -40,7 +40,7 @@ services:
ports:
- "9092:9092"
schema-registry:
container_name: s8k-schema-registry
container_name: silverback-schema-registry
depends_on:
- zookeeper
- kafka
Expand All @@ -56,21 +56,58 @@ services:
### RabbitMQ ###
# management console http://localhost:15672/#/ (login guest/guest)
rabbit:
container_name: s8k-rabbit
container_name: silverback-rabbit
image: rabbitmq:3-management
ports:
- "15672:15672"
- "5672:5672"

### MQTT (emqx)
mqtt:
container_name: s8k-mqtt-emqx
image: emqx/emqx:4.2.14 # Fixed version because of crash at startup, probably related to https://github.com/emqx/emqx/issues/3996
emqx1:
image: emqx:5.1.0
container_name: silverback-emqx1
environment:
- "[email protected]"
- "EMQX_CLUSTER__DISCOVERY_STRATEGY=static"
- "EMQX_CLUSTER__STATIC__SEEDS=[[email protected],[email protected]]"
healthcheck:
test: ["CMD", "/opt/emqx/bin/emqx", "ctl", "status"]
interval: 5s
timeout: 25s
retries: 5
networks:
default:
aliases:
- node1.emqx.io

emqx2:
image: emqx:5.1.0
container_name: silverback-emqx2
environment:
- "[email protected]"
- "EMQX_CLUSTER__DISCOVERY_STRATEGY=static"
- "EMQX_CLUSTER__STATIC__SEEDS=[[email protected],[email protected]]"
healthcheck:
test: ["CMD", "/opt/emqx/bin/emqx", "ctl", "status"]
interval: 5s
timeout: 25s
retries: 5
networks:
default:
aliases:
- node2.emqx.io

### HA Proxy (used to load balance the emqx cluster nodes)
haproxy:
image: haproxy:latest
container_name: silverback-haproxy
ports:
- "1883:1883"
- "9001:9001"
environment:
EMQX_ZONE__EXTERNAL__RETRY_INTERVAL: "10s"
volumes:
- ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
depends_on:
- emqx1
- emqx2

networks:
default:
Expand Down
18 changes: 18 additions & 0 deletions haproxy.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
global
log stdout format raw local0

defaults
log global
mode tcp
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms

frontend mqtt-in
bind *:1883
default_backend emqx_cluster

backend emqx_cluster
balance roundrobin
server emqx1 emqx1:1883 check
server emqx2 emqx2:1883 check

0 comments on commit 2eef9e7

Please sign in to comment.