【问题标题】:How to enable automatic routing in Netflix/Zuul and Netflix/Ribbon with discovery information from Netflix/Eureka Service?如何使用来自 Netflix/Eureka 服务的发现信息在 Netflix/Zuul 和 Netflix/Ribbon 中启用自动路由?
【发布时间】:2017-05-02 11:15:59
【问题描述】:

我对 Netflix 云微服务架构还很陌生。

我的网络中运行着三个微服务:

  • Zuul/Ribbon 服务:localhost:8765

    Application.yml: =============== eureka: client: serviceUrl: defaultZone: http://localhost:8761/eureka/

  • 尤里卡服务:localhost:8761

  • 租车服务:本地主机:8888

现在,我的请求是:localhost:8765/RentCarService/getAllAvailableCars

此请求应自动转发到正确的微服务(端口为 8888 的 RentCarService),例如 localhost:8888/getAllAvailableCars

我看过很多教程,其中大部分都是像本教程一样以编程方式转发请求:

Microservice discovery with spring boot and eureka

Or here by a method called getServiceURL

我必须自己编码转发还是功能区可以自动编码

最好的问候 拉尔斯

【问题讨论】:

    标签: java spring-boot microservices netflix-zuul netflix-eureka


    【解决方案1】:

    到目前为止,还没有自动路由之类的东西,至少我们需要在你的 yml 文件中声明 Zuul 来处理路由。

    在你的 application.yml 添加这些行

     zuul:
      routes:
       users:
        path: /myusers/**
        serviceId: users_service
    

    若要忽略任何路由,请使用 ignoredServices 属性,如

     zuul:
      ignoredServices: '*'
    

    有关更多信息,请参阅此this 链接。

    这将忽略您服务的所有自动路由。

    希望对你有所帮助。

    谢谢。

    【讨论】:

    • 感谢您的评论!但这并不意味着我提供了一项名为 users 的服务?我想,也许这是一个机会? github.com/jmnarloch/… 最好的问候,拉尔斯
    • 因为,我不想在 application.yml 中描述服务特定信息。应从 Eureka 服务器请求有关服务的所有信息。 Zuul 服务器应该动态路由到之前在 Eureka 服务器中注册的服务。
    【解决方案2】:

    到目前为止,我得到了它的工作。我的主要问题是不同微服务中的不同版本。请注意这个!

    另一个想法:我认为自动路由(没有任何路由定义)是不可能的。我必须在路由定义中至少写下微服务的名称。在这种情况下,地址解析由 Eureka 服务器完成。

    如果我错了,请纠正我。

    【讨论】:

      猜你喜欢
      • 2019-08-04
      • 2018-01-03
      • 1970-01-01
      • 2020-04-15
      • 2015-06-12
      • 2016-09-11
      • 2016-06-15
      • 2018-04-05
      • 2020-05-06
      相关资源
      最近更新 更多