pull/1/MERGE
tanghc 5 years ago
parent 563d5adcc0
commit 99cb38eaa4
  1. 5
      sop-common/sop-bridge-zuul/src/main/resources/sop-bridge.properties
  2. 51
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/DefaultLimitConfigManager.java
  3. 12
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/controller/ZuulIndexController.java

@ -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}

@ -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<String> buildKeys(ConfigLimitDto configLimitDto) {
Set<String> keys = new HashSet<>();
Set<String> 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;
}

@ -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);
}
}

Loading…
Cancel
Save