Fork me on GitHub

Spring Cloud Edgware新特性之四:Zuul routes端点功能增强

Spring Cloud是当前炙手可热的微服务开发框架。它的功能强大,组件丰富,设计优雅。目前Spring Cloud还在不断发展之中。

Spring Cloud即将发布Spring Cloud Edgware 版本。该版本解决了不少Bug,新增了不少新特性,本系列博客将为大家详细阐述在Spring Cloud Edgware中新增的特性。

我们知道,Zuul有一个非常实用的 /routes 端点。访问 $ZUUL_URL/routes 即可查看当前Zuul的路由规则,从而在很多情况下能够帮助我们定位Zuul的问题——当Zuul没有按照我们的计划去转发请求时,/routes 就会很有用,可通过该端点查看Zuul转发的规则。访问结果类似如下:

1
2
3
4
{
/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=details 来查看更多详情。访问后,将会展示类似如下的结果:

1
2
3
4
5
6
7
8
9
10
11
12
{
"/sample-service/**": {
"id": "sample-service",
"fullPath": "/sample-service/**",
"location": "sample-service",
"path": "/**",
"prefix": "/sample-service",
"retryable": false,
"customSensitiveHeaders": false,
"prefixStripped": true
}
}

由结果可知,此时Zuul为我们展示了很多有用的信息,例如:转发到了那个地址、是否重试等。使用/routes?format=details 可进一步简化我们的调试与排错。

相关文章

评论系统未开启,无法评论!