Zuul 似乎在 REST 调用后重写路由

Zuul seems to rewrite routes after REST call

我在微服务项目中遇到了 Zuul-Proxy 的奇怪行为。我的设置包括一个发现服务 (Eureka)、一个 API-网关 (Zuul) 和两个微服务 "A" & "B"。 开始设置后,通过"localhost:10000/routes"显示以下路由:

{
  "/api-gateway/**": "api-gateway",
  "/a-service/**": "a-service",
  "/b-service/**": "b-service"
}

我的 Zuul 配置如下所示:

zuul:
  ignored-services: ''
  add-proxy-headers: true
  sensitiveHeaders: 'Cookie,Set-Cookie'

现在我通过网关访问服务并进行一些 REST 调用:

http://localhost:10000/a-service/sayHello --> 确定

http://localhost:10000/b-service/sayBye --> 确定

http://localhost:10000/a-service/sayHello --> 错误 404

我可以看到最后一个请求被错误地路由到服务 B,即使我使用的是“/a-service/**”路由。这怎么会发生?对服务 B 的第二个 REST 调用是否以某种方式重写了路由?

但是 "localhost:10000/routes" 仍然返回与上面相同的结果。这也适用于以相反的顺序调用服务 B-A-B -> 404 并错误地路由到服务 A.

您可以下载一个包含 4 个组件的最小项目,它应该可以让您在此处轻松复制此行为: https://github.com/Netflix/zuul/files/827817/MinimalZuulRouteBugProject.zip

感谢您提供有关此问题的任何见解。

spencergibb 的回答@github:

这是一个记录在案的问题http://cloud.spring.io/spring-cloud-static/Camden.SR5/#_customizing_the_ribbon_client

The FooConfiguration has to be @Configuration but take care that it is not in a @ComponentScan for the main application context, otherwise it will be shared by all the @RibbonClients. If you use @ComponentScan (or @SpringBootApplication) you need to take steps to avoid it being included (for instance put it in a separate, non-overlapping package, or specify the packages to scan explicitly in the @ComponentScan).

在您的情况下,RibbonConfigAvailability 由组件扫描获取并在所有功能区客户端之间共享(这很糟糕)。要么删除 @Configuration(不必如此注释,这是我测试的方式),要么将其从组件扫描中排除。

错误代码:

@Configuration //THIS ANNOTATION IS THE ERROR    
public class RibbonConfigAvailability {

    @Bean
    public IRule ribbonRule() {
        return new AvailabilityFilteringRule();
    }

}