使用fegin做服务的调用的时候,报错:handleAllExceptionsException :com.netflix.hystrix.exception.HystrixRuntimeException: PayClient#addOrModifyChargeManagement(AddOrModifyChargeManagement,Long) timed-out and no fallback available.

原因:调用等待时间超市,Hystrix因超时导致的熔断

hystrix

修改配置中心的timeoutInMilliseconds 改为10000, 即10秒

hystrix:
  threadpool:
    default:
      coreSize: 10  #并发执行的最大线程数,默认10
  command:
    paas-file:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 3000
    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 1000  #命令执行超时时间,默认1000ms

 将1000ms改为10000(10s)延长服务等待时间

其他方法:

ribbon

ribbon:
  MaxAutoRetries: 1 #最大重试次数,当Eureka中可以找到服务,但是服务连不上时将会重试,如果eureka中找不到服务则直接走断路器
  MaxAutoRetriesNextServer: 1 #切换实例的重试次数
  OkToRetryOnAllOperations: false  #对所有操作请求都进行重试,如果是get则可以,如果是post,put等操作没有实现幂等的情况下是很危险的,所以设置为false
  ConnectTimeout: 10000  #请求连接的超时时间
  ReadTimeout: 10000 #请求处理的超时时间

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐