In a previous article, we have declared/defined the Zuul routes by providing the service details (URL) manually (Click here to visit that article). That means we have provided the domain name or ip address and port number of each service. Just think of a situation where the application contains a large number of microservices. Do you think that it is practical to find (manually) the server details (ip address/domain) and port details of every service? If that is difficult, then how do we declare the zuul route mapping to expose each service through the Zuul Proxy?
“The solution is to perform the Zuul routes mapping with serviceId registered in the Eureka Server“.
Here i am not going to discuss about the importance of Netflix Zuul Proxy or Netflix Eureka server. I have already written two separate articles on both of those areas. If you need to refresh your knowledge on those areas, please refer the relevant articles.
- Click here to view the article on Netflix Zuul Proxy.
- Click here to view the article on Netflix Eureka Server.
What we are going to do here?
In order to demonstrate the serviceId based Zuul route mapping, we will be creating following set of applications.
- Eureka Server :- Spring Boot Applciation to act as Eureka Server. All the microservices will be registered here.
- Zuul Proxy: – Spring Boot Application to act as Zuul Reverse Proxy. This is the centralized gateway for directing all the requests for the misroservices. Zuul proxy will communicate with Eureka server to get the details (ip address and port) of the relevant microservice for delegating the client request.
- student-service :- just dummy microservice for representing the backend business service.
Lets create them one by one. The full source code of this application can be found at GitHub.
Eureka Server is just another spring boot application with Spring Cloud Netflix Eureka dependency. Then annotate the main spring boot configuration class with @EnableEurekaServer annotation.
Therefore create a spring boot application with Eureka dependency.
Then add the @EnableEurekaServer annotation to the main Spring Boot Application configuration class (That is the class annotated with @SpringBootApplication annotation)
application.properties (Eureka Server)