Skip to content

Instantly share code, notes, and snippets.

@benedmunds
Created April 22, 2017 21:08
Show Gist options
  • Save benedmunds/8fae2bae7e49a5ac0abb2e65494d3e9a to your computer and use it in GitHub Desktop.
Save benedmunds/8fae2bae7e49a5ac0abb2e65494d3e9a to your computer and use it in GitHub Desktop.
function processCalendarData(cb) {
setTimeout(function(){
cb();
}, 1000);
};
var amqp = require('amqplib/callback_api');
amqp.connect('amqp://localhost', function(err, conn) {
conn.createChannel(function(err, ch){
var queueName = 'notification';
ch.assertQueue(queueName, {durable:true});
console.log('[*] Waiting for notifications');
ch.consume(queueName, function(msg) {
ch.ack(msg);
console.log(" [x] Received %s", msg.content.toString());
var data = JSON.parse(msg.content.toString());
//process calendar data then call queue complete notification
processCalendarData(function(){
console.log('processedCalendarData - writing calendarComplete to ' + data.callbackQueue + ' queue');
ch.sendToQueue(data.callbackQueue, new Buffer('calendarComplete'));
})
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment