Last active
July 26, 2016 08:28
-
-
Save eastlondoner/e1cfb7ae64bda4ec5531dfe0024199c3 to your computer and use it in GitHub Desktop.
Simple node "module" for doing marathon "service discovery"
This file contains hidden or 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
| 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