Zuul filters
Zuul filter Profile
spring cloud Zuul contains routing requests and two filter functions. Is responsible for routing function forwards the request to the specific micro-services, and the filter is responsible for processing the request to intervene is the basis of authority check, and other functions of the service aggregator.
In actual operation, the route mapping and forwards the request by several different filter completed. Each will enter zuul http request through a series of filters to give request response processing chain and returned to the client.
spring cloud zuul comprising four types of filters.
- pre filter. Called before the request is routed. Zuul request before micro-services. For example, request authentication, select the service instance micro, record debugging information.
- route filter. Responsible for forwarding the request to the micro-service. In this construct the original request, and sending the original request using the Apache HttpClient or Netflix Ribbon.
- post filter. After the route is called and error filters. You can add standard HTTP Header In response, gather statistics and indicators, as well as the response sent to the client and so on.
- error filter. It is called when an error occurs processing the request.
In addition to the default Filter, Zuul also allows us to create a custom filter type. For example, we can customize a STATIC type filter, it generates the response Zuul, instead of forwarding the request to a specific micro-services.
Lifecycle Zuul request are as follows:
Reference Netflix Zuul wiki
Custom filters Zuul
Create a new module microservice-gateway-zuul-filter.
Add rely Zuul and Eureka client:
1 |
<dependency> |
application.yml:
1 |
spring: |
Define a pre types of filters, records the request URI.
1 |
public class extends ZuulFilter { |
spring boot main categories:
1 |
|
test:
Start Eureka Server, user module and microservice-gateway-zuul-filter.
We access user module by Zuul's host and port / sample / 1.
We look at the console.
We simply record what URI request. More usage can refer netflix-core package ZuulFilter implemented.
Details of the filter may use Zuul Reference: https://www.jianshu.com/p/ff863d532767
Original: Big Box Zuul filters