Search code examples
spring-bootnetflix-zuulnetflix-eurekaspring-cloud-netflix

Route Existing Services via ZUUL without adding routing rule


I am trying to route existing services via Spring cloud Netflix Zuul.

I have an existing service available at below url,

http://localhost:3080/query-service/getquery/1

Out of the box, with zuul I can route to the service as below, localhost:9000/queryservice-id/queryservice/getquery/1, with "queryservice-id" as the service-id of the service when it is registered in Service Registry. The zuul port is 9000.

I do not want to change the context path and service path information when accessing the service via ZUUL.

With ZUUL, I want to access the service as below, http://localhost:9000/query-service/getquery/1

I do want to prefix with the "serviceId". This is because I do not want to impact any existing clients of the service. Only the host and port changes, without serviceId.

I was able to accomplish it as below with ZUUL Configuration,

zuul:
  routes:
    query-service:
      path: /query-service/**
      serviceId: query-service
      stripPrefix: false

With the above configuration, I am able to only use the zuul host and port, the other service specific information remains as before. Seems like stripPrefix is helping in routing without the serviceId.

But, I have a lot of services and will be adding more services too.

For every such service, I do not want to be adding a rule like that to ZUUL configuration which will mean rebuilding and recycling the ZUUL Service.

I feel there should be a simpler and better way to accomplish this, without a big effort, because the change I want to do is common to all services

Is there a way to making this change common for alll the services I want to be routed via ZUUL.

Thanks,


Solution

  • As checked with the Spring Cloud Netflix team this is recommended approach. https://github.com/spring-cloud/spring-cloud-netflix/issues/1549