【问题标题】:Spring Boot Zuul : Map Multiple Route URLsSpring Boot Zuul:映射多个路由 URL
【发布时间】:2017-11-13 19:45:46
【问题描述】:

我们使用带有 Zuul 代理的 Spring Boot 将 API 请求转发到 API。示例配置如下:

zuul.routes.common.url=http://10.0.0.1:8081/common
zuul.routes.meta.url=http://10.0.0.2:8082/meta

这一切都很好。为了平衡我们的负载和有效地利用底层服务器,我们希望指定多个 URL 作为配置的一部分,并为其中一个 URL 启用请求转发。准确地说,我们希望通过提供可以处理请求的以逗号分隔的端点列表来配置代理配置,如下所示。

zuul.routes.common.url=http://10.0.0.1:8081/common,http://10.0.0.11:8081/common
zuul.routes.meta.url=http://10.0.0.2:8082/meta,http://10.0.0.12:8082/meta

但不幸的是,这样的配置会导致“找不到资源错误”。

问题:

  1. 这是一种可能的配置吗?
  2. 如果没有,是否可以通过其他方式实现?

问候, 曼朱纳特

编辑:回答

仅使用 Zuul 无法配置多个 URL。请求需要使用 Ribbon 进行负载平衡。这是带有功能区的示例配置:

zuul.routes.common.path=/**
zuul.routes.common.serviceId=common
common.ribbon.listOfServers=http://10.0.0.1:8081/common,http://10.0.0.2:8081/common

【问题讨论】:

    标签: spring-boot spring-cloud netflix-zuul


    【解决方案1】:

    您想使用功能区和属性client.ribbon.listOfServers。这是一个简单的例子

    zuul:
      routes:
        users:
          path: /myusers/**
          serviceId: users
    
    ribbon:
      eureka:
        enabled: false
    
    users:
      ribbon:
        listOfServers: example.com,google.com
    

    【讨论】:

    • 非常感谢。直接使用 Zuul 是不可能设置多个 URL 的。
    • 正确,你需要使用Ribbon
    • 但这不允许HTTPS,我得到的只是java.security.SignatureException: Signature does not match
    猜你喜欢
    • 2016-03-21
    • 2020-10-25
    • 1970-01-01
    • 1970-01-01
    • 2016-06-30
    • 1970-01-01
    • 2019-02-01
    • 2018-01-12
    • 2017-11-09
    相关资源
    最近更新 更多