Last active
December 15, 2015 08:29
-
-
Save Kami/5230779 to your computer and use it in GitHub Desktop.
Rackspace Service Registry EventsFeedPoller Node.js client class example
This file contains hidden or 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
| /** | |
| * 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