增加全功能spring-cloud-gateway,优化部分公共模块适配webFlux
This commit is contained in:
+18
@@ -0,0 +1,18 @@
|
||||
package com.central.common.ribbon;
|
||||
|
||||
import com.central.common.constant.ConfigConstants;
|
||||
import com.central.common.ribbon.config.RuleConfigure;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.cloud.netflix.ribbon.RibbonClients;
|
||||
|
||||
/**
|
||||
* Ribbon扩展配置类
|
||||
*
|
||||
* @author zlt
|
||||
* @date 2018/11/17 9:24
|
||||
*/
|
||||
@ConditionalOnProperty(value = ConfigConstants.CONFIG_RIBBON_ISOLATION_ENABLED, havingValue = "true")
|
||||
@RibbonClients(defaultConfiguration = {RuleConfigure.class})
|
||||
public class LbIsolationAutoConfigure {
|
||||
|
||||
}
|
||||
-11
@@ -1,14 +1,9 @@
|
||||
package com.central.common.ribbon;
|
||||
|
||||
import com.central.common.constant.ConfigConstants;
|
||||
import com.central.common.ribbon.config.RestTemplateProperties;
|
||||
import com.central.common.ribbon.config.RuleConfigure;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.netflix.ribbon.DefaultPropertiesFactory;
|
||||
import org.springframework.cloud.netflix.ribbon.RibbonClients;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Ribbon扩展配置类
|
||||
@@ -22,10 +17,4 @@ public class RibbonAutoConfigure {
|
||||
public DefaultPropertiesFactory defaultPropertiesFactory() {
|
||||
return new DefaultPropertiesFactory();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnProperty(value = ConfigConstants.CONFIG_RIBBON_ISOLATION_ENABLED, havingValue = "true")
|
||||
@RibbonClients(defaultConfiguration = {RuleConfigure.class})
|
||||
public class LbIsolationConfig {
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ public class FeignInterceptorConfig {
|
||||
Enumeration<String> headers = request.getHeaders(CommonConstant.TOKEN_HEADER);
|
||||
while (headers.hasMoreElements()) {
|
||||
String value = headers.nextElement();
|
||||
if ((value.toLowerCase().startsWith(CommonConstant.BEARER_TYPE.toLowerCase()))) {
|
||||
if ((value.toLowerCase().startsWith(CommonConstant.BEARER_TYPE))) {
|
||||
String authHeaderValue = value.substring(CommonConstant.BEARER_TYPE.length()).trim();
|
||||
int commaIndex = authHeaderValue.indexOf(',');
|
||||
if (commaIndex > 0) {
|
||||
|
||||
+5
@@ -5,8 +5,12 @@ import com.central.common.constant.CommonConstant;
|
||||
import com.central.common.constant.ConfigConstants;
|
||||
import com.central.common.context.LbIsolationContextHolder;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -19,6 +23,7 @@ import java.io.IOException;
|
||||
* @author zlt
|
||||
* @date 2019/9/15
|
||||
*/
|
||||
@ConditionalOnClass(Filter.class)
|
||||
public class LbIsolationFilter extends OncePerRequestFilter {
|
||||
@Value("${" + ConfigConstants.CONFIG_RIBBON_ISOLATION_ENABLED + ":false}")
|
||||
private boolean enableIsolation;
|
||||
|
||||
+8
-1
@@ -18,6 +18,7 @@ import java.util.stream.Collectors;
|
||||
* @date 2019/9/3
|
||||
*/
|
||||
public class CustomIsolationRule extends RoundRobinRule {
|
||||
private final static String KEY_DEFAULT = "default";
|
||||
/**
|
||||
* 优先根据版本号取实例
|
||||
*/
|
||||
@@ -26,7 +27,13 @@ public class CustomIsolationRule extends RoundRobinRule {
|
||||
if (lb == null) {
|
||||
return null;
|
||||
}
|
||||
String version = LbIsolationContextHolder.getVersion();
|
||||
String version;
|
||||
if (key != null && !KEY_DEFAULT.equals(key)) {
|
||||
version = key.toString();
|
||||
} else {
|
||||
version = LbIsolationContextHolder.getVersion();
|
||||
}
|
||||
|
||||
List<Server> targetList = null;
|
||||
List<Server> upList = lb.getReachableServers();
|
||||
if (StrUtil.isNotEmpty(version)) {
|
||||
|
||||
Reference in New Issue
Block a user