springcloud-gateway的spi加载SlotChainBuilder问题 #2180
Labels
area/gateway-flow-control
Issues or PRs related to API gateway flow control
duplicate
This issue or pull request already exists
问题描述:
使用springcloud-gateway+sentinel,引入
发现两者顺序对调,会影响网关流控是否生效,sentinel-spring-cloud-gateway-adapter在前会生效,在后则不会生效,经过分析源码,是由于两者都引入了
flow-control的SlotChainBuilder的spi是
com.alibaba.csp.sentinel.slots.HotParamSlotChainBuilder
而gateway-adapter的SlotChainBuilder的spi是
com.alibaba.csp.sentinel.adapter.gateway.common.slot.GatewaySlotChainBuilder
,两者差了关键的:继续分析,发现原因是
使用了SpiLoader.loadFirstInstanceOrDefault方法,所以获取到第一个非default的builder时就直接返回了,如果gateway-adapter在后面,则GatewaySlotChainBuilder不会被加载到,这里的加载方式改用SpiLoader.loadHighestPriorityInstance并且设置Builder的优先级会好点
The text was updated successfully, but these errors were encountered: