Skip to content

Instantly share code, notes, and snippets.

@Kami
Last active December 15, 2015 08:29
Show Gist options
  • Select an option

  • Save Kami/5230779 to your computer and use it in GitHub Desktop.

Select an option

Save Kami/5230779 to your computer and use it in GitHub Desktop.
Rackspace Service Registry EventsFeedPoller Node.js client class example
/**
* En example which uses EventsFeedPoller abstraction to poll the events feed
* and print all of the events to the standard output.
*/
var Client = require('../lib').Client;
var EventsFeedPoller = require('../lib').EventsFeedPoller;
var EVENT_KEYS = [
'service.join',
'service.timeout',
'service.remove',
'configuration_value.update',
'configuration_value.remove'
];
var client = new Client('myusername', 'myapikey', 'us');
var eventsPoller = new EventsFeedPoller(client.events, {'pollInterval': 5});
function printEmittedEvent(type) {
return function(payload) {
console.log('Event type: ' + type);
console.log('Event payload: ' + JSON.stringify(payload));
};
}
// Add listener for all the available events
EVENT_KEYS.forEach(function(key) {
eventsPoller.on(key, printEmittedEvent(key));
});
eventsPoller.on('error', function(err) {
console.log('Error occured: ' + err.toString());
});
// Start polling
eventsPoller.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment