在使用Spring Cloud Gateway過程當中,但願配置多Routes映射不一樣的微服務,由於Gateway 和Zuul的訪問路徑不一樣(zuul 會帶有服務service Id),形成錯誤。微服務
routes: - id: after_route uri: lb://user-center predicates: # 噹噹前時間晚於設置時間以後,才能訪問 # 不然獲得404錯誤 #- After=2010-01-01T18:00:00.789-07:00[America/Denver] # 當Host屬於**.geekplus.com.cn或**.life-runner.com時 # http://localhost:9999/** -> user-center/** # eg. http://localhost:9999/users/1 -> user-center/users/1 #- Host=**.geekplus.com.cn,**.life-runner.com - TimeBetween=上午6:00,下午11:00 - Path=/users/** filters: - AddRequestHeader=CompanyKey,123456 - AddResponseHeader=Success,Isaac - PreLog=CustomLogKey,CustomLogValue - id: content_route uri: lb://shared-center - After=2010-01-01T18:00:00.789-07:00[America/Denver] - Path=/share/** filters: - AddRequestHeader=CompanyKey,123456 - AddResponseHeader=Success,Isaac - PreLog=CustomLogKey,CustomLogValue
routes: - id: content_route uri: lb://shared-center predicates: - Path=/share/** - id: after_route uri: lb://user-center predicates: # 噹噹前時間晚於設置時間以後,才能訪問 - TimeBetween=上午6:00,下午11:00 - Path=/users/** filters: - AddRequestHeader=CompanyKey,123456 - AddResponseHeader=Success,Isaac - PreLog=CustomLogKey,CustomLogValue
四處尋求幫助,無奈,Gateway的資料網上真的不多。仍是自食其力吧,根據錯誤信息,查看Nacos中元數據,發現異常!code
解決方法,重啓shared-center,從新獲取實例Ip,結果恢復正常!blog
Tipsip
我使用的是Spring Cloud Alibaba Nacos做爲服務發現中心,在重啓內容服務以後,發現中心的失敗IPservice並無被刷新,須要手動處理一下,不然依舊會調用到老的IP。class