松江泗泾网站建设,国外有建站公司吗,快速seo关键词优化技巧,看啥网一个没有人工干预的网灰度实体类 Datapublic static class NewSwitch{//是否开启灰度#xff0c;true是#xff0c;false否Boolean enable;//灰度基数#xff0c;-1的时候默认为全部开启灰度Long divisor;//灰度比例 参数对divisor取余小于等于mod命中灰度Long mod;//白名单#xff0c;优先判断…灰度实体类 Datapublic static class NewSwitch{//是否开启灰度true是false否Boolean enable;//灰度基数-1的时候默认为全部开启灰度Long divisor;//灰度比例 参数对divisor取余小于等于mod命中灰度Long mod;//白名单优先判断白名单ListString whiteList;}
灰度配置
# 开关配置
switchConfig:orderSwitch:#是否开启灰度true是false否enable: true#灰度基数-1的时候默认为全部开启灰度divisor: 100#灰度比例 参数对divisor取余小于mod命中灰度mod: 1#白名单优先判断白名单whiteList:- 1- 2
配置类
Component
RefreshScope
Data
ConfigurationProperties(switch-config)
public class SwitchConfig {private NewSwitch orderSwitch;//适用于根据指定id或标识灰度白名单可以是用户id手机号啥的public boolean isNewSwitch(NewSwitch newSwitch, Long mod, String white) {if(newSwitchnull){return false;}if(!Boolean.TRUE.equals(newSwitch.enable)){return false;}if(newSwitch.divisor-1){return true;}if(!StringUtils.isEmpty(white)){if(newSwitch.whiteList.contains(white)){return true;}}if(newSwitch.divisor0){return false;}if(modnull){modgetRandomNumber(newSwitch.divisor.intValue());}Long resmod%newSwitch.divisor;if(resnewSwitch.mod){return true;}return false;}//适用于随机灰度 按配置的比例灰度public boolean isNewSwitch(NewSwitch newSwitch) {return isNewSwitch(newSwitch,null,null);}//适用于根据指定id或标识灰度public boolean isNewSwitch(NewSwitch newSwitch,Long mod) {return isNewSwitch(newSwitch,mod,null);}//有需要可以再加个白名单灰度Datapublic static class NewSwitch{//是否开启灰度true是false否Boolean enable;//灰度基数-1的时候默认为全部开启灰度Long divisor;//灰度比例 参数对divisor取余小于等于mod命中灰度Long mod;//白名单优先判断白名单ListString whiteList;}
}
灰度使用
public class OrderTest {Autowiredprivate SwitchConfig switchConfig;public void switchTest { if(switchConfig.isNewSwitch(switchConfig.getOrderToHtapSwitch())){//todo new}else{//todo old}}