diff --git a/sop-common/sop-bridge-zuul/src/main/resources/sop-bridge.properties b/sop-common/sop-bridge-zuul/src/main/resources/sop-bridge.properties index 4f0c045e..7f4699ad 100644 --- a/sop-common/sop-bridge-zuul/src/main/resources/sop-bridge.properties +++ b/sop-common/sop-bridge-zuul/src/main/resources/sop-bridge.properties @@ -8,6 +8,11 @@ zuul.Servlet30WrapperFilter.pre.disable=true # 不用改,如果要改,请全局替换修改 sop.secret=MZZOUSTua6LzApIWXCwEgbBmxSzpzC +# zuul优化配置 +zuul.host.max-per-route-connections=1000 +zuul.host.max-total-connections=1000 +zuul.semaphore.max-semaphores=1000 + # nacos cloud配置 spring.cloud.nacos.discovery.server-addr=${nacos.url} diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/DefaultLimitConfigManager.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/DefaultLimitConfigManager.java index 54efd924..d7885087 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/DefaultLimitConfigManager.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/DefaultLimitConfigManager.java @@ -3,6 +3,7 @@ package com.gitee.sop.gatewaycommon.manager; import com.gitee.sop.gatewaycommon.bean.ConfigLimitDto; import org.apache.commons.lang.StringUtils; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -39,22 +40,64 @@ public class DefaultLimitConfigManager implements LimitConfigManager { } } + /** + * // 根据路由ID限流 + * routeId, + * // 根据appKey限流 + * appKey, + * // 根据路由ID + appKey限流 + * routeId + appKey, + * + * // 根据ip限流 + * ip, + * // 根据ip+路由id限流 + * ip + routeId, + * // 根据ip+appKey限流 + * ip + appKey, + * // 根据ip+路由id+appKey限流 + * ip + routeId + appKey, + * @param configLimitDto + * @return + */ protected Set buildKeys(ConfigLimitDto configLimitDto) { Set keys = new HashSet<>(); + Set baseKeys = new HashSet<>(); String routeId = Optional.ofNullable(configLimitDto.getRouteId()).orElse(""); String appKey = Optional.ofNullable(configLimitDto.getAppKey()).orElse(""); String limitIp = Optional.ofNullable(configLimitDto.getLimitIp()).orElse("").replaceAll("\\s", ""); - String baseKey = routeId.trim() + appKey.trim(); - keys.add(baseKey); + // 根据路由ID限流 + if (StringUtils.isNotBlank(routeId) && StringUtils.isBlank(appKey) && StringUtils.isBlank(limitIp)) { + keys.add(routeId); + baseKeys.add(routeId); + } + // 根据appKey限流 + if (StringUtils.isBlank(routeId) && StringUtils.isNotBlank(appKey) && StringUtils.isBlank(limitIp)) { + keys.add(appKey); + baseKeys.add(appKey); + } + // 根据路由ID + appKey限流 + if (StringUtils.isNotBlank(routeId) && StringUtils.isNotBlank(appKey) && StringUtils.isBlank(limitIp)) { + keys.add(routeId.trim() + appKey.trim()); + baseKeys.add(routeId.trim() + appKey.trim()); + } + // 根据ip限流 + if (StringUtils.isBlank(routeId) && StringUtils.isBlank(appKey) && StringUtils.isNotBlank(limitIp)) { + String[] ips = limitIp.split("\\,|\\,"); + keys.addAll(Arrays.asList(ips)); + } + // 根据ip+路由id限流 + // 根据ip+appKey限流 + // 根据ip+路由id+appKey限流 if (StringUtils.isNotBlank(limitIp)) { String[] ips = limitIp.split("\\,|\\,"); for (String ip : ips) { - keys.add(ip + baseKey); + for (String baseKey : baseKeys) { + keys.add(ip + baseKey); + } } } - return keys; } diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/controller/ZuulIndexController.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/controller/ZuulIndexController.java index ac1606e4..bc7ebd27 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/controller/ZuulIndexController.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/controller/ZuulIndexController.java @@ -6,7 +6,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import javax.servlet.ServletException; @@ -75,15 +74,4 @@ public class ZuulIndexController { request.getRequestDispatcher(this.path).forward(request, response); } - @RequestMapping("/{method}/{version}/") - public void redirect( - @PathVariable("method") String method - , @PathVariable("version") String version - , HttpServletRequest request - , HttpServletResponse response - ) { - request.setAttribute(SopConstants.REDIRECT_METHOD_KEY, method); - request.setAttribute(SopConstants.REDIRECT_VERSION_KEY, version); - validateService.validate(request, response, callback); - } }