Springcloud gateway uses Gateway Routing


Route forwarding and filtering of gateway

Configure in a gateway project (configured with Eureka and other components)

  port: 9006
    name: zhao-service-gateway
       - id: service-autodeliver-router
         uri: lb://zhao-service-autodeliver
          - Path= /autodeliver/**
       - id: service-resume-router
         uri: lb://zhao-service-resume
           - Path=/resume/**
           - StripPrefix=1

Through the configuration of the first service, Hao service autodelivery, you can normally access the service through the gateway project by using the fixed IP and service name. However, the method of fixed IP is not very flexible. Lb://zhao-service-autodelivery can realize random load balancing, and you do not need to fill in the fixed IP to avoid unnecessary trouble

Springcloud gateway uses Gateway Routing

In the second service configuration, filters:- stripprefix=1 will filter out the first path configuration. Therefore, in addition to the first filtered configuration, we also need to add the original configuration in the final access. The access form is as follows

Springcloud gateway uses Gateway Routing

Gateway assertion

The above configuration for paths is the configuration of assertion predictions, and the gateway also has the following built-in assertions

Springcloud gateway uses Gateway Routing

Basically, the above assertions are filtered based on the information carried by the request. In the actual operation process, these information can be comprehensively used to achieve the desired operation

Gateway custom global filter

//fhadmin. cn

The filter intercepts the requests in the blacklist (in practice, this operation can be realized with the help of MySQL or redis and other data stores) to achieve the effect

Springcloud gateway uses Gateway Routing

High availability of gateway

As a component of the “normal core”, if the connection fails, all requests may be routed. Therefore, we need to do the “passable” of the gateway. Gateway scalability is very simple: you can start multiple gateway instances to achieve scalability, and enable load balancing devices such as nginx to perform load forwarding upstream of gateway to achieve scalability. Start multiple gateway instances (say two, ⼀ end ⼝ 9002, ⼀ end ⼝ 9003), and the rest is to make ⽤ nginx and others complete the load agent.

This work adoptsCC agreement, reprint must indicate the author and the link to this article