當前位置:編程學習大全網 - 源碼下載 - Gateway動態路由實現

Gateway動態路由實現

無論是哪壹種,在啟動網關後將無法修改路由配置,如有新服務要上線,則需要先把網關下線,修改 yml 配置後,再重啟網關。

Gateway網關啟動時,路由信息默認會加載內存中,路由信息被封裝到 RouteDefinition 對象中,配置多個RouteDefinition組成Gateway的路由系統。

*RouteDefinitionLocator是個接口,在org.springframework.cloud.gateway.route包下,如果想查看網關中所有的路由信息,可以調用此方法;後面還有另外壹種查看方式,是Spring Cloud Gateway 的Endpoint端點提供的方法

Endpoint 端點有暴露路由信息、獲取所有路由、刷新路由、查看單個路由、刪除路由等方法,源碼在 org.springframework.cloud.gateway.actuate.GatewayControllerEndpoint 中,訪問端點中的方法需要修改pom和配置文件:

*添加pom文件依賴:

*yml配置

準備:

* Spring Cloud:Greenwich.SR1

* Spring Boot: 2.1.1.RELEASE

* 註冊中心(Consul)

* 網關Gateway

* 業務服務(ijep-service-sys)

*過濾器模型

*路由斷言模型

*路由模型

查詢所有的路由地址信息,訪問地址: http://localhost:9000/actuator/gateway/routes

項目地址: 無權訪問

  • 上一篇:CMS日誌分析
  • 下一篇:熱門白馬選股思路?
  • copyright 2024編程學習大全網