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

相关文章
相关标签/搜索