2017-04-10 146 views
8

因此,我们使用Spring-Boot编写Java微服务,使用Consul进行服务发现和配置管理,并在Docker容器中运行。所有这些都在工作,但是当一个容器死亡或服务重新启动时,旧的service-id在Consul永远不会消失,并且永久服务在Consul UI中显示为“Failing”,尽管新容器已经注册并显示了所有绿色。Docker中的Consul和Spring Boot服务 - 未注销

我们没有使用心跳 - 但我无法找到关于心跳和健康检查对领事有什么区别的文档。

这里是我的bootstrp.yml

spring: 
    application: 
    name: my-service 
    cloud: 
    config: 
     enabled: false 
    consul: 
     host: ${discovery.host:localhost} 
     port: ${discovery.port:8500} 
     config: 
     watch: 
      wait-time: 30 
      delay: 10000 
     profile-separator: "-" 
     format: FILES 
     discovery: 
     prefer-ip-address: true 
     instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}} 

还有其他设置,使心跳加快,但文件说一下这把更多的压力领事群集上。

有没有人设法让Consul和Spring Boot/Docker服务实际上自动取消注册?它实际上不会造成任何实际问题,但它使Consul UI非常无用,实际上可以监视up/down服务。

+0

也许这一个帮助:http://stackoverflow.com/questions/32259323/consul-not-deregistering-zombie-services – gesellix

回答

1

领事不会自动注销服务。

有关同一问题的提示,请参见https://groups.google.com/forum/#!topic/consul-tool/slV5xfWRpEE。根据该线程,您需要更新配置或执行Agent API call。由于代理是真相的来源,因此您不应该尝试通过目录API进行更新。详情请参阅GitHub。他们还在Google小组中提到,如果节点正常关闭,您不一定需要注销服务,但这似乎不是您的使用案例。

请查看Consul not deregistering zombie services了解关于使用api或工具(如registrator)自动取消注册服务的提示。

1

你已经提到你正在使用码头容器来运行微服务。您是否在Docker容器的入口点脚本中陷入SIGTERM?如果发送SIGTERM,引导应用程序将会得到它,您将看到下面的日志显示微服务正在取消与Consul的注册。

2017-04-27 09:20:19.854 INFO 6852 --- [on(6)-127.0.0.1] inMXBeanRegistrar$SpringApplicationAdmin : Application shutdown requested. 
2017-04-27 09:20:19.857 INFO 6852 --- [on(6)-127.0.0.1] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot[email protected]afb5821: startup date [Thu Apr 27 09:20:00 EDT 2017]; parent: org.spring[email protected]130c12b7 
2017-04-27 09:20:19.859 INFO 6852 --- [on(6)-127.0.0.1] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 2147483647 
2017-04-27 09:20:19.863 INFO 6852 --- [on(6)-127.0.0.1] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 0 
2017-04-27 09:20:19.863 INFO 6852 --- [on(6)-127.0.0.1] o.s.c.c.s.ConsulServiceRegistry   : Deregistering service with consul: xxxxxxxxxxxxx 

This blog post discusses this.

+0

是啊,我是沿着这些线路的思考为好,但在我的日志中,我确实看到了“取消与领事注册....”信息消息。 – Gandalf

+0

@Gandalf你在Dockerfile中使用这个表单吗? {CMD exec java -jar microservice.jar} 在我的consul/docker/spring-boot设置中,服务已正确注销。不同的是,我没有领事代理人。我的微服务直接与处于引导模式的领事服务器通话。 – cherit