在默認的springCloud中eureka注冊中心在服務下線時表現的非常不靈敏,用慣了dubbo的zk注冊中心表示很不習慣,eureka設計的本意是在服務不會頻繁上下線和網絡穩定的內網,這種設計在生產環境是沒什么問題的,但在開發和測試環境卻會導致經常調用到已經下線的服務提供者,可以加上如下配置來解決(建議配合profile)
1、eureka server中的application.properties
#此配置建議只試用開發和測試環境
#驅逐下線的服務,間隔,5秒,默認是60 #org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean.evictionIntervalTimerInMs eureka.server.evictionIntervalTimerInMs=5000
參見類:com.netflix.eureka.registry.AbstractInstanceRegistry
2、服務提供者的application.properties
#此配置建議只試用開發和測試環境
#心跳間隔時間,默認是30秒 #org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean.leaseRenewalIntervalInSeconds eureka.instance.leaseRenewalIntervalInSeconds=2 #最后一次心跳時間后leaseExpirationDurationInSeconds秒就認為是下線了,默認是90秒 #org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean.leaseExpirationDurationInSeconds eureka.instance.leaseExpirationDurationInSeconds=6
詳細配置項見:org.springframework.cloud.netflix.eureka.EurekaClientConfigBean