Zuul proxy that dynamically discovers routes
I have a simple Zuul application that has one route in application.yml to go to my microservice. He works.
However, what I am looking for is a more dynamic solution where I can connect routes dynamically, either through code, or perhaps by POST to some Zuul endpoints at build time (perhaps using SpringFX and swagger definition from microservices) I couldn't find an API for Zuul.
I know a little about Eureka and it looks like a solution to abstract away routing by making a discovery. However, I am curious if there is a solution without the introduction of Eureka. If there is a way to bind these routes in Zuul at build time since you have to edit application.yml every time.
Thanks in advance.
source to share
If you go to Eureka this will actually work ootb. Zuul, packaged in the spring cloud, automatically exposes all services under its own name. Thus, if you register a service called users
Eureka, Zuul will automatically create a /users
default forwarding route for instances. This will only allow simple URL structures, but should fix your problem.
Please see the official documentation for details:
By convention, the service with the identifier "users" will receive requests from the proxy server located at / users (with the prefix removed). The proxy uses the tape to find the instance to forward through the discovery, and all requests are made with the hystrix, ...
source to share
I am actually editing a blog post about this exact topic ( Routing and Filtering with Spring Cloud Zuul Server ), but the source code is already available and has been working for a while. Feel free to use it as a reference:
- https://bitbucket.org/asimio/zuulserver
- https://bitbucket.org/asimio/discoveryserver (in case routes are configured using serviceIds)
- https://bitbucket.org/asimio/demo-config-properties/src (Zuul-Server-refreshable.yml where routes are dynamically refreshed).
Check the updated profile settings Spring
. This setup Zuul
works with both hardcoding url routes and with Eureka
.
It also acts as a Spring Cloud Config client so that routes can be dynamically updated via Git, which is also covered in another blog post: Updatable Configuration Using Spring Cloud Config Server, Spring Cloud Bus, RabbitMQ, and Git .
source to share