为了账号安全,请及时绑定邮箱和手机立即绑定

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

标签:
Spring Cloud

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

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

我们知道,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 可进一步简化我们的调试与排错。


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消