Spring Cloud 執行器API是通過Actuator自定義控制器端點,他可以在網關已經啟動的時候對網關的路徑進行增删改操作。
gateway 端點允許和Spring Cloud 網關互動,但是必須需要公開端點;
使用Spring Cloud Gateway 需要注意的地方:
Spring Cloud Gateway是基于Spring Boot 2.x, Spring WebFlux和Project Reactor 建構的。是以,在使用Spring Cloud Gateway時,許多不熟悉的同步庫(例如,Spring Data和Spring Security)和模式可能不适用。** Spring Cloud Gateway需要Spring Boot和Spring Webflux提供的Netty運作時。它不能在傳統的Servlet容器中或作為WAR建構。
一定要記住隻有Spring Boot2.0才支援!!
get方式的請求轉發到本地8081端口;
post的請求轉發到本地8083端口;
yml格式要注意别寫錯了,這裡推薦一個yml和properties進行轉換的網站。
https://www.toyaml.com/index.html
通過<code>GET</code>方式 請求<code>/actuator/gateway/routes</code> 進行檢索
路徑
類型
描述
<code>route_id</code>
String
路線編号。
<code>route_object.predicate</code>
Object
路由謂詞。
<code>route_object.filters</code>
Array
GatewayFilter工廠使用的路由。
<code>order</code>
Number
路線順序。
POST 通過<code>/gateway/routes/{id_route_to_create}</code>接口進行建立路由;
位址:<code>/actuator/gateway/routes/first_route</code>
例1:GET請求到本地8081端口
所有get請求轉發到http://localhost:8081這個位址上去;
<code>DELETE</code>方式請求<code>/actuator/gateway/routes/{id_route_to_create}</code>,即如上的<code>/actuator/gateway/routes/first_route</code>位址進行删除;
路由規則建立和删除之後不會立即生效,需要重新整理才可以生效;
POST請求<code>/actuator/gateway/refresh</code> 位址進行重新整理,該請求傳回200,但沒有響應主體。
ID
HTTP方法
<code>globalfilters</code>
GET
顯示應用于路由的全局過濾器清單。
<code>routefilters</code>
顯示應用于特定路由的GatewayFilter工廠清單。
<code>refresh</code>
POST
清除路由緩存。
<code>routes</code>
顯示網關中定義的路由清單。
<code>routes/{id}</code>
顯示有關特定路線的資訊。
将新路由添加到網關。
DELETE
從網關删除現有路由。