1、首先了解個東西ServerWebExchange(服務網絡交換器)
ServerWebExchange存儲了當前請求得上下文,包括Request和Response 對象,並公開額外的 服務器 端處理相關屬性和特性,如請求屬性以下爲實現類
DefaultServerWebExchange
DefaultServerRequestBuilder 內部類DelegatingServerWebExchange 實現該接口
MockServerWebExchange
DefaultServerWebExchangeBuilder 內部類MutativeDecorator 實現該接口
ServerWebExchangeDecorator
2、RouteDefinitionLocator 路由定位器
org.springframework.cloud.gateway.route.RouteDefinitionLocator ,路由定義定位器接口,只有一個方法,用來獲取路由定義列表的方法。
public interface RouteDefinitionLocator {
Flux<RouteDefinition> getRouteDefinitions();
}
實現類
- PropertiesRouteDefinitionLocator:基於屬性配置:從配置文件讀取路由配置信息
- DiscoveryClientRouteDefinitionLocator:基於服務發現:該類通過服務發現組件從註冊中心獲取服務信息,此時路由定義的源就是配置中心
- CompositeRouteDefinitionLocator:組合方式:組合方式路由定義定位器使用組合模式進行實現,組合多個 RouteDefinitionLocator 的實現,爲獲取路由定義信息 getRouteDefinitions 提供統一入口,組合的邏輯很簡單,通過傳入的路由定義定位器作爲代理,具體的路由定義實際上是由傳入的路由定義定位器產生。
- CachingRouteDefinitionLocator:緩存方式:緩存方式的路由定義定位器,通過傳入路由定義定位器獲取路由定義並緩存到本地。通過監聽路由刷新時間RefreshRoutesEvent 來刷新本地緩存的路由定義信息
擴展接口
RouteDefinitionRepositor 保存或刪除路由 實現類 InMemoryRouteDefinitionRepository
3、路由謂詞工廠 RoutePredicateFactory(這個理解爲路由過濾工廠更合適)
- AbstractRoutePredicateFactory<C> 抽象實現類
- AfterRoutePredicateFactory 請求時間在指定時間點之後
- BeforeRoutePredicateFactory 請求時間在指定時間點之前
- BetweenRoutePredicateFactory 請求時間在指定時間段之間
- CloudFoundryRouteServiceRoutePredicateFactory 請求頭包含指定屬性
- CookieRoutePredicateFactory 請求cookie正則匹配
- HeaderRoutePredicateFactory 請求頭屬性正則匹配
- HostRoutePredicateFactory 請求host匹配指定值
- MethodRoutePredicateFactory 請求方法匹配指定值
- PathRoutePredicateFactory 請求路徑正則匹配
- QueryRoutePredicateFactory 請求參數正則匹配
- ReadBodyPredicateFactory 異步body緩存匹配(註釋說得意思大概是對body進行緩存然後無需進行多次讀取)
- RemoteAddrRoutePredicateFactory 遠程地址匹配指定值
- WeightRoutePredicateFactory 根據路由組和指定權重進行匹配