SpringCloudGateway集成Ribbon不重试可用服务

问题描述

使用Springcloud Gateway 搭建了一个网关用来路由请求,没有服务中心(Eureka),使用Ribbon做负载均衡,但是当某个服务的实例死掉之后,请求依旧会转发到此实例上,也就是不能重试到其他可用的实例上

问题出现的环境背景及自己尝试过哪些方法

尝试了很多方法,都没能起作用,所有的代码基本上都在配置文件里

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)

spring:
  application:
    name: hyacinth-api-gateway
management:
  endpoints:
    web:
      exposure:
        include: '*'
ribbon:
  eureka:
    enabled: false
  eager-load:
    enabled: true
    clients: api-research-load-balance

debug: true
---
server:
  port: 1606
spring:
  profiles: dev

  cloud:
    gateway:
      routes:
      - id: hyacinth-api-research
        uri: lb://api-research-load-balance
        predicates:
        - Path=/api/research/**

    loadbalancer:
      retry:
        enabled: true


api-research-load-balance:
  ribbon:

    listOfServers: localhost:1603,localhost:1602
    NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule
    ServerListRefreshInterval: 2000
    retryableStatusCodes: 500
    ConnectTimeout: 500
    ReadTimeout: 20000
    OkToRetryOnAllOperations: true
    MaxAutoRetriesNextServer: 2
    MaxAutoRetries: 0

hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMillisecond: 10000

你期待的结果是什么?实际看到的错误信息又是什么?

求大神给点建议,怎么配置,才能实现选中server是宕机的之后能重试到其他server上。

阅读 3.9k
1 个回答
推荐问题