Skip to content

Instantly share code, notes, and snippets.

@ollieparsley
Created January 24, 2012 14:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ollieparsley/1670563 to your computer and use it in GitHub Desktop.
Save ollieparsley/1670563 to your computer and use it in GitHub Desktop.
DataSift Node.JS Multistreaming
//var DataSift = require('/path/to/datasift.js'); //When downloading datasift.js
var DataSift = require('datasift'); //When using npm installation
//Create a new instance of the DataSift consumer
var consumer = new DataSift('username', 'api_key');
//Connect
consumer.connect();
//Emitted when stream is connected
consumer.on("connect", function(){
//Subscribe to a few streams
consumer.subscribe('e4941c3a0b4a905314ce806dea26e0d7');
consumer.subscribe('2cff2642077232db000e9e7fed0d6071');
consumer.subscribe('bfaf7ae5e6bfb3e76d0454a665280f48');
//After 10 seconds unsubscribe from the first and second stream
setInterval(function(){
consumer.unsubscribe('e4941c3a0b4a905314ce806dea26e0d7');
consumer.unsubscribe('2cff2642077232db000e9e7fed0d6071');
}, 10 * 1000);
//After 30 seconds sunbscribe to another hash
setInterval(function(){
consumer.subscribe('c63bb577b68e33777351cc0d4d82f075');
}, 30 * 1000);
});
//Emitted when an interaction is received
consumer.on("interaction", function(obj){
console.log("Hash: ", obj.hash); //The hash that the interaction was related to
console.log("Data: ", obj.data); //The actual interaction data
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment