Skip to content

Instantly share code, notes, and snippets.

@mocheng
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mocheng/d5d7aa532c12c8ac8b24 to your computer and use it in GitHub Desktop.
Save mocheng/d5d7aa532c12c8ac8b24 to your computer and use it in GitHub Desktop.
storm mosca server
var mqtt = require('mqtt');
var port = 1883;
var host = 'localhost';
var options = {
username: 'my_username',
password: 'my_password',
clientId: 'my_client_id'
};
var client = mqtt.createClient(port, host, options);
client.on('connect', function() {
var sum = 1000;
setInterval(function(){
sum = 20;
for(var i=1; i<sum; i++){
client.publish(topic, 'hello', {qos : 1});
}
}, 1000);
});
/*global setInterval:true, setTimeout:true */
var mqtt = require('mqtt');
var port = 1883;
var host = 'localhost';
var topic = ['some_topic'];
var options = {
keepalive: 60,
clientId: 'my_client', // this client id should pass authenticate
username: 'my_username', // this username and password should make authorizeSubscribe fail
password: 'my_password'
clean: false
};
var clientSub = mqtt.createClient(port, host, options);
var count = 100;
clientSub.on('connect', function() {
count += 2;
for(var i=1; i<count; i++){
clientSub.subscribe(topic, {qos : 1}, function(err, result) {
console.log('subscribe sent: ' + i);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment