Javatpoint Logo
Javatpoint Logo

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:

  • Authentication and Security: It provides authentication requirements for each resource.
  • Insights and Monitoring: It tracks meaningful data and statistics that give us an accurate view of production.
  • Dynamic Routing: It dynamically routes the requests to different backed clusters as needed.
  • Stress Testing: It increases the traffic to a cluster in order to test performance.
  • Load Shedding: It allocates capacity for each type of request and drops a request that goes over the limit.
  • Static Response Handling: It builds some responses directly at the edge instead of forwarding them to an internal cluster.
  • Multi-region Resiliency: It routes requests across AWS regions in order to diversify our ELB usage.

Zuul Components

Zuul 2.x components:

  • zuul-core: It is a library that contains the core functionality of Zuul 2.0.
  • zuul-sample: It is a sample driver application for Zuul 2.0

Zuul 1.x components:

  • zuul-core: It defines the core functionality.
  • zuul-simple-webapp: A web app that shows a simple example of how to build an application with zuul-core.
  • zuul-netflix: It is a library that adds other NetflixOSS components to Zuul.
  • zuul-netflix-webapp: It is a webapp that packages zuul-core and zuul-netflix together.

Setting up Zuul API Gateway Server

There are three steps to set up the Zuul API Gateway:

  • Create a component for the Zuul API Gateway
  • Decide the things that the Zuul API Gateway should do
  • All the important requests are configured to pass through 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.

Zuul API Gateway

Step 5: Click on the Generate button. It starts packing the project into zip file and download it.

Zuul API Gateway

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.

NetflixZuulApiGatewayServerApplication.java

Step 9: Open application.properties file and configure the application name, port, and eureka naming server.

application.properties






Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA