使用eureka服务时的Zuul路由

Kyl*_*lin 0 routing spring-boot netflix-eureka netflix-zuul spring-cloud-netflix

我有一个相当简单的Spring Cloud Netflix设置.我们使用Zuul作为反向代理,使用Eureka进行服务发现和注册.我们有遗留服务,我们正在慢慢窒息.我们有许多简单的服务,其端点配置如下:

{host}:{port}/{service-name}/**
Run Code Online (Sandbox Code Playgroud)

所以现在当每个服务都在eureka注册,并且随后有一条添加到Zuul的路由时,zuul端点如下所示:

{zuul-host}:{zuul-port}/{service-name}/{service-name}/**
Run Code Online (Sandbox Code Playgroud)

我想阻止Zuul从eureka服务的路由URI中删除前缀,以便我的zuul端点看起来像这样:

{zuul-host}:{zuul-port}/{service-name}/**
Run Code Online (Sandbox Code Playgroud)

并转发到:

{zuul-host}:{zuul-port}/{service-name}/** 
Run Code Online (Sandbox Code Playgroud)

我希望这样做,以便我不必为每个服务添加配置.

我本以为zuul.strip-prefix可以做到这一点,但事实并非如此.

当前Zuul application.yml:

zuul:
  routes:
    oldservice:
      path: /oldservice/**
      url: http://oldservice-host:9080/api/v1/oldservice
  strip-prefix: false
eureka:
  client:
    serviceUrl:
      defaultZone: http://eureka-host:8761/eureka/
Run Code Online (Sandbox Code Playgroud)

有人建议我如何以这种方式配置zuul?

Gri*_*pal 6

由于您使用eureka注册服务,为什么不使用service-id进行路由,如下所示.service-id是您的服务在Eureka中注册的ID.

zuul:
  routes:
     path: /oldservice/**
     service-id: oldservice
     strip-prefix: false
eureka:
  client:
    serviceUrl:
      defaultZone: http://eureka-host:8761/eureka/
Run Code Online (Sandbox Code Playgroud)

对于您当前的场景,我将条带前缀移动到我所拥有的路径中,就像在我的系统中一样,您可以尝试使用它.

zuul:
  routes:
    oldservice:
      path: /oldservice/**
      url: http://oldservice-host:9080/api/v1/oldservice
      strip-prefix: false
eureka:
  client:
    serviceUrl:
      defaultZone: http://eureka-host:8761/eureka/
Run Code Online (Sandbox Code Playgroud)