This is the 6th day of my participation in the August More Text Challenge

SpringCloud Zuul provides gateway functionality in microservices, and today’s purpose is to take a look at the basic architecture and configuration of SpringCloud Zuul.

What gateway functionality does Zuul provide

  1. The Zuul component provides a unified API entry to the microservices architecture, and processes the API according to the different filters that are passed to the back-end business.

  2. The Zuul component mainly provides filtering mechanism and dynamic routing functions.

  3. The Zuul component also provides performance filtering, service aggregation, service fault tolerance, and more.

  4. Because Zuul automatically integrates the Ribbon and Hystrix, Zuul components come with built-in load balancing and service fault tolerance capabilities.

What is the core of Zuul’s work?

What is the core of Zuul’s work? The unanimous answer is filters, and Zuul’s internal code implements multiple filter types to support gateway work.

What types of filter types Zuul provides

Pre: can be called before the request is routed.

This filter type is more applicable to identity authentication scenarios. After the authentication succeeds, go to the next step.

Route: called when routing a request.

Suitable for grayscale publishing scenarios, while accessing the route to do some custom logic, to meet the corresponding weird needs.

Post: called after route and error filters.

Such filters will be executed after the request routes to a specific service. This method is applicable to scenarios where response headers are added and response logs are recorded.

Error: Called when an error occurs while processing a request.

When an error is sent during execution, an error filter is displayed to record the error information in a unified manner for later troubleshooting.

What are the key configurations of Zuul

We import the jar package directly into the Spring Cloud Zuul module, and of course we need to modify the Application class with the @EnableZuulProxy annotation.

Configure Zuul access API path:

zuul.routes.eureka-application-service.path=/api/**
Copy the code

Configure Zuul service name:

zuul.routes.eureka-application-service.serviceId=service-zuul-name
Copy the code

Configure the ignorable service:

zuul.ignored-services=service-1
Copy the code

Configure Zuul route prefix path:

zuul.prefix=/zuul
Copy the code