Spring Cloud Edgware新特性之四:Zuul routes端點功能加強

Spring Cloud是當前煊赫一時的微服務開發框架。它的功能強大,組件豐富,設計優雅。目前Spring Cloud還在不斷髮展之中。html

Spring Cloud即將發佈Spring Cloud Edgware 版本。該版本解決了很多Bug,新增了很多新特性,本系列博客將爲你們詳細闡述在Spring Cloud Edgware中新增的特性。spring

咱們知道,Zuul有一個很是實用的 /routes 端點。訪問 $ZUUL_URL/routes 便可查看當前Zuul的路由規則,從而在不少狀況下可以幫助咱們定位Zuul的問題——當Zuul沒有按照咱們的計劃去轉發請求時,/routes 就會頗有用,可經過該端點查看Zuul轉發的規則。訪問結果相似以下:微信

{
    /sample-service/**: "sample-service"
}
// 這段JSON表示:若是請求$ZUUL_URL/sample-service/**,Zuul會將請求轉發到註冊在Eureka Server上的sample-service服務的/**。

TIPS:使用routes 端點的前提:框架

  1. Zuul Server須要有Spring Boot Actuator的依賴,不然訪問/routes 端點將會返回404;。
  2. 設置management.security.enabled = false ,不然將會返回401;也可添加Spring Security的依賴,這樣可經過帳號、密碼訪問routes 端點。

/routes 端點相關文檔,可詳見http://cloud.spring.io/spring-cloud-static/Dalston.SR4/single/spring-cloud.html#_the_routes_endpoint微服務

在Spring Cloud Edgware 中,Spring Cloud對該端點進行了加強。咱們可經過/routes?format=detail 來查看更多詳情。訪問後,將會展現相似以下的結果:設計

{
  "/sample-service/**": {
    "id": "sample-service",
    "fullPath": "/sample-service/**",
    "location": "sample-service",
    "path": "/**",
    "prefix": "/sample-service",
    "retryable": false,
    "customSensitiveHeaders": false,
    "prefixStripped": true
  }
}

有結果可知,此時Zuul爲咱們展現了不少有用的信息,例如:轉發到了那個地址、是否重試等。使用/routes?format=detail 可進一步簡化咱們的調試與排錯。調試

本文連接: http://www.itmuch.com/spring-cloud/edgware-zuul-routes-endpoint/ 版權聲明: 本博客由周立創做,採用 CC BY 3.0 CN 許可協議。可自由轉載、引用,但需署名做者且註明文章出處。如轉載至微信公衆號,請在文末添加做者公衆號二維碼。code

相關文章
相關標籤/搜索