Last active
August 29, 2015 14:04
-
-
Save mocheng/d5d7aa532c12c8ac8b24 to your computer and use it in GitHub Desktop.
storm mosca server
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
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); | |
}); | |
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
/*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