-
-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[question] How to create aedes
broker cluster in Docker?
#152
Comments
the configuration you used is correct but you also need to setup mongodb/redis persistence. mqemitter is used to share messages between aedes instances and mongo to persist qos > 0, retained messages and subscriptions so you also need that. |
@robertsLando, thanks for reply! 🙏 I don’t need persistence nor QOS > 0. Do I still need to setup As for the main question: as I understand it, the config in the OP is not yet a cluster config, is it? If it is not a cluster yet, how to make a cluster config?
|
You should setup both mqemitter and persistence in order to run clusters Then follow this guide to provide the load balancing: (there are a lot) You will have N instances of aedes broker running, mqemitter allows them to share messages (so if you have a client A connected to instance 1 and a client B connected to instance 2 client A will be able receive messages published to instance 2 and vice versa). Persistence is needed to share the same state between all aedes instances |
Thanks again. The linked site help me a lot, however, the ports ( Is there a way to change the ports per container instance? Or how could I work around the issue?
version: '3.7'
services:
aedes:
# Note: I needed to remove `container_name`, as each container instance needs to have different name.
# container_name: aedes
image: moscajs/aedes:latest
restart: always
stop_signal: SIGINT
deploy:
# Scale = 3
replicas: 3
network_mode: host
command: -c /data/dockerConfig.js
volumes:
- /some/path/mqtt:/data
mongo:
container_name: mongo
restart: always
network_mode: host
logging:
driver: none
image: mvertes/alpine-mongo
volumes:
- mongo_data:/data/db
ports:
- 27017:27017
volumes:
mongo_data:
name: mongo_data
module.exports = {
protos: ['tcp', 'ws'],
host: 'localhost',
port: 1883,
wsPort: 3000,
wssPort: 4000,
tlsPort: 8883,
key: null,
cert: null,
rejectUnauthorized: true,
credentials: null,
brokerId: 'aedes',
concurrency: 100,
queueLimit: 42,
maxClientsIdLength: 23,
heartbeatInterval: 60000,
connectTimeout: 30000,
stats: false,
statsInterval: 5000,
persistence: {
name: 'mongodb',
options: {
url: 'mongodb://localhost:27017/aedes'
}
},
mq: {
name: 'mongodb',
options: {
url: 'mongodb://localhost:27017/aedes'
}
},
verbose: false,
veryVerbose: false,
noPretty: false
} Update I understand I can append |
The approach I suggest is to create multiple aedes containers directly in compose file naming them like
and
You don't have to to expose aedes or mongodb ports in docker-compose (remove |
@robertsLando, sorry for being away for a while. I am in the middle of dockerising my app, therefore now I came back to this issue. I can successfully run the following For now, I have not done config in What could be wrong with this config? # docker-compose
aedes:
image: moscajs/aedes:latest
restart: unless-stopped
stop_signal: SIGINT
deploy:
replicas: 3
networks:
- someNetwork
command: -c /data/aedes.js
volumes:
- /some/path/aedes.js:/data/aedes.js:ro // /some/path/aedes.js
module.exports = {
protos: ['tcp', 'ws'],
host: 'localhost',
port: 8193,
wsPort: 4000,
wssPort: 4001,
tlsPort: 8883,
key: null,
cert: null,
rejectUnauthorized: false,
credentials: null,
brokerId: 'aedes',
concurrency: 0,
queueLimit: 200,
maxClientsIdLength: 23,
heartbeatInterval: 60000,
connectTimeout: 30000,
stats: false,
statsInterval: 5000,
persistence: {
name: 'mongodb',
options: {
url: 'mongodb://mongo:27017/aedes'
}
},
mq: {
name: 'mongodb',
options: {
url: 'mongodb://mongo:27017/aedes'
}
},
verbose: false,
veryVerbose: false,
noPretty: false
} // Client (in another container); both TCP and WS connection fails with `ECONNREFUSED`
const {connect} = require('mqtt')
const tcpPort = 8193
const tcpClient = connect(`mqtt://aedes:${tcpPort}`)
tcpClient.on('error', e => {
console.log(`MQTT error:`, e)
})
const wsPort = 4000
const wsClient = connect(`mqtt://aedes:${wsPort}`)
wsClient.on('error', e => {
console.log(e)
})
// Sample output:
// - same output for both TCP and WS;
// - IP addresses cycle through the replicas.
Error: connect ECONNREFUSED 172.29.0.6:8193
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1195:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '172.29.0.6',
port: 8193
} Update: I also tried to run the client code within Update 2: When I comment out Update 3: I believe that the ports are not open outside of the Update 4: I ‘solved’ this issue by modifying the official example. I believe the ports issue is on the Docker image/container level, but I have no idea why it does not work. |
First asked on SO.
I need to create a MQTT broker cluster. I want to use
aedes
(as I already use it, albeit without cluster) and Docker. Note that I have never created a cluster before (with nor without Docker).Here I found official example how to create a cluster using
aedes
, but I was thinking about usingaedes-cli
Docker image.Now, I have no idea which is better: should I create separate containers per broker (similarly to this question) or use
mqemitter-redis
/mqemitter-mongodb
(as theaedes-cli
docs suggest).As for creating separate containers, I have no idea how to connect them.
As for using
mqemitter-redis
/mqemitter-mongodb
, I have no idea how to setup them in theaedes-cli
config file.I have no need for data persistance accross broker cluster restarts. All I need is to distribute the messages accross multiple brokers in order to improve the runtime performance.
Below is a working, single-broker configuration.
aedes.yml
:/some/path/mqtt/dockerConfig.js
The text was updated successfully, but these errors were encountered: