微服务架构-Hystrix熔断器



Hystrix实现

/**
 * Hystrix实现-feign
 * 1.feign已经引入了hystrix依赖,所以不用添加,yml文件开启即可
 *
 * 2.@FeignClient(value = "Eureka-Client",configuration = FeignConfig.class,fallback = HiError.class)
 * fallback快速失败的处理类,处理类实现了这个服务接口
 *
 * 3.处理类注入到ioc中去@Component
 *
 */
/**
 * Hystrix 实现-restTemplate
 * 1.依赖 spring-cloud-starter-hystrix
 *
 *2.添加注解@EnableHystrix
 *
 * 3.在调用服务添加注解 @HystrixCommand(fallbackMethod = "hiError")
 *    fallbackMethod失败时执行的方法
 *
 */

Hystrix状态监控

/**
 * Hystrix Dashboard实现 -feign
 * 1.依赖,feign原本有hystrix依赖,但是是起步依赖所以要重新添加
 * spring-cloud-starter-hystrix-dashboard spring-boot-starter-actuator spring-cloud-starter-hystrix
 *
 * 2.开启熔断器监控注解 @EnableHystrixDashboard @EnableCircuitBreaker
 *
 */
/**
 * Hystrix DashBoard监控熔断器状态 -restTemplate
 * 1.添加依赖spring-cloud-starter-hystrix-dashboard spring-boot-starter-actuator spring-cloud-starter-hystrix
 *
 * 2.开启熔断器监控注解 @EnableHystrixDashboard
 *
 */

Turbine聚合监控

注解
@EnableTurbine
@EnableDiscoveryClient
依赖spring-cloud-starter-turbine spring-boot-starter-actuator
配置
turbine:
  aggregator:
    clusterConfig: default
  appConfig: eureka-feign-client, eureka-ribbon-client
  cluster-name-expression: new String("default")
  combine-host-port: true
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/

 

 

 

你可能感兴趣的:(spring,springcloud)