Soul网关源码分析-http后台应用启动自动注册拦截规则信息到soul-admin

本文分析了soul-examples-http如何在启动时将URL拦截规则注册到soul-admin。通过源码调试,揭示了配置加载、启动过程以及注册逻辑,涉及SoulSpringMvcClient、soul-http配置、SpringMvcClientBeanPostProcessor等关键类。最终确认,应用通过OkHttpClient向soul-admin发送注册请求。
摘要由CSDN通过智能技术生成

按照计划,今天要从源码的角度分析soul是如何处理浏览器请求并找到真正要访问的后台服务,但计划赶不上变化,作为一名超级奶爸,只有深夜的时间真正属于自己,无法按计划完成今天任务了,但是还是坚持每天有所产出,那么今晚分析soul源码得到的结果是终于弄清楚了接入soul的springBoot应用启动时是如何将url的拦截规则信息注册到soul-admin管理控制台的。

首先将今天分析源码带着的问题先抛出来,我们在上一篇中就以使用者的角度体验了http请求通过soul成功转发到了后台,在后台工程soul-examples-http启动时,是会有以下日志信息的:

2021-01-16 23:52:16.861  INFO 49500 --- [pool-1-thread-1] o.d.s.client.common.utils.RegisterUtils  : http client register success: {"appName":"http","context":"/http","path":"/http/test/**","pathDesc":"","rpcType":"http","host":"192.168.137.1","port":8188,"ruleName":"/http/test/**","enabled":true,"registerMetaData":false} 
2021-01-16 23:52:31.083  INFO 49500 --- [pool-1-thread-1] o.d.s.client.common.utils.RegisterUtils  : http client register success: {"appName":"http","context":"/http","path":"/http/order/save","pathDesc":"Save order","rpcType":"http","host":"192.168.137.1","port":8188,"ruleName":"/http/order/save","enabled":true,"registerMetaData":false} 
2021-01-16 23:52:39.780  INFO 49500 --- [pool-1-thread-1] o.d.s.client.common.utils.RegisterUtils  : http client register success: {"appName":"http","context":"/http","path":"/http/order/findById","pathDesc":"Find by id","rpcType":"http","host":"192.168.137.1","port":8188,"ruleName":"/http/order/findById","enabled":true,"registerMetaData":false} 
2021-01-16 23:52:50.768  INFO 49500 --- [pool-1-thread-1] o.d.s.client.common.utils.RegisterUtils  : http client register success: {"appName":"http","context":"/http","path":"/http/order/path/**","pathDesc":"","rpcType":"http","host":"192.168.137.1","port":8188,"ruleName":"/http/order/path/**","enabled":true,"registerMetaData":false} 
2021-01-16 23:52:59.528  INFO 49500 --- [pool-1-thread-1] o.d.s.client.common.utils.RegisterUtils  : http client register success: {"appName":"http","context":"/http","path":"/http/order/path/**/name","pathDesc":"","rpcType":"http","host":"192.168.137.1","port":8188,"ruleName":"/http/order/path/**/name","enabled":true,"registerMetaData":false}

这里打印出来的日志信息,实际上是后台工程在启动时,将提供服务的url的相对路径的拦截规则注册到了soul-admin中,此举的目的是为了让请求通过soul处理时,能灵活的根据soul-admin中对单个接口或者所有接口的请求做灵活处理,包括限制访问,在集群环境下通过加权以及指定ip访问等方式控制此请求是否能到达对应的后台服务或者指定到达某个后台服务,可以看到,上述日志信息和在soul-admin首页的divide插件看到的选择器规则是一致的,如下图所示:
选择器规则
那么带着这个问题,我Debug了一波源码,得出了以下结论,我画了一个流程图描述,如下所示:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值