A cluster of consul agents
Hi,
we develop a library with a sort of high level utils for Consul like leader election, consul watcher, datacenter reading etc. It is not open-sourced yet, but I hope it will be soon. It turned out that we need a cluster of consul agents in integration tests for example 2 agents connected in one datacenter or even 2 datacenters. This may seem like a crazy idea, but it works just fine, because Consul starts and connect with other agent really fast.
I came up with the solution called ConsulCluster which I use like this
@Shared
@ClassRule
ConsulCluster consulCluster = new ConsulCluster.Builder()
.withNode("dc1", "node1-dc1")
.withNode("dc2", "node1-dc2")
.withNode("dc2", "node2-dc2")
.build()
Then I can connect to any agent by retrieving its HTTP port
consulCluster.getHttpPort("dc1", "node1-dc1")
I can also register/deregister healthy/unhealthy service instances (but this probably should be done in https://github.com/pszymczyk/embedded-consul/issues/65 )
consulCluster.registerHealthyServiceInstance("my-service", "dc1", "node1-dc1")
consulCluster.registerUnhealthyServiceInstance("my-service", "dc2", "node1-dc2")
consulCluster.deregisterService(serviceId, "dc1", "node1-dc1")
Of course I coded it for our case. I would need to think of more universal API.
Do you find this feature useful? :)
Hi Jakub
Feature sounds interesting and if it's useful for you it could be useful for someone else :) So if you'd like to contribute you have my green light.