Zuul之ZuulRoute学习

zuul学习一:spring cloud zuul的快速入门

ZuulRoute 是 ZuulProperties 的一个内部类

265

前提:通过这段代码来实现动态路由刷新

for (RespRouteDto respRouteDto : respRouteDtos) {
    routes.put(respRouteDto.getId(), new ZuulProperties.ZuulRoute(respRouteDto.getPath(), respRouteDto.getLocation()));
}

进入 ZuulRoute

public ZuulRoute(String path, String location) {
    this.id = this.extractId(path);
    this.path = path;
    this.setLocation(location);
}

setLocation()

public void setLocation(String location) {
    if (location == null || !location.startsWith("http:") && !location.startsWith("https:")) {
        this.serviceId = location;
    } else {
        this.url = location;
    }

}

发现上面的代码 serviceId 的值为location

总结: 其实上面的代码是通过编码的形式配置 路径服务实例名 的映射关系

ext:通过配置文件的方式配置映射关系

zuul:
  routes:
    user-service:
      path: /users/**
      serviceId: user-service

当访问路径 /user/** 时,即访问 user-service 的服务接口

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值