Kyle Chamberlin
Kyle Chamberlin

Reputation: 127

Zuul Routing when using eureka services

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?

Upvotes: 0

Views: 5249

Answers (1)

Grinish Nepal
Grinish Nepal

Reputation: 3063

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/

Upvotes: 7

Related Questions