无效节点自动清除
服务正常关闭情况下,会向consul发起Deregistering ,例如:
// spring的生命周期destroy节点,通过AbstractAutoServiceRegistration destroy的stop函数调用ConsulServiceRegistry#deregister
@PreDestroy
public void destroy() {
stop();
}
//ConsulServiceRegistry
@Override
public void deregister(ConsulRegistration reg) {
if (ttlScheduler != null) {
ttlScheduler.remove(reg.getInstanceId());
}
if (log.isInfoEnabled()) {
log.info("Deregistering service with consul: " + reg.getInstanceId());
}
client.agentServiceDeregister(reg.getInstanceId(), properties.getAclToken());
}
但对于宕机直接结束进程的情况,节点会一直驻留,直到检测超时,默认是72小时,原文如下:
Consul will automatically remove dead nodes out of the catalog. This process is called reaping. This is currently done on a configurable interval of 72 hours (changing the reap interval is not recommended due to its consequences during outage situations). Reaping is similar to leaving, causing all associated services to be deregistered.
对于上述情况可以手动清除
consule ip:port+ "/v1/agent/service/deregister/" + serviceId
启动指令 -dev
使用 consul agent -dev 启动时会挂载在前台启动,窗口关闭后日志记录会丢失,生产不建议使用。
Consul ships with a -dev flag that configures the agent to run in server mode and several additional settings that enable you to quickly get started with Consul. The -dev flag is provided for learning purposes only. We strongly advise against using it for production environments.