Created
March 9, 2018 09:03
-
-
Save stephendeyoung/3180ce2ec527332e0ece6eee573e6ecb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mqtt = require('mqtt'); | |
const _ = require('lodash'); | |
const memwatch = require('memwatch-next'); | |
const util = require('util'); | |
const setTimeoutPromise = util.promisify(setTimeout); | |
memwatch.on('leak', (info) => { | |
console.error('Memory leak detected:\n', info); | |
}); | |
const NUMBER_OF_CLIENTS = parseInt(process.env.NUMBER_OF_CLIENTS, 10) || 5; | |
console.log('NUMBER_OF_CLIENTS: ', NUMBER_OF_CLIENTS) | |
_.times(NUMBER_OF_CLIENTS, async (n) => { | |
await setTimeoutPromise(n * 500); | |
console.log('connecting client') | |
const client = mqtt.connect('mqtt://broker.hivemq.com'); | |
client.subscribe(`/blah`, err => { | |
if (err) { | |
console.error(err, 'Subscription error') | |
} | |
}) | |
client.on('error', err => { | |
console.error(err, 'Error with mqtt client'); | |
}) | |
client.once('connect', () => { | |
console.log(`client connected`) | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment