Created
November 19, 2014 21:36
-
-
Save michaeldauria/9d184269182e534678b0 to your computer and use it in GitHub Desktop.
Bitly NSQ Data Streams via nsqjs
This file contains 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 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