12

I am using spring cloud eureka and spring cloud zuul proxy and i was wondering if there is any way to add dymanic zuul routes when a new service is register in eureka server or the only way to add a route is edit the application.yml file and restart the spring zuul application

zuul:
  ignoredPatterns: /**/admin/**
  routes:
    users: /myusers/**
spencergibb
  • 24,471
  • 6
  • 69
  • 75
alfespa17
  • 335
  • 1
  • 3
  • 12

1 Answers1

24

If your Zuul server is also EurekaClient (use @EnableDiscoveryClient annotation) it will discover all the services and automatically will create routes.

Ex. Zuul server is zuul.mydomain.com Eureka has 2 services registered with it : orders and accounts

Then Zuul will automatically have two routes Zuul.mydomain.com/orders and Zuul.mydomain.com/accounts

And this will forward to particular service. It will also automatically load balance calls for you if services run on multiple machines.

vladsfl
  • 617
  • 8
  • 18
  • Thanks, I added @EnableDiscoveryClient to my Zuul class and all services from eureka were discovered with automatic routes. – alfespa17 May 08 '16 at 05:13
  • 2
    I love it :), its so simple to experiment with microservices using it, rigth now i have eureka, zuul and two microservices working with just a few lines of code, now i will add spring cloud hystrix, cloud config and cloud bus – alfespa17 May 08 '16 at 05:19
  • @vladsfl, is there a way to control the routes? For e.g. how to map service orders to Zuul.mydomain.com/notorders (could not think of a nice name)? – Anand Patel Feb 22 '17 at 06:11
  • 1
    in case you added ` @EnableDiscoveryClient` and didn't work make sure you also add the depedency ` org.springframework.cloud spring-cloud-starter-eureka-server ` as well otherwise you won't see it listed in eureka server – Michail Michailidis Apr 22 '17 at 21:59
  • You probably don't want the server dependency, `spring-cloud-starter-eureka` should work just fine. – nickb Jan 30 '18 at 01:12