consul-client icon indicating copy to clipboard operation
consul-client copied to clipboard

Why do two callbacks happen?

Open yancheng199287 opened this issue 5 years ago • 3 comments

     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

yancheng199287 avatar Aug 02 '20 13:08 yancheng199287

update

yancheng199287 avatar Aug 02 '20 13:08 yancheng199287

I wrote it in kotlin,thanks

yancheng199287 avatar Aug 02 '20 13:08 yancheng199287

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?

lwsbox avatar Jan 07 '21 11:01 lwsbox