0
votes

I have a reasonably simple Spring Cloud Netflix setup. We are using Zuul as a reverse proxy and Eureka for service discovery and registry. we have legacy services we are slowly choking out. We have many simple services that have their endpoints configured like this:

{host}:{port}/{service-name}/**

so now when each service is registered with eureka, and subsequently has a route added to Zuul, the zuul endpoint looks like this:

{zuul-host}:{zuul-port}/{service-name}/{service-name}/**

I want to stop Zuul from striping the prefix off the routed URIs for eureka services so that my zuul endpoints look like this:

{zuul-host}:{zuul-port}/{service-name}/**

and forward to:

{zuul-host}:{zuul-port}/{service-name}/** 

I would like this to be done in a way such that I do not have to add configs for each and every service.

I would have assumed that zuul.strip-prefix would have done the trick, but that doesn't appear to be the case.

current 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/

Anyone have a suggestion for how I can configure zuul in this way?

1
Have you tried defining the prefix in zuul.prefix?Jeff
The prefix is different for each service, that prefix being each service's name. so as a work around we currently have entries in the application.yml for each eureka service but that doesn't scale well.Kyle Chamberlin

1 Answers

6
votes

Since you are registering your service with eureka why not use the service-id for routing like below. the service-id is the id that your service gets registered in Eureka with.

zuul:
  routes:
     path: /oldservice/**
     service-id: oldservice
     strip-prefix: false
eureka:
  client:
    serviceUrl:
      defaultZone: http://eureka-host:8761/eureka/

For your current scenario I moved the strip-prefix inside the routes I have it like that in my system you can try that.

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/