grpc断路器之hystrix

上一章介绍了grpc断路器sentinel,
grpc断路器之sentinel
但是由于公司线上系统用的告警与监控组件是prometheus,而sentinel暂时还没有集成prometheus,所以这里就在部分线上系统还是用hystrix

步骤

1、pom依赖
<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
        </dependency>
2、启动类或者配置类中增加@EnableHystrix
3、增加hystrixCommend注解
 @PostMapping("/grpc")
    @HystrixCommand(fallbackMethod = "fallbackMethod")
    public BaseResponse doGrpc(@RequestBody ReRequest rr){
		......
		.......
}

public BaseResponse fallbackMethod(@RequestBody ReRequest rr){
		......
		.......
}
4、yml中增加相关配置
feign:
  hystrix:
    enabled: true
  okhttp:
    enabled: true
  httpclient:
    enabled: false
  compression:
    request:
      enabled: true
    response:
      enabled: true
hystrix:
  command:
    default:
      execution:
        timeout:
          enabled: true
        isolation:
          thread:
            timeoutInMilliseconds: 1000
      circuitBreaker:
        requestVolumeThreshold: 50
  threadpool:
    default:
      coreSize: 60
      maxQueueSize: 200
      queueSizeRejectionThreshold: 200

需要注意的是grpc也会有超时时间,这里断路器设置超时时间应该比grpc超时时间大。

在这里插入图片描述在这里插入图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章