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

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

相关文章
相关标签/搜索