Skip to content

Latest commit

 

History

History

spring-cloud-gateway

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Purpose

演示Spring Cloud Gateway如何通过Apollo配置中心实现动态路由

Instructions

  1. 在Apollo配置中心创建AppId为spring-cloud-Gateway的项目

  2. 在默认的application下做如下配置(可以通过文本模式直接复制、粘贴下面的内容):

    server.port = 9090
    spring.cloud.gateway.routes[0].id = github_route
    spring.cloud.gateway.routes[0].uri = https://github.com/
    #spring.cloud.gateway.routes[0].uri = https://github.com/ctripcorp/apollo
    spring.cloud.gateway.routes[0].predicates[0] = Path=/**
  3. 运行com.ctrip.framework.apollo.use.cases.spring.cloud.gateway.SpringCloudGatewayApplication启动Demo

  4. 打开http://localhost:9090,显式内容为GitHub首页

  5. 在Apollo配置中心修改配置,把spring.cloud.gateway.routes[0].uri的值改为https://github.com/ctripcorp/apollo并发布配置

  • 可以以文本模式在原来生效的spring.cloud.gateway.routes[0].uri前面加上#注释掉,同时把原来注释掉的指向https://github.com/ctripcorp/apollo的配置反注释掉来快速修改
  1. 刷新http://localhost:9090页面,显式的内容会变成Apollo配置中心的GitHub首页,说明动态路由生效了
  2. 如果浏览器缓存影响测试,可以配置actuator使用org.springframework.cloud.gateway.actuate.GatewayControllerEndpoint提供的端点查看路由配置