在Docker领事和Spring Boot服务 – 不注销

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

我们没有使用心跳,但是我找不到有关领事与心跳检查之间区别的文档。

这是我的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群集的更多信息。

有没有人设法得到Consul和Spring Boot / Docker服务实际上自动注销? 它实际上不会造成任何实际的问题,但它使Consul UI很无用,实际上监视up / down服务。

领事不会自动注销服务。

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

请看看领事没有注销僵尸服务的暗示关于使用api或注册工具等工具自动化服务注销 。

你已经提到你正在使用docker容器来运行微服务。 你在Docker容器中的入口脚本中陷入SIGTERM? 如果发送SIGTERM,启动应用程序将会得到它,你会看到下面的日志显示微服务正在注销领事。

 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.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@afb5821: startup date [Thu Apr 27 09:20:00 EDT 2017]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@130c12b7 2017-04-27 09:20:19.859 INFO 6852 --- [on(6)-127.0.0.1] oscsupport.DefaultLifecycleProcessor : Stopping beans in phase 2147483647 2017-04-27 09:20:19.863 INFO 6852 --- [on(6)-127.0.0.1] oscsupport.DefaultLifecycleProcessor : Stopping beans in phase 0 2017-04-27 09:20:19.863 INFO 6852 --- [on(6)-127.0.0.1] osccsConsulServiceRegistry : Deregistering service with consul: xxxxxxxxxxxxx 

这篇博文讨论了这一点。