2017-04-10 151 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