mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
优化Gateway限流
This commit is contained in:
@@ -2,6 +2,7 @@ package com.gitee.sop.gatewaycommon.gateway.configuration;
|
||||
|
||||
import com.gitee.sop.gatewaycommon.bean.ApiConfig;
|
||||
import com.gitee.sop.gatewaycommon.gateway.filter.GatewayModifyResponseGatewayFilter;
|
||||
import com.gitee.sop.gatewaycommon.gateway.filter.LimitFilter;
|
||||
import com.gitee.sop.gatewaycommon.gateway.filter.LoadBalancerClientExtFilter;
|
||||
import com.gitee.sop.gatewaycommon.gateway.filter.ParameterFormatterFilter;
|
||||
import com.gitee.sop.gatewaycommon.gateway.filter.ValidateFilter;
|
||||
@@ -90,6 +91,11 @@ public class BaseGatewayConfiguration extends AbstractConfiguration {
|
||||
return new ValidateFilter();
|
||||
}
|
||||
|
||||
@Bean
|
||||
LimitFilter limitFilter() {
|
||||
return new LimitFilter();
|
||||
}
|
||||
|
||||
@Bean
|
||||
LoadBalancerClientExtFilter loadBalancerClientExtFilter() {
|
||||
return new LoadBalancerClientExtFilter();
|
||||
|
@@ -17,7 +17,6 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -41,7 +40,7 @@ public class LimitFilter implements GlobalFilter, Ordered {
|
||||
}
|
||||
// 单个限流功能未开启
|
||||
if (configLimitDto.getLimitStatus() == ConfigLimitDto.LIMIT_STATUS_CLOSE) {
|
||||
return null;
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
byte limitType = configLimitDto.getLimitType().byteValue();
|
||||
LimitManager limitManager = ApiConfig.getInstance().getLimitManager();
|
||||
@@ -82,12 +81,15 @@ public class LimitFilter implements GlobalFilter, Ordered {
|
||||
List<ConfigLimitDto> limitConfigList = new ArrayList<>();
|
||||
for (String limitKey : limitKeys) {
|
||||
ConfigLimitDto configLimitDto = limitConfigManager.get(limitKey);
|
||||
if (configLimitDto == null) {
|
||||
continue;
|
||||
}
|
||||
limitConfigList.add(configLimitDto);
|
||||
}
|
||||
if (limitConfigList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
Collections.sort(limitConfigList, Comparator.comparing(ConfigLimitDto::getOrderIndex));
|
||||
limitConfigList.sort(Comparator.comparing(ConfigLimitDto::getOrderIndex));
|
||||
return limitConfigList.get(0);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user