Service Discovery with python

Hi,

please give me simple example how to discover each service and communicate between each service using DNS on python flask project.

i have read many documentation, but not clear how to do in python.

i am appreciate if any one can help

regards
Janaka

Hi,

By default Consul runs its own DNS on port 8600. Registered services can be discovered through this DNS resolver with specific domain.

Read also:
https://www.consul.io/docs/discovery/dns

Let’s say you have a service registered in Consul with the name myservice1. Then, making a myservice1.service.consul DNS query to Consul DNS running by default on port 8600 will give you the IP address of the node where myservice1 is running.

Even better, Consul supports SRV DNS record. Instead of the usual A record, you can write your code to request SRV record instead. SRV record contains not only the IP address but also the port of myservice1, perfect for the case if myservice1 uses dynamically allocated port (for example if you run it on top of Kubernetes or Nomad).

You can also discover service by contacting Consul directly with consul template, but I think that might be inconvenient for your use case.

Hope this helps.