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超時時間大。

在這裏插入圖片描述在這裏插入圖片描述

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