1:SpringCloud中使用:
1.1:加入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
1.2:启动类上添加
@SpringBootApplication
@EnableHystrixDashboard
@EnableCircuitBreaker
//@EnableHystrix
1.3:Controller上配置
在Controller的方法上添加Hystrix的配置,形如:
@HystrixCommand(fallbackMethod = "error", commandProperties = {
@HystrixProperty(name="execution.isolation.strategy", value = "THREAD"),
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "4000"),
@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),
@HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = ”50")
}, threadPoolProperties = {
@HystrixProperty(name = "coreSize", value = "1"),
@HystrixProperty(name = "maxQueueSize", value = "10"),
@HystrixProperty(name = "keepAliveTimeMinutes", value = "1000"),
@HystrixProperty(name = "queueSizeRejectionThreshold", value = "8"),
@HystrixProperty(name = "metrics.rollingStats.numBuckets", value = "12"),
@HystrixProperty(name = "metrics.rollingStats.timeInMilliseconds", value = "1500")
})
Hystrix支持两种方式定义HystrixCommand,一种是将类继承自HystrixCommand类,重写run方法,另一种是在方法头上写注解的方式,使用注解的方式代码会比较清晰,将Hystrix代码和业务代码隔离开
2: DashBoard
2.1: 概述
Hystrix自带了DashBoard,如果监控单个实例,可以很方便的通过Hystrix的dashboard进行查看运行情况,直接进入http://localhost:8080/hystrix
Hystrix Dashboard共支持三种不同的监控方式,依次为:
- 1:默认的集群监控:通过URLhttp://turbine-hostname:port/turbine.stream开启,实现对默认集群的监控。
- 2:指定的集群监控:通过URLhttp://turbine-hostname:port/turbine.stream?cluster=[clusterName]开启,实现对clusterName集群的监控。
- 3:单体应用的监控:通过URLhttp://hystrix-app:port/hystrix.stream开启,实现对具体某个服务实例的监控。
前两者都对集群的监控,需要整合Turbine才能实现
2.2: 示例如下
- Delay:该参数用来控制服务器上轮询监控信息的延迟时间,默认为2000毫秒,可以通过配置该属性来降低客户端的网络和CPU消耗。
- Title:该参数对应了头部标题Hystrix Stream之后的内容,默认会使用具体监控实例的URL,可以通过配置该信息来展示更合适的标题。
- 监控信息的左上部分找到两个重要的图形信息:一个实心圆和一条曲线。
(1)实心圆:共有两种含义。它通过颜色的变化代表了实例的健康程度,它的健康度从绿色、黄色、橙色、红色递减。该实心圆除了颜色的变化之外,它的大小也会根据实例的请求流量发生变化,流量越大该实心圆就越大。所以通过该实心圆的展示,就可以在大量的实例中快速的发现故障实例和高压力实例。
(2)曲线:用来记录2分钟内流量的相对变化,可以通过它来观察到流量的上升和下降趋势。
相关推荐
spring-cloud-netflix-hystrix应用
spring-cloud-netflix-hystrix-dashboard-2.2.3.RELEASE.jar
spring-cloud-hystrix:Hystrix熔断的使用示例 hystrix-dashboard-turbine:熔断监控Hystrix Dashboard和Turbine的示例 spring-cloud-config-git:配置中心git版本示例 spring-cloud-config-svn-refresh:配置中心...
springcloud-ribbon-feign-hystrix-zuul-config
SpringCloud-2.0-order-hystrix-ribbon-8011.zip 使用hystrix实现短路保护操作
spring-cloud-netflix-hystrix-2.1.0.RELEASE
spring-cloud-starter-netflix-hystrix-2.1.0.RELEASE
spring-cloud-starter-netflix-hystrix-dashboard-2.1.0.RELEASE
spring-cloud-eureka Spring Cloud(一)服务的注册与发现(Eureka) spring-cloud-consul Spring Cloud(二) Consul 服务治理实现 spring-cloud-ribbon Spring Cloud(三) 服务提供者 Eureka + ...
spring-cloud-hystrix:Hystrix熔断的使用示例 hystrix-dashboard-turbine:熔断监控Hystrix Dashboard和Turbine的示例 spring-cloud-config-git:配置中心git版本示例 spring-cloud-config-svn-refresh:配置中心...
hystrix原理
spring-cloud-hystrix-dashboard(包含注册中心、member、hystrix-dashboard配置等).zip 包含配置好的eureka注册中心,member服务生产者、hystrix-dashboard的hystrix配置和仪表盘配置
- [springcloud(十五):服务网关 Spring Cloud GateWay 初级篇](http://www.ityouknow.com/springcloud/2018/12/12/spring-cloud-gateway-start.html) - [springcloud(十六):服务网关 Spring Cloud GateWay 服务...
spring cloud eureka zuul ribbon hystrix feign config 示例代码
springcloud config bus 配套代码
spring-cloud-hystrix-feign(注册中心、member、feign-order).zip 包含注册中心、member、feign-order系列代码
SpringCloud10-2 Hystrix整合Dashboard教程
spring cloud降级服务-hystrix.7z
SpringCloud——断路器(Hystrix)之Ribbon使用断路器和Feign使用断路器
轻松阅读是一款图书阅读类 APP,基于 Spring Cloud 开发的微服务实战项目,涉及 SpringCloud-Gateway、Nacos、Hystrix、OpenFeign、Jwt、ElasticSearch 等技术栈的应用。 轻松阅读是一款图书阅读类 APP,基于 Spring...