I have setup a consul cluster having a single server and 2 clients(2 different VMs) running Service A registered in the service mesh. On VM1 there is a service Test also registered in the the service mesh that needs to call Service A. When service Test calls the service A, will the service running in VM1 serve the request or will the service A running on VM2 serve it?
Does Consul service discover use the n/w latency consideration such that service requested if available locally gets priority or is there any way to implement in such a way?
You can use Consul’s prepared queries to find upstream services that are nearest by latency. However, this requires that you access the service via a static upstream. (Prepared queries are not compatible with transparent proxy redirection.)
Here’s an example config prepared query and upstream config.
name = "test-service"
port = 1234
upstreams = [
destination_name = "service-a"
destination_type = "prepared_query"
local_bind_port = 9001
Be aware that if you’re using a prepared query upstream, they are not compatible with Consul’s layer 7 traffic management. Any L7 policies you have defined will not be processed and the connection will be forwarded to the upstream as a standard TCP service.