GateWay路由規(guī)則與動(dòng)態(tài)路由詳細(xì)介紹
1、路由規(guī)則
Spring Cloud GateWay 幫我們內(nèi)置了很多 Predicates功能,實(shí)現(xiàn)了各種路由匹配規(guī)則(通過(guò) Header、請(qǐng)求參數(shù)等作為條件)匹配到對(duì)應(yīng)的路由。
時(shí)間點(diǎn)后匹配
spring:
cloud:
gateway:
routes:
- id: after_route
uri: https://example.org
predicates:
- After=2017-01-20T17:42:47.789-07:00[America/Denver]
時(shí)間點(diǎn)前匹配
spring:
cloud:
gateway:
routes:
- id: before_route
uri: https://example.org
predicates:
- Before=2017-01-20T17:42:47.789-07:00[America/Denver]
時(shí)間區(qū)間匹配
spring:
cloud:
gateway:
routes:
- id: between_route
uri: https://example.org
predicates:
- Between=2017-01-20T17:42:47.789-07:00[America/Denver],2017-01-21T17:42:47.789-07:00[America/Denver]
指定Cookie正則匹配指定值
spring:
cloud:
gateway:
routes:
- id: cookie_route
uri: https://example.org
predicates:
- Cookie=chocolate, ch.p
指定Header正則匹配指定值
spring:
cloud:
gateway:
routes:
- id: header_route
uri: https://example.org
predicates:
- Header=X-Request-Id, \d+
請(qǐng)求Host匹配指定值
spring:
cloud:
gateway:
routes:
- id: host_route
uri: https://example.org
predicates:
- Host=**.somehost.org,**.anotherhost.org
請(qǐng)求Method匹配指定請(qǐng)求方式
spring:
cloud:
gateway:
routes:
- id: method_route
uri: https://example.org
predicates:
- Method=GET,POST
請(qǐng)求路徑正則匹配
spring:
cloud:
gateway:
routes:
- id: path_route
uri: https://example.org
predicates:
- Path=/red/{segment},/blue/{segment}
請(qǐng)求包含某參數(shù)
spring:
cloud:
gateway:
routes:
- id: query_route
uri: https://example.org
predicates:
- Query=green
請(qǐng)求包含某參數(shù)并且參數(shù)值匹配正則表達(dá)式
spring:
cloud:
gateway:
routes:
- id: query_route
uri: https://example.org
predicates:
- Query=red, gree.
遠(yuǎn)程地址匹配
spring:
cloud:
gateway:
routes:
- id: remoteaddr_route
uri: https://example.org
predicates:
- RemoteAddr=192.168.1.1/24
2、動(dòng)態(tài)路由
GateWay支持自動(dòng)從注冊(cè)中心中獲取服務(wù)列表并訪(fǎng)問(wèn),即所謂的動(dòng)態(tài)路由
實(shí)現(xiàn)步驟如下
- pom.xml中添加注冊(cè)中心客戶(hù)端依賴(lài)(因?yàn)橐@取注冊(cè)中心服務(wù)列表,eureka客戶(hù)端已經(jīng)引入)
- 動(dòng)態(tài)路由配置
注意:動(dòng)態(tài)路由設(shè)置時(shí),uri以 lb: //開(kāi)頭(lb代表從注冊(cè)中心獲取服務(wù)),后面是需要轉(zhuǎn)發(fā)到的服務(wù)名稱(chēng)
到此這篇關(guān)于GateWay路由規(guī)則與動(dòng)態(tài)路由詳細(xì)介紹的文章就介紹到這了,更多相關(guān)GateWay路由規(guī)則內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Spring?Cloud?Gateway動(dòng)態(tài)路由Apollo實(shí)現(xiàn)詳解
- SpringCloud Gateway使用redis實(shí)現(xiàn)動(dòng)態(tài)路由的方法
- Spring Cloud Gateway + Nacos 實(shí)現(xiàn)動(dòng)態(tài)路由
- SpringCloud?Gateway詳細(xì)分析實(shí)現(xiàn)負(fù)載均衡與熔斷和限流
- springcloud gateway如何實(shí)現(xiàn)路由和負(fù)載均衡
- GateWay動(dòng)態(tài)路由與負(fù)載均衡詳細(xì)介紹
相關(guān)文章
如何用Springboot Admin監(jiān)控你的微服務(wù)應(yīng)用
這篇文章主要介紹了如何用Springboot Admin監(jiān)控你的微服務(wù)應(yīng)用,幫助大家更好的理解和使用springboot框架,感興趣的朋友可以了解下。2021-01-01詳解使用SSM實(shí)現(xiàn)簡(jiǎn)單工作流系統(tǒng)之實(shí)現(xiàn)篇
這篇文章主要介紹了使用SSM實(shí)現(xiàn)簡(jiǎn)單工作流系統(tǒng)之實(shí)現(xiàn)篇,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-12-12Java中時(shí)間戳的獲取和轉(zhuǎn)換的示例分析
這篇文章主要介紹了Java中時(shí)間戳的獲取和轉(zhuǎn)換的示例分析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07Mybatis之Select Count(*)的獲取返回int的值操作
這篇文章主要介紹了Mybatis之Select Count(*)的獲取返回int的值操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-11-11Java實(shí)現(xiàn)HTTP請(qǐng)求的4種方式總結(jié)
這篇文章主要給大家介紹了關(guān)于Java實(shí)現(xiàn)HTTP請(qǐng)求的4種方式,在java開(kāi)發(fā)中,經(jīng)常遇到需要調(diào)用第三方提供的接口服務(wù)的需求,文中給出了詳細(xì)的代碼示例,需要的朋友可以參考下2023-08-08Spring?Boot?配置?Hikari?數(shù)據(jù)庫(kù)連接池的操作代碼
數(shù)據(jù)庫(kù)連接池是一個(gè)提高程序與數(shù)據(jù)庫(kù)的連接的優(yōu)化,連接池它主要作用是提高性能、節(jié)省資源、控制連接數(shù)、連接管理等操作,這篇文章主要介紹了SpringBoot配置Hikari數(shù)據(jù)庫(kù)連接池,需要的朋友可以參考下2023-09-09