【问题标题】:Zuul routing : One endpoint with multiple microservicesZuul 路由:一个端点与多个微服务
【发布时间】:2017-05-16 20:04:48
【问题描述】:

我想设置 zuul 和底层微服务,使所有服务都在“/gateway”上下文中。

例如:

微服务 1 有:http://localhost:8081/api/hello

微服务 2 有:http://localhost:8082/api/bye

我希望能够通过 zuul 访问微服务,如下所示:

微服务 1:http://localhost:8080/网关/microservice1/api/hello

微服务 2:http://localhost:8080/网关/microservice2/api/bye

我已尝试进行设置,但请求似乎没有正确路由。

我希望前端将所有客户端 REST 调用路由到以“/gateway”开头的服务器的原因是它为前端提供了更简单的维护。

我的应用程序.yml:

zuul:
 prefix: /gateway
   routes:
     microservice1:
        path: /microservice1/**
        serviceId: microservice1
        strip-prefix: true
     microservice2:
        path: /microservice2/**
        serviceId: microservice2
        strip-prefix: true

谢谢

【问题讨论】:

  • 你怎么把两个微服务和网关放在同一个端口号下……它们是部署在不同的服务器上还是所有东西都打包在一起。
  • 每个服务都在自己的端口上启动。更新了问题。 Zuul 在 8080 上,M1 在 8081 上,M2 在 8082 上。更新了问题。谢谢

标签: java spring-cloud microservices netflix-zuul spring-cloud-netflix


【解决方案1】:

试试这个配置,让我知道这是否适合你。我认为您将必须定义一个全局 strip-prefix:true ,如下所示。实际上它也应该在没有去除前缀的情况下工作,因为默认情况下它会去除两个前缀。

zuul:
 prefix: /gateway
 strip-prefix: true
   routes:
     microservice1:
        path: /microservice1/**
        serviceId: microservice1
        strip-prefix: true
     microservice2:
        path: /microservice2/**
        serviceId: microservice2
        strip-prefix: true

【讨论】:

    猜你喜欢
    • 2017-04-28
    • 2019-07-18
    • 2015-04-24
    • 2020-09-15
    • 1970-01-01
    • 1970-01-01
    • 2018-03-23
    • 2018-05-22
    • 2019-09-11
    相关资源
    最近更新 更多