-
-
Save ssebro/b7bf9d018aa3f0bd0754 to your computer and use it in GitHub Desktop.
Generic template for event consumer
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
//This is a representation of what would be generated by the generic-event-consumer | |
var rabbit = require('rabbitConnect'); | |
//Data consumer can be anything that depends on a queue - it's just a placeholder. | |
var dataConsumer = require('dataConsumer'); | |
//The dataConsumer will dispatch messages to the change handler functions appropriately. | |
var exchange = rabbit.topic('change.events'); | |
exchange | |
.queue({ name: 'es.sync', keys: ['canAlarms.*','trackingData.*', 'equipment.*'] }) | |
.consume(function fwd(data, ack, nack, msg) { | |
var resource, action; | |
// extract routingKey from msg, parse and populate resource and action | |
dataConsumer.push(data,resource,action).then(function(){ | |
ack(); | |
}).catch(function() { | |
nack(); | |
}) | |
} | |
); |
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 queueConsumer = require('generic-event-consumer'); | |
//keys are generated from the collection names. | |
var orderedAlarmsChangeConsumer = queueConsumer({exchange:"change.events", "name":"es.sync", exclusive:false}).handle( | |
'canAlarms':{ | |
'insert':function(data){ | |
if(JSON.parse(data).canAlarms[0].archiveRequested){ | |
return createAndSendCanAlarms(data).catch(function(err){ | |
console.error(err); | |
throw err; | |
}); | |
} | |
}, | |
'delete':function ... | |
'update':function ... | |
}, | |
'trackingData': { | |
'insert':function(data){ | |
}, | |
'delete':function ... | |
'update':function ... | |
}, | |
'equipment': { | |
'insert':function(data){ | |
}, | |
'delete':function ... | |
'update':function ... | |
}, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment