Reputation: 1093
I am learning Micro-services architecture by writing a small web app. The app has the following components, each of which will be hosted by a docker container.
In my API Gateway which is written in NodeJS, there is some place I will call:
request('http://service_b_ip_addr:port/get_service_b', callback);
However, both service_b_ip_addr
and port
are not known until Marathon has the Service B's docker container created.
With some Service Discovery mechanism, such as mesos-dns or marathon-lb, I guess that I could just change service_b_ip_addr
to something like service_b.marathon.com
.
But I've no idea how should I put the port
in my program.
Thanks in advance for your help.
PS:
port
is a NATted random number.Upvotes: 0
Views: 202
Reputation: 6371
Take a look at this answer.
If you use marathon-lb then there is no need to pass a port because it's a proxy and it will know where service is just by name.
If you use mesos-dns you should make a SRV request to get ip and port. In node you can do it with dns.resolveSrv(hostname, callback)
but your DNS must be exposed on defaul (53) port and supports SRV request (mesos-dns supports it).
Upvotes: 1