Zuul API Gateway
What is Zuul?
Zuul Server is an API Gateway application. It handles all the requests and performs the dynamic routing of microservice applications. It works as a front door for all the requests. It is also known as Edge Server.
Zuul is built to enable dynamic routing, monitoring, resiliency, and security. It can also route the requests to multiple Amazon Auto Scaling Groups.
For Example, /api/products are mapped to the product service and /api/user is mapped to the user service. The Zuul Server dynamically routes the requests to the respective backend application.
Why we use Zuul?
The volume and variety of Netflix API traffic sometimes result in production issues that arises quickly and without warning. So we need a system that allows us to rapidly change behavior in order to react to these situations.
Zuul provides a range of different types of filters that allows us to quickly and nimbly apply functionality to our edge service. The filters perform the following functions:
Zuul 2.x components:
Zuul 1.x components:
Setting up Zuul API Gateway Server
There are three steps to set up the Zuul API Gateway:
Follow the steps to set up the Zuul API Gateway server.
Step 1: Open Spring Initializr https://start.spring.io.
Step 2: Provide the Group name. We have provided com.javatpoint.microservices.
Step 3: Provide the Artifact. We have provided netflix-zuul-api-gateway-server.
Step 4: Add the following dependencies: Zuul, Eureka Discovery, Actuator, and DevTools.
Step 5: Click on the Generate button. It starts packing the project into zip file and download it.
Step 6: Extract the zip file and paste it in the Spring Tool Suite’s workspace.
Step 7: Import the project in the STS IDE.
File -> Import -> Existing Maven Projects -> Browse -> Select netflix-zuul-api-gateway-server -> Select Folder -> Finish
It takes some time to import.
Step 8: Open the NetflixZuulApiGatewayServerApplication.java file and enable zuul proxy and discovery client by using the annotations @EnableZuulProxy and @EnableDiscoveryClient, respectively.
Step 9: Open application.properties file and configure the application name, port, and eureka naming server.