javascript
微服务网关之Springcloud GateWay
簡介
由于有如此眾多的客戶端和服務器,在云體系結構中包括一個API網關通常會很有幫助。網關可以負責保護和路由消息,隱藏服務,限制負載以及許多其他有用的事情。Spring Cloud Gateway為您提供對API層的精確控制,集成了Spring Cloud服務發現和客戶端負載平衡解決方案,以簡化配置和維護。
SpringCloud Gateway 是Spring cloud的一個全新的項目,基于Spring Framework 5,Project Reactor和Spring Boot 2.0等技術開發的網關,它旨在為為微服務架構提供簡單有效的統一的API路由管理方式。
SpringCloud Gateway作為Spring cloud 生態系統中的網關,目標是替代zuul,在Springcloud2.0以上的版本中,沒有對新版本的zuul2.0一盒收納柜最新高性能版本進行集成,仍然還是使用的是Zuul1.x非Reactor模式的老版本。而為了提升網關的性能,SpringCloud Gateway 是基于WebFlux框架實現的,而WebFlux框架使用了高性能的Reactor模式通信框架Netty。
Spring Cloud Gateway的目標提供統一的路由方式且基于Filter鏈的方式提供網關的基本功能,例如:安全,監控/指標,和限流。
Spring Cloud架構亮點
[外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-ISvGGIqG-1625737431421)(https://spring.io/images/cloud-diagram-1a4cad7294b4452864b5ff57175dd983.svg)]
特征
Spring Cloud Gateway功能:
- 基于Spring Framework 5,Project Reactor和Spring Boot 2.0構建
- 能夠匹配任何請求屬性上的路由。
- 謂詞和過濾器特定于路由。
- Hystrix斷路器集成。
- Spring Cloud DiscoveryClient集成
- 易于編寫的謂詞和過濾器
- 請求速率限制
- 路徑改寫
三大核心概念
Route( 路由)
路由是構建網關的基本模塊,它由ID,目標URI,一系列的斷言和過濾器組成,如果斷言為true則匹配該路由。Predicate(斷言)
開發人員可以匹配HTTP請求中的所有內容(例如請求頭或請求參數),如果請求與斷言相匹配則進行路由。Filter(過濾)
值得是Spring框架中GatewayFilter的實例,使用過濾器,可以在請求被路由前或者之后對請求進行修改。工作流程
Clients make requests to Spring Cloud Gateway. If the Gateway Handler Mapping determines that a request matches a route, it is sent to the Gateway Web Handler. This handler runs the request through a filter chain that is specific to the request. The reason the filters are divided by the dotted line is that filters can run logic both before and after the proxy request is sent. All “pre” filter logic is executed. Then the proxy request is made. After the proxy request is made, the “post” filter logic is run.總結
以上是生活随笔為你收集整理的微服务网关之Springcloud GateWay的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2008年8月26号,星期二,晴。欲穷千
- 下一篇: Unity3D学习之射箭小游戏