如果访问share/1和share/2
sentinel后台会出现两种资源名,为share/1设置流控规则不会影响到share/2,这是很致命的,我们不可能每一种资源都去做流控,sentinel控制台不支持占位符
UrlCleaner
package com.itmuch.usercenter.sentineltest; import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlCleaner; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.math.NumberUtils; import org.springframework.stereotype.Component; import java.util.Arrays; @Component @Slf4j public class MyUrlCleaner implements UrlCleaner { @Override public String clean(String s) { String[] split = s.split("/"); return Arrays.stream(split) .map(i->{ if (NumberUtils.isNumber(i)){ return "{number}"; } return i; }) .reduce((a,b)->a+'/'+b) .orElse(""); } }
该方法只是简单的将链接替换成占位符