Merge branch 'master' into eureka

eureka
tanghc 4 years ago
commit 7de5fe9ef2
  1. 1
      changelog.md
  2. 1
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/LimitFilter.java
  3. 17
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/DefaultLimitConfigManager.java

@ -6,6 +6,7 @@
- 优化异常处理 - 优化异常处理
- 优化网关多实例数据库重复保存问题 - 优化网关多实例数据库重复保存问题
- 修复`IP`,`IP+路由ID`,`IP+APP_ID`限流不生效问题
## 4.3.4 ## 4.3.4

@ -85,6 +85,7 @@ public class LimitFilter implements GlobalFilter, Ordered {
appKey, appKey,
routeId + appKey, routeId + appKey,
ip,
ip + routeId, ip + routeId,
ip + appKey, ip + appKey,
ip + routeId + appKey, ip + routeId + appKey,

@ -82,20 +82,25 @@ public class DefaultLimitConfigManager implements LimitConfigManager {
if (StringUtils.isNotBlank(routeId) && StringUtils.isNotBlank(appKey) && StringUtils.isBlank(limitIp)) { if (StringUtils.isNotBlank(routeId) && StringUtils.isNotBlank(appKey) && StringUtils.isBlank(limitIp)) {
keys.add(routeId.trim() + appKey.trim()); keys.add(routeId.trim() + appKey.trim());
} }
Set<String> baseKeys = new HashSet<>(keys);
// 根据ip限流 // 根据ip限流
if (StringUtils.isBlank(routeId) && StringUtils.isBlank(appKey) && StringUtils.isNotBlank(limitIp)) { if (StringUtils.isBlank(routeId) && StringUtils.isBlank(appKey) && StringUtils.isNotBlank(limitIp)) {
String[] ips = limitIp.split("\\,|\\,"); String[] ips = limitIp.split("\\,|\\,");
keys.addAll(Arrays.asList(ips)); keys.addAll(Arrays.asList(ips));
} }
// 根据ip+路由id限流
// 根据ip+appKey限流
// 根据ip+路由id+appKey限流
if (StringUtils.isNotBlank(limitIp)) { if (StringUtils.isNotBlank(limitIp)) {
String[] ips = limitIp.split("\\,|\\,"); String[] ips = limitIp.split("\\,|\\,");
for (String ip : ips) { for (String ip : ips) {
for (String baseKey : baseKeys) { // 根据ip+路由id限流
keys.add(ip + baseKey); if (StringUtils.isNotBlank(ip) && StringUtils.isNotBlank(routeId) && StringUtils.isBlank(appKey)) {
keys.add(routeId);
}
// 根据ip+appKey限流
if (StringUtils.isNotBlank(ip) && StringUtils.isBlank(routeId) && StringUtils.isNotBlank(appKey)) {
keys.add(ip + appKey);
}
// 根据ip+路由id+appKey限流
if (StringUtils.isNotBlank(ip) && StringUtils.isNotBlank(routeId) && StringUtils.isNotBlank(appKey)) {
keys.add(ip + routeId +appKey);
} }
} }
} }

Loading…
Cancel
Save