How does Spring Cloud Gateway work?
Spring Cloud Gateway is a library built on Spring 5.0, Spring Boot 2.0, and Project Reactor for constructing API gateways. It operates as follows:
- The client sends a request to Spring Cloud Gateway.
- Spring Cloud Gateway accepts requests and uses RouterLocator to find matching routing rules.
- According to the routing rules, Spring Cloud Gateway forwards requests to the target service using HTTP, WebSocket, or any other protocol.
- The target service processes the request and returns the response to Spring Cloud Gateway.
- Spring Cloud Gateway is sending the response back to the client.
The working principle of Spring Cloud Gateway is based on an asynchronous and non-blocking model, utilizing Reactor Netty from the Reactor project to achieve high-performance proxy and routing functions. It offers a set of filters that can modify and handle requests and responses, such as adding request headers, rate limiting, authentication, etc. Additionally, it supports dynamic routing, allowing for the dynamic modification of routing rules based on runtime conditions.