Zuul some simple concepts

. What is a gateway:

Inlet unified, all requests received and forwarded to the appropriate service according to the rules defined.
In this process, the system can also complete some general unified work, such as checking permissions, limiting and so on.
Zuul is a service provided by NetFlix gateway for implementing routing, filters and other functions (Zuul is blocking asynchronous model).
Gateway also serving gateway (non-blocking model).

Popular point is to provide a layer of protection for the service, the request is forwarded outside of the filter to the back-end service.

Here we can come to understand through a few simple example of FIG ..

FIG example 1.1 NA gateway:
Here Insert Picture Description

FIG gateway Example 1.2:

Here Insert Picture Description

We found that after adding the gateway is actually a pair of N relationship turned into one relationship, the user simply dealing with a gateway like, this advantage is that we can legally check data at the gateway, certification authority, load balancing, unified treatment, it saves a great extent on the human and material resources.

Two. Zuul function ( Zuul be appreciated Wei filter )

Wei will be appreciated that the filter Zuul

  1. Zuul, Ribbon, Eureka combination, can achieve intelligent routing and load balancing functions, Zuul request traffic can be distributed to the state of the cluster according to some policies of multiple service instances.
  2. The API interface for all services consistent aggregation, and unified external exposure. When the system call API interface to the outside world, are calling API interface, the external system gateway of foreign exposure is not known micro-service system for each service does. Interface in the protection system will not be attacked.
  3. Can be used as user authentication and permissions certification, API interface to prevent the illegal operation request, the server is a protective effect.
  4. You can achieve monitoring, real-time log output, to request records.
  5. Traffic monitoring can be achieved, in the case of high traffic, the service downgrade.
  6. API interface is separated from the internal service, convenient to do the test.

Work of the principle of Zuul

Zuul 是通过 Servlet 来实现的, Zuul 通过自定义的ZuulServlet(类似 Spring MVC 的 DispatcServlet)来对请求进行控制。
Zuul的核心是一系列的过滤器,可以在Http请求的发起和响应期间执行一系列的过滤器。

Zuul 包括以下4中过滤器:

  1. PRE过滤器: 它是在请求路由到具体的服务之前执行的,可以做安全验证,例如:身份验证、参数验证等。
  2. ROUTING过滤器: 将请求转发到具体的微服务实例进行逻辑处理。在默认情况下,它使用Http Client 进行网络请求。
  3. POST过滤器: 它是在请求已被路由到微服务后执行的。一般情况下,用作收集统计信息、指标,以及将相应传输回客户端。
  4. ERROR 过滤器:: 它是在其他过滤器发生错误时执行。

Zuul 过滤器具有以下关键特性:

  1. Type(类型):pre,routing,post,error
  2. Execution Order(执行顺序):规定了过滤器的执行顺序,Order的值越小,越先执行。
  3. Criteria(标准):过滤器执行所需的条件。
  4. Action(行动): 如果符合执行条件,则执行Action(即逻辑代码)

四. Zuul的生命周期

Here Insert Picture Description
当一个客户端Request 请求进入 Zuul 网关服务时,

  1. 网关先进入"pre filter",进行一系列的验证、操作或者判断。
  2. 然后交给 “routing filter” 进行路由转发,转发到具体的服务实例进行逻辑处理、返回数据。
  3. 当具体的服务处理完后,最后有"post filter" 进行处理,处理完后将Response信息返回给客户端。
  4. 如果以上3步出现了异常,就会进入"error filter"的过滤器,"error filter"返回结果给请求客户端.
Published 33 original articles · won praise 42 · views 3155

Guess you like

Origin blog.csdn.net/weixin_40991408/article/details/103924214