mvn spring-boot:run动态路由的存储中间件有很多,可以选择单机的ConcurrentHashMap,可以选择分布式存储中间件,如etcd、consul、zk和redis等
都可以直接通过继承 AbstractDynamicRouter 实现对应方法来实现动态路由
实现可见 ConcurrentHashMapDynamicRouter
- 使用etcd的实现,需要先安装etcd
# 下面的mac的安装方式,其他的也可以参考文档 https://github.com/etcd-io/etcd/releases
brew install etcd- 启动etcd
etcd --advertise-client-urls 'http://0.0.0.0:2379' \
     --listen-client-urls 'http://0.0.0.0:2379'etcdctl put foo bar
etcdctl get foo - 启动动态代理
# 修改配置文件中router.type类型为etcd再启动
mvn spring-boot:run可以通过接口操作路由,达到动态代理路由的功能
- 增加route
curl -X POST http://localhost/api/route \
     -H "Content-Type: application/json" \
     -d @route.json- 删除route
curl -X DELETE http://localhost/api/route \
     -H "Content-Type: application/json" \
     -d @route.json- 查看所有route信息
curl -X GET http://localhost/api/route 
curl -X GET http://localhost:81/api/route - 删除所有route信息
curl -X DELETE http://localhost/api/route/clearAll