Skip to content

Instantly share code, notes, and snippets.

@dminkovsky
Created October 31, 2014 19:53
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 dminkovsky/0384c304ae9f2b384ed3 to your computer and use it in GitHub Desktop.
Save dminkovsky/0384c304ae9f2b384ed3 to your computer and use it in GitHub Desktop.
var nsq = require('nsqjs');
function populate(done) {
var w = new nsq.Writer('10.0.0.101', 4150);
w.connect();
w.on('ready', function() {
function publish(n, max) {
if (n < max) {
console.log('populating message %s', n);
w.publish('test_topic', 'hello ' + n);
return publish(n + 1, max);
}
done();
}
publish(0, 10);
});
}
function read() {
var r = new nsq.Reader('test_topic', 'churn_n_burn', {
lookupdHTTPAddresses: '10.0.0.101:4161',
maxInFlight: 2
});
r.on('message', function(msg) {
console.log(msg.body.toString());
setTimeout(function() { msg.finish(); }, 5000);
});
r.connect();
}
//populate(read);
read();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment