Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Cloud Zuul/Eureka dynamic route

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/**
like image 230
alfespa17 Avatar asked May 05 '16 15:05

alfespa17


People also ask

What is dynamic routing in Zuul?

The Netflix Zuul service provides dynamic routing. Using Zuul in your app enables your services to use the information from the Eureka service directory to reach other services. Because both Eureka and Zuul are Java applications they can be implemented with Spring Boot, part of the Spring Framework for Java.

How does Zuul work with Eureka?

Each request received by Zuul is forwarded to a different instance in a round robin fashion. If we start another instance and register it in Eureka, Zuul will register it automatically and start forwarding requests to it: Hello from 'SPRING-CLOUD-EUREKA-CLIENT with Port Number 8083'!

What is difference between Eureka and Zuul?

Eureka belongs to "Open Source Service Discovery" category of the tech stack, while Zuul can be primarily classified under "Microservices Tools". Eureka is an open source tool with 8.16K GitHub stars and 2.27K GitHub forks.


1 Answers

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.

like image 172
vladsfl Avatar answered Oct 13 '22 00:10

vladsfl