日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring Cloud入门+深入(十二)-Gateway网关(一)

發(fā)布時間:2023/12/20 javascript 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring Cloud入门+深入(十二)-Gateway网关(一) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一、Gateway網(wǎng)關(guān)

1、簡介

上一代zuul 1.X??zuul官網(wǎng)

Spring Cloud Gateway官網(wǎng)

Spring Cloud 自己研發(fā)了一個網(wǎng)關(guān),替換zuul,就是Spring Cloud Gateway

Gateway是在Spring生態(tài)系統(tǒng)之上構(gòu)建的API網(wǎng)關(guān)服務(wù),基于Spring 5,Spring Boot 2 和Project Reactor等技術(shù)。Gateway旨在提供一種簡單而有效的方式來對API進(jìn)行路由,以及提供一些強(qiáng)大的過濾器功能,例如:熔斷、限流、重試等。

Spring Cloud Gateway 是Spring的一個全新項目,基于Spring 5.0+Spring Boot 2.0和Project Reactor等技術(shù)開發(fā)的網(wǎng)關(guān),它旨在微服務(wù)架構(gòu)提供一種簡單有效的統(tǒng)一的API路由管理方式。

Spring Cloud Gateway作為 Spring Cloud生態(tài)系統(tǒng)中的網(wǎng)關(guān),目標(biāo)是代替Zuul,在Spring Boot 2.0以上版本中,沒有對新版本的Zuul2.0以上最新高性能版本進(jìn)行集成,仍然還是使用Zuul 1.x非Reactor模式的老版本。而為了提升網(wǎng)關(guān)的性能,SpringCloud Gateway是基于WebFlux框架實(shí)現(xiàn)的,而WebFlux框架底層則使用了高性能的Reactor模式通信框架Netty。

Spring Cloud Gateway的目標(biāo)提供統(tǒng)一的路由方式且基于Filter鏈的方式提供了網(wǎng)關(guān)基本的功能,例如:安全,監(jiān)控/指標(biāo),和限流。

總結(jié):Spring Cloud Gateway 使用的Webflux中的reactor-netty響應(yīng)式編程組件,底層使用了Netty通訊框架。

Spring Cloud Gateway在架構(gòu)圖中的位置

?2、作用

反向代理

流量控制

熔斷

日志監(jiān)控

3、為什么選擇Gatway?

1.zuul2.0遲遲未發(fā)布。Gatway是基于異步非阻塞模型上進(jìn)行開發(fā)的,性能方面不需要擔(dān)心。

2.SpringCloud Gateway具有如下特性:

? ? ? ? 基于Spring Framework 5,Project Reactor 和 Spring Boot 2.0進(jìn)行構(gòu)建。

? ? ? ? 動態(tài)路由:能夠匹配任何請求屬性。

? ? ? ? 可以對路由指定Predicate(斷言)和Filter(過濾器)。

? ? ? ? 集成Hystrix的斷路器功能。

? ? ? ? 集成Spring Cloud服務(wù)發(fā)現(xiàn)功能。

????????易于編寫的Predicate(斷言)和Filter(過濾器)。

????????請求限流功能。

? ? ? ? 支持路徑重寫

3.SpringCloud Gateway與Zuul的區(qū)別

????????1、Zuul 1.x是一個基于阻塞I/O的API Gateway

? ? ? ? 2、Zuul 1.x基于Servlet2.5使用阻塞架構(gòu)它不支持任何長連接(如WebSocket)Zuul的設(shè)計模式和Nginx較像,每次I/O操作都是從工作線程中選擇一個執(zhí)行,請求線程被阻塞到工作線程完成,但是差別是Nginx用C++實(shí)現(xiàn),Zuul用Java實(shí)現(xiàn),而JVM本身會有第一次加載較慢的情況,使用Zuul的性能相對較差。

? ? ? ? 3、Zuul2.x理念更先進(jìn),想基于Netty非阻塞和支持長連接,但是SpringCloud目前沒有整合。

? ? ? ? 4、SpringCloud Gateway建立Spring Framework 5,Project Reactor 和 Spring Boot 2.0之上,使用非阻塞API。

? ? ? ? 5、SpringCloud Gateway還支持WebSocket,并且與Spring緊密集成擁有更好的開發(fā)體驗。

二、Spring WebFlux

reactive

?Spring WebFlux

1. Spring WebFlux The original web framework included in the Spring Framework, Spring Web MVC, was purpose- built for the Servlet API and Servlet containers. The reactive-stack web framework, Spring WebFlux, was added later in version 5.0. It is fully non-blocking, supports Reactive Streams back pressure, and runs on such servers as Netty, Undertow, and Servlet 3.1+ containers.Both web frameworks mirror the names of their source modules (spring-webmvc and spring- webflux) and co-exist side by side in the Spring Framework. Each module is optional. Applications can use one or the other module or, in some cases, both?—?for example, Spring MVC controllers with the reactive WebClient.

傳統(tǒng)的Web框架,比如說:struts2,springmvc等都是基于Servlet API與Servlet容器基礎(chǔ)之上運(yùn)行的。

在Servlet3.1之后有了異步非阻塞的支持。而WebFlux是一個典型非阻塞異步的框架,它的核心是基于Reactor的相關(guān)API實(shí)現(xiàn)的。相對于傳統(tǒng)的Web框架,它可以運(yùn)行在諸如Netty,Undertow及支持Servlet3.1的容器上。非阻塞式+函數(shù)式編程(Spring5必須讓你使用java8).

?

Spring Cloud入門+深入(一)

Spring Cloud入門+深入(十三)-Gateway網(wǎng)關(guān)(二)

總結(jié)

以上是生活随笔為你收集整理的Spring Cloud入门+深入(十二)-Gateway网关(一)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。