Created
November 27, 2016 10:00
-
-
Save gowrishankarin/ff8692567fbf05a0c5ab3a34a305c1ca to your computer and use it in GitHub Desktop.
NodeJS AMQP Connector and Receiver
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 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