grpc斷路器之hystrix

上一章介紹了grpc斷路器sentinel,spring

grpc斷路器之sentinelapp

可是因爲公司線上系統用的告警與監控組件是prometheus,而sentinel暫時尚未集成prometheus,因此這裏就在部分線上系統仍是用hystrixui

步驟

一、pom依賴
<dependency>
            <groupid>org.springframework.cloud</groupid>
            <artifactid>spring-cloud-starter-netflix-hystrix</artifactid>
        </dependency>
二、啓動類或者配置類中增長@EnableHystrix
三、增長hystrixCommend註解
@PostMapping("/grpc")
    @HystrixCommand(fallbackMethod = "fallbackMethod")
    public BaseResponse doGrpc(@RequestBody ReRequest rr){
		......
		.......
}

public BaseResponse fallbackMethod(@RequestBody ReRequest rr){
		......
		.......
}
四、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超時時間大。.net

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

相關文章
相關標籤/搜索