Skip to content

Instantly share code, notes, and snippets.

@mocheng

mocheng/storm with publish

Last active Aug 29, 2015
Embed
What would you like to do?
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