【问题标题】:How to Configure Zuul Multiple instances of one microservice如何配置 Zuul 一个微服务的多个实例
【发布时间】:2018-12-24 19:57:17
【问题描述】:

我在一个 Spring Cloud 项目中工作,我有一个 eruka 服务、zull 代理和一个名为缺陷服务的微服务(zull 代理和我的缺陷服务是 eurka​​ 的客户端)并且一切正常。 在我的 zull 代理中,我有以下配置:

eureka:
  client:
    register-with-eureka: true
    fetch-registry: true
    serviceUrl:
      defaultZone:  http://localhost:8370/eureka/
  instance:
      hostname: localhost

    zuul:
      prefix: /api
      routes:
        defects-service:
         path: /defects-service/**
         url: http://localhost:8300

我现在的问题是我在不同的端口 8301 和 8302 上启动了我的缺陷服务的两个实例(在 eruka 服务中成功注册),但我不知道如何配置我的 zull 代理来进行负载平衡并启动重定向请求到我在端口(8300,8301,8302)上的三个实例。 注意,zull 只知道http://localhost:8300上的实例

谁能帮我解决这个问题。

最好的问候。

【问题讨论】:

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


    【解决方案1】:

    Zuul 支持开箱即用的负载平衡,而不是在你的配置中给出url,而是使用serviceId

     zuul:
          prefix: /api
          routes:
            defects-service:
             path: /defects-service/**
             serviceId: defects-service
    

    【讨论】:

    • 您好@slimane 感谢您的回复,我通过添加 serviceId 更改了我的配置,但是当我调用我的服务“状态”时出现以下错误:504,“错误”:“网关超时” , "message": "com.netflix.zuul.exception.ZuulException: Hystrix Readed time out" 还有其他配置我应该添加吗?
    • 你能发布更多的堆栈跟踪吗?请将其添加到您的帖子中
    • 我得到:com.netflix.zuul.exception.ZuulException: at org.springframework.cloud.netflix.zuul.filters.post.SendErrorFilter.findZuulException(SendErrorFilter.java:114) ~[ spring-cloud-netflix-zuul-2.1.0.RC3.jar:2.1.0.RC3] 在 org.springframework.cloud.netflix.zuul.filters.post.SendErrorFilter.run(SendErrorFilter.java:76) ~[spring -cloud-netflix-zuul-2.1.0.RC3.jar:2.1.0.RC3]
    • 这还不够日志,第一个建议:ribbon.eager-load.enabled = true
    • 非常感谢@slimane 的回复,我找到了解决方案,并将其作为回复发布。问候
    【解决方案2】:

    这个问题的解决方法是使用以下配置:

    zuul:
          prefix: /api
          routes:
            defects-service:
             path: /defects-service/**
             serviceId: defects-service
    

    之后,如果您遇到任何错误,例如 Hystrix Readed time out.. 只需添加以下配置:

    hystrix:
      command:
        default:
          execution:
            isolation:
              thread:
                timeoutInMilliseconds: 11000
    ribbon:
      ConnectTimeout: 10000
      ReadTimeout: 10000
    

    【讨论】:

      猜你喜欢
      • 2018-02-18
      • 2017-05-16
      • 2018-03-23
      • 2019-11-27
      • 1970-01-01
      • 2021-10-04
      • 2021-09-12
      • 2018-05-22
      • 2017-04-28
      相关资源
      最近更新 更多