码迷,mamicode.com
首页 > 编程语言 > 详细

spring cloud 健康监测配置

时间:2018-03-10 11:55:19      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:lis   elf   fetch   status   crazy   map   ict   开始时间   meta   

配置说明 注意-转驼峰

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;
        }
    }

}

 

spring cloud 健康监测配置

标签:lis   elf   fetch   status   crazy   map   ict   开始时间   meta   

原文地址:https://www.cnblogs.com/zfzf1/p/8537424.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!