配置说明 注意-转驼峰
english
http://cloud.spring.io/spring-cloud-static/Dalston.SR2/#spring-cloud-feign
china
https://springcloud.cc/spring-cloud-dalston.html
eureka server配置server:
server:
port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: false
server:
enable-self-preservation: false
#每指定时间 刷新服务列表
eviction-interval-timer-in-ms: 5000
eureka client
server:
port: 8080
spring:
application:
name: my-health-provider
endpoints:
sensitive: false
eureka:
instance:
#每指定时间向发送 eureka服务器发送续约信息
leaseRenewalIntervalInSeconds: 5
#每指定时间没有向服务器发送续约信息,即向eureka服务器发送down机信息
leaseExpirationDurationInSeconds: 10
metadata-map:
company-name: crazyit
client:
#指示将实例信息复制到eureka服务器的开始时间(以秒为单位)
#配合健康检测器,健康指示器 将实例健康状态通知eureka服务器
instanceInfoReplicationIntervalSeconds: 10
serviceUrl:
defaultZone: http://localhost:8761/eureka/
健康指示器
@Component public class MyHealthIndicator implements HealthIndicator { public Health health() { if(PoliceController.canVisitDb) { return new Health.Builder(Status.UP).build(); } else { return new Health.Builder(Status.DOWN).build(); } } }
健康监测器
@Component public class MyHealthCheckHandler implements HealthCheckHandler { @Autowired private MyHealthIndicator halthIndicator; public InstanceStatus getStatus(InstanceStatus currentStatus) { Status status = halthIndicator.health().getStatus(); if(status.equals(Status.UP)) { return InstanceStatus.UP; } else { return InstanceStatus.DOWN; } } }