Skip to content

Instantly share code, notes, and snippets.

@kristofsajdak
Forked from ssebro/generic-event-consumer.js
Last active November 18, 2015 10:07
Show Gist options
  • Save kristofsajdak/d57e5373a58f9a41d538 to your computer and use it in GitHub Desktop.
Save kristofsajdak/d57e5373a58f9a41d538 to your computer and use it in GitHub Desktop.
Generic template for event consumer
//keys are generated from the collection names.
var orderedAlarmsChangeConsumer = queue({exchange, "name":"ordered.alarms", exclusive:false}).consume(
'canAlarms.insert': function(data) {
if(data.canAlarms[0].archiveRequested){
return createAndSendCanAlarms(data)
},
'canAlarms.delete': function ... ,
'canAlarams.update': function ... ,
'trackingData.insert': function... ,
'trackingData.delete':function ... ,
'trackingData.update':function ... ,
'equipment.#': function ... ,
'foo.bar.baz': function ...
},
)
queue({exchange, "name":"consoleLogs", keys: ['log.warn', 'log.info']}).consume(
function(data, msg) {
console.log(data)
return Promise.resolve()
}
)
queue({exchange, "name":"errorFile", keys: ['log.error', 'log.critical']}).consume(
function(data) {
return sendEmail(data)
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment