I am building a cloud stack using consul for service discovery, but I've hit a wall, so I ask the people of internet about that.
What I do want to do is registering a service in consul from multiple hosts, but return only one of them for all of the queries while the service is up. To be exact:
- node A, node B, node C are all capable to provide service X
- all the nodes are up and running
- and they all register the service into consul.
In this moment when I query consul for these data I'll get all of the three nodes as answer. I do want to get only one of them, as long as the service is provided by that node, but if not, I'd like to get an another node for all the questions.
To be more exact with an example: I build up an xtradb cluster, and one of the nodes has to replicate from the old datacenter of us. There could be only one, which is replicating in a given moment, but if that node goes down, some of the other nodes have to continue replicating.
I can solve this with an external monitoring host, but that can be a SPOF, so the best would be to put a replication supervising script on all the nodes, which is querying consul about 'am I the responsible host for replication?' and if the answer is yes, then set up replica locally. Theoretically if that node goes down, consul could vote for the new 'replica master' --- and the agent on that node will set up replication.
So, is consul capable of this? If not, is there any other way for achieving this? (We are running on GCP so I can't quorum with disks, or with floating IPs. All the hosts are independent, I need some layer which can have consensus about hosts.) In worst case scenario I'll write this by myself, but it would be better to have a production-ready solution.