Skip to content

Instantly share code, notes, and snippets.

@gowrishankarin
Created November 27, 2016 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gowrishankarin/ff8692567fbf05a0c5ab3a34a305c1ca to your computer and use it in GitHub Desktop.
Save gowrishankarin/ff8692567fbf05a0c5ab3a34a305c1ca to your computer and use it in GitHub Desktop.
NodeJS AMQP Connector and Receiver
function startAMQPReceiver() {
amqp.connect('amqp://' + CustomConfig.CC.aims.domain).then(function(conn) {
process.once('SIGNT', function() {
conn.close();
});
return conn.createChannel().then(function(ch) {
var ok = ch.assertQueue('heartspots', {
durable: true
});
ok = ok.then(function(_qok) {
return ch.consume('heartspots', function(msg) {
// console.log(" [x] Received '%s'", msg.content.toString());
var message = JSON.parse(msg.content);
var properties = message.vals;
properties.mode = message.mode;
var street = getStreet(properties);
var location = getLocation(properties);
var address = street + ', ' + location;
console.log(" [x] Received '%s'", properties.name);
properties.address = address;
properties.photo_path = 'https://' + CustomConfig.CC.aims.domain + '/photos/' + properties.photo_path;
if(properties.email.length === 0) {
properties.email = properties.ref.toLowerCase() + '@heartfulness.org';
}
googleMapsClient.geocode({
address:location
})
.asPromise()
.then(updateTrainerInfo(properties))
.catch(function(err) {
});
}, {
noAck: true
});
});
return ok.then(function(_consumeOk) {
console.log(' [*] Waiting for messages. To exit press CTRL+C');
});
});
}).then(null, console.warn);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment