【发布时间】:2019-11-23 02:20:08
【问题描述】:
在我的 MicroserviceZoo 中,我有一个 Zuul 网关和 3 个由 Eureka 发现的微服务(service1、service2、service3)。 Zuul 应将它们代表到外部并充当具有负载平衡(功能区)和断路(hystrix)的 api 网关。
现在在服务路由中,我遇到了一个看起来很容易解决的问题,但我被这个问题困扰太久了。
我想要的是 Zuul 通过同一个 API 路由到 service1、service2、service3:
gateway:port/api/1/service1/public/time
应该变成
gateway:port/api/1/public/time
和
gateway:port/api/1/service2/public/stats
会变成
gateway:port/api/1/public/stats
..这样 /api/1/public/stats 路由到 microservice2(托管 stats 方法)和 /api/1/public/time 路由到 microservice1(托管 time 方法)
这是我当前的 Zuul-Config(在 bootstrap.yml 中):
zuul:
prefix: /api/1
stripPrefix: false
routes:
time:
path: /**/public/time
serviceId: service1
stats:
path: /**/public/stats
serviceId: service2
stream:
path: /**/public/stream
serviceId: service3
ignored-services: '*'
strip-prefix: false
我错过了什么? 你如何使用 Zuul 和 Eureka 进行细粒度路由?
【问题讨论】:
-
不幸的是spring cloud的zuul只能去除前缀。除非您编写自己的过滤器,否则您需要仅在 Spring Cloud Gateway 中可用的重写功能
-
谢谢你的好提示@spencergibb 你会建议迁移到spring cloud gateway还是自己实现一个过滤器?我认为云网关可能更适合未来,因为它成功了 zuul..?
标签: rest spring-cloud netflix-eureka netflix-zuul api-gateway