Created
April 22, 2017 21:08
-
-
Save benedmunds/8fae2bae7e49a5ac0abb2e65494d3e9a to your computer and use it in GitHub Desktop.
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
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