Skip to content

Instantly share code, notes, and snippets.

@eastlondoner
Last active July 26, 2016 08:28
Show Gist options
  • Save eastlondoner/e1cfb7ae64bda4ec5531dfe0024199c3 to your computer and use it in GitHub Desktop.
Save eastlondoner/e1cfb7ae64bda4ec5531dfe0024199c3 to your computer and use it in GitHub Desktop.
Simple node "module" for doing marathon "service discovery"
Promise = require('bluebird');
resolveSrv = Promise.promisify(require('dns').resolveSrv);
function fetchMarathonServiceBaseUrl(serviceName){
var dns_url = ['_' + serviceName, "_tcp.marathon.mesos"].join('.');
return resolveSrv(dns_url).then(function(addresses){
// TODO: take an address at random ?
// should we use some logic to choose addresses?
var internalUrl = "http://" + addresses[0].name + ":" + addresses[0].port;
return internalUrl
})
}
module.exports = {
fetchMarathonServiceBaseUrl: fetchMarathonServiceBaseUrl
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment