SpringCloud-Hystrix

1 篇文章 0 订阅
1 篇文章 0 订阅

Hystrix

系统容错、限流工具

功能

降级

当一个服务调用一个后台服务失败(异常、服务不存在、超时:Hystrix的超时时间默认为1s),可以执行当前服务中的一段"降级代码",
来返回降级结果,如:“系统异常”

添加降级功能:
1、添加Hystrix依赖

 <dependency>
     <groupId>org.springframework.cloud</groupId>
     <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
 </dependency>

2、启动类添加注解:@EnableCircuitBreaker
3、添加降级代码:
在远程调用的代码上,添加:@HystrixCommoand(fallbackMethod=“降级方法”)

更改hystrix的默认超时时间

hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMillisecond: 1000

熔断

服务过热,直接把后台服务断开,限制服务的请求流量
在特定条件下,会自动触发熔断(参数可调):
	1)10秒20次请求(必须满足,才会判断第二个条件)
	2)50%失败,执行了降级代码
熔断后,所有请求直接执行降级代码,返回降级结果。

半开状态:
断路器打开几秒后,会进入半开状态,向后台服务发送一次用户请求,如果成功,则关闭断路器,回复正常。
如果失败,继续保持断开状态几秒,循环执行。

actuator

SpringBoot提供的项目监控信息工具,提供项目的各种监控日志数据
hystrix利用actuator曝露自己的监控日志,日志端点:hystrix.stream

添加actuator
1、添加actuator依赖

 <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

2、曝露监控端点

management:
  endpoints:
    web:
      exposure:
        include: "*"

Hystrix Dashboard

1、添加Hystrix Dashboard依赖

 <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
        </dependency>

2、yml配置
配置允许抓取日志

hystrix:
  dashboard:
    proxy-stream-allow-list: localhost

3、启动类添加@EnableHystrixDashboard注解

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值