-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
34 lines (26 loc) · 1.22 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
const Aedes = require('aedes'),
ws = require('websocket-stream'),
redisMq = require('mqemitter-redis'),
config = require('./config'),
logger = require('./src/utils/logger'),
cassandra = require('./bootstrap/cassandra'),
handler = require('./src/mqtt/handler');
const port = config.get('/mqttPort'), wsPort = config.get('/websocketPort');
const mq = redisMq(config.get('/redisPubSub'));
mq.state.on('subConnect', () => logger.info('Flash Subscriber connected'));
mq.state.on('pubConnect', () => logger.info('Flash Publisher connected'));
const aedes = Aedes({mq});
const server = require('net').createServer(aedes.handle);
const wsServer = require('http').createServer();
ws.createServer({server: wsServer}, aedes.handle);
cassandra.connect(async err => {
if (err)
return logger.error(err);
logger.info('Batman (Cassandra) connected');
await require('./bootstrap/mongo').connectMongo()
await require('./bootstrap/redis')
wsServer.listen(wsPort, () => {logger.info('Thor websocket server listening on port', wsPort)});
server.listen(port, () => logger.info('Thor server listening on port', port));
handler(aedes);
});