Gateway simple concept

. 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. Gateway

Spring Cloud Gateway as Spring Cloud ecosystem gateway, the goal is to replace Netflix Zuul, which not only provides a unified routing, and provides the basic functions of gateway-based approach Filter chain, such as: security, monitoring / indicators, and current limit .

Related concepts:

  1. The Route (route): This is the basic building block of the gateway. It is defined by an ID, a target URI, a set of assertions and a set of filters. If the assertion is true, the route matches.
  2. Predicate (assertion): This is the interface of a Java 8. The interface accepts one input parameter and returns a boolean result. We can use it to match any of the content from the HTTP request, such as headers or parameters.
  3. Filter (filter): This is an example org.springframework.cloud.gateway.filter.GatewayFilter, we can use it to modify requests and responses.

work process:

Here Insert Picture Description
As shown above:
The client sends a request to Spring Cloud Gateway. First, the request to the Gateway Handler Mapping process, if it finds the request matches the route (this time will be used to assert), it is sent to the Gateway Web Handler process. Handler then through the specified filter chain to send a request to the service we actually execute business logic and then returns.

Separated by a dashed line between the filter because the filter may be ( "pre") or after ( "post") execute business logic before sending a proxy request.

In the implementation of all of the "pre" filter logic, general permission may be achieved, the current limit, the log output, change request header and protocol conversion functions.

After receiving the response, performs all of the "post" logical filter, here with the response data can be modified, such as replacing response headers and protocol conversion.

Gateway Services Gateway built-in assertions

In the Spring Spring Cloud Gateway Predicate achieved using various properties of the matching routing rules, there by Header, different conditions requested parameters to be matched as a condition corresponding routing. Internet has achieved a figure summarizes the Spring Cloud built of several Predicate.
Here Insert Picture Description

Published 33 original articles · won praise 42 · views 3134

Guess you like

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