Skip to content

Zuul Filters

Wuyi Chen edited this page Apr 2, 2019 · 24 revisions

Overview


Filter Types

  • Pre filter
    • Invocation: Invoked before routing the request to the target service.
    • Uses:
      • Request authentication.
      • Request authorization.
      • Make sure all the requests are in the consistent format.
      • Log debug info.
  • Post filter
    • Invocation: Invoked after the target service has been triggered and a response is being sent back to the client.
    • Uses:
      • Make sure all the response are in the consistent format.
      • Log debug info.
      • Collect statistics and metrics.
      • Stream the response from the target service to the client.
  • Route filter
    • Invocation: Invoked when the request is routing to the target service.
    • Uses:
      • Define a custom routing logic.
      • A/B test.
  • Error filter
    • Invocation: Invoke when an error occurs during the execution of other filters.

How to Define a Filter

To define a custom filter, you need to create a class and implement the ZuulFilter interface. For the ZuulFilter interface, there are 4 methods need to be overridden:

Method Description
public String filterType() Type: Define the filter type
public int filterOrder()
shouldFilter() Criteria: Define the filter will be invoked or not.
public Object run() Action: The action to be executed if the criteria is met.
Clone this wiki locally