【问题标题】:Spring cloud gateway load balancingSpring Cloud 网关负载均衡
【发布时间】:2019-11-28 11:45:03
【问题描述】:

我们使用 Spring Cloud Gateway [JavaDsl] 作为我们的 API 网关。对于代理,我们有多个微服务 [在不同的 ip:port 上运行] 作为目标。想知道我们可以配置多个目标到spring cloud gateway代理,类似于apache camel负载均衡器eip。

camel.apache.org/manual/latest/loadBalance-eip.html

我们正在寻找在 spring cloud gateway [类似于 netflix/apache-camel] 中的软件负载平衡,而不是另一个专用的 LB。

【问题讨论】:

    标签: apache-camel spring-cloud-gateway


    【解决方案1】:

    能够使用 spring-cloud-starter-netflix-ribbon 使 Spring Cloud Gateway 负载平衡路由工作。但是,当其中一个服务器实例关闭时,负载平衡失败。下面的代码片段。

    版本:

    spring-cloud-gateway : 2.1.1.BUILD-SNAPSHOT

    网关路线

    .route(
            r ->
                r.path("/res/security/")
                .filters( f -> f
                        .preserveHostHeader()
                        .rewritePath("/res/security/", "/targetContext/security/")
                        .filter(new LoggingFilter()) 
                        .uri("lb://target-service1-endpoints")
                )           
    

    application.yml

    ribbon:
      eureka:
       enabled: false
    
    
    target-service1-endpoints:
      ribbon:
        listOfServers: 172.xx.xx.s1:80, 172.xx.xx.s2:80
        ServerListRefreshInterval: 1000 
        retryableStatusCodes: 404, 500 
        MaxAutoRetriesNextServer: 1
    
    management:
      endpoint:
        health:
          enabled: true
    

    【讨论】:

      【解决方案2】:

      这是 Spring Cloud 团队的回复。

      你所描述的,确实发生了。但是,它不是特定于网关的。如果你只是在带有 listOfServers 的 Spring Cloud 项目中使用 Ribbon,同样的事情也会发生。这是因为,与 eureka 不同,非发现服务场景的 IPing 未检测(使用 DummyPing 实例)。

      您可以通过提供自己的 IPing、IRule 或 ServerListFilter 实现并以这种方式覆盖我们在自动配置中提供的设置来更改此行为。

      https://github.com/spring-cloud/spring-cloud-gateway/issues/1482

      【讨论】:

        猜你喜欢
        • 2019-08-22
        • 2020-10-06
        • 2016-10-07
        • 2022-01-18
        • 2019-04-28
        • 2016-03-29
        • 2021-10-22
        • 2015-12-24
        • 2016-01-03
        相关资源
        最近更新 更多