Skip to content

Instantly share code, notes, and snippets.

@michaeldauria
Created November 19, 2014 21:36
Show Gist options
  • Save michaeldauria/9d184269182e534678b0 to your computer and use it in GitHub Desktop.
Save michaeldauria/9d184269182e534678b0 to your computer and use it in GitHub Desktop.
Bitly NSQ Data Streams via nsqjs
var nslookupdOptions = {
hostname: 'api-ssl.bitly.com',
path: '/v3/nsq/lookup?topic=topic&access_token='+access_token,
};
var lookupds = [];
var request = https.request(nslookupdOptions, function(res) {
res.on('data', function(response) {
JSON.parse(response).data.producers.forEach(function(nslookupd) {
nslookupds.push(nslookupd.hostname+':'+nslookupd.tcp_port);
});
// lookupds ready
var reader = new nsq.Reader('topic', 'channel', {
lookupdHTTPAddresses: nslookupds,
maxInFlight: 30,
tls: true,
authSecret: access_token
});
console.log('Connecting to nsq...');
reader.connect();
reader.on('message', function (msg) {
console.log('Received message [%s]: %s', msg.id, msg.body.toString());
msg.finish();
});
});
});
request.end();
request.on('error', function(e) {
console.error(e);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment