consul-client
consul-client copied to clipboard
Why do two callbacks happen?
val svHealth = ServiceHealthCache.newCache(healthClient, serviceName, false, 10, QueryOptions.BLANK)
svHealth.addListener { newValues: Map<ServiceHealthKey, ServiceHealth> ->
run {
println("----------------")
logger.info(JSON.toJSONString(IMServerInstance.parserConsulClientServiceInstance(newValues)))
}
}
svHealth.start()
my log show twice callback for same service id when I kill a server
as follows
----------------
21:41:14.435 [OkHttp http://localhost:8500/...] INFO com.oneinlet.ConsulClientService - {"dataCenter":"dc1","id":"c87870158a643ec79044af3997524ee5","metaData":{"serverInstancePublicIp":"localhost"},"name":"Interesting-IM-Service","nodeAddress":"127.0.0.1","nodeName":"DESKTOP-EOTSJE5","serverInstancePort":80,"serviceTagList":[],"status":"critical"}
21:41:15.431 [OkHttp http://localhost:8500/...] DEBUG com.orbitz.consul.cache.ConsulCache - Consul cache updated for health.service "Interesting-IM-Service" (index=339), request duration: 996 ms
----------------
21:41:15.432 [OkHttp http://localhost:8500/...] INFO com.oneinlet.ConsulClientService - {"dataCenter":"dc1","id":"c87870158a643ec79044af3997524ee5","metaData":{"serverInstancePublicIp":"localhost"},"name":"Interesting-IM-Service","nodeAddress":"127.0.0.1","nodeName":"DESKTOP-EOTSJE5","serverInstancePort":80,"serviceTagList":[],"status":"critical"}
2
update
I wrote it in kotlin,thanks
maybe cased by your health indicator changed
for example:
{"status":"UP","diskSpace":{"status":"UP","total":117081018368,"free":26488745984,"threshold":10485760},
if the free indicator changed would run the callback.
Maybe should avoid this situation?