Merge pull request #435 from wehotel/develop
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
<groupId>com.fizzgate</groupId>
|
<groupId>com.fizzgate</groupId>
|
||||||
<artifactId>fizz-bootstrap</artifactId>
|
<artifactId>fizz-bootstrap</artifactId>
|
||||||
<version>2.6.4</version>
|
<version>2.6.5-beta1</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
|
|||||||
@@ -116,19 +116,21 @@ fizz:
|
|||||||
code-field: "msgCode"
|
code-field: "msgCode"
|
||||||
message-field: "message"
|
message-field: "message"
|
||||||
|
|
||||||
dedicated-line:
|
fast-fail-when-registry-center-down: false
|
||||||
server:
|
|
||||||
enable: true
|
# dedicated-line:
|
||||||
client:
|
# server:
|
||||||
enable: true
|
# enable: true
|
||||||
port: 8601
|
# client:
|
||||||
request:
|
# enable: true
|
||||||
timeliness: 300 # default 300 sec
|
# port: 8601
|
||||||
timeout: 0 # default no timeout
|
# request:
|
||||||
retry-count: 0 # default no retry
|
# timeliness: 300 # default 300 sec
|
||||||
retry-interval: 0 # default no retry interval
|
# timeout: 0 # default no timeout
|
||||||
crypto: true # if true, client will encrypt request body and decrypt response body
|
# retry-count: 0 # default no retry
|
||||||
service-registration:
|
# retry-interval: 0 # default no retry interval
|
||||||
|
# crypto: true # if true, client will encrypt request body and decrypt response body
|
||||||
|
# service-registration:
|
||||||
# eureka:
|
# eureka:
|
||||||
# server-port: 8601
|
# server-port: 8601
|
||||||
# client:
|
# client:
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>fizz-gateway-community</artifactId>
|
<artifactId>fizz-gateway-community</artifactId>
|
||||||
<groupId>com.fizzgate</groupId>
|
<groupId>com.fizzgate</groupId>
|
||||||
<version>2.6.4</version>
|
<version>2.6.5-beta1</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public abstract class PropertiesUtils {
|
|||||||
|
|
||||||
public static void setBeanPropertyValue(Object bean, Properties properties, Map<String, Class<?>> propertyTypeHint) {
|
public static void setBeanPropertyValue(Object bean, Properties properties, Map<String, Class<?>> propertyTypeHint) {
|
||||||
BeanWrapperImpl beanWrapper = new BeanWrapperImpl(bean);
|
BeanWrapperImpl beanWrapper = new BeanWrapperImpl(bean);
|
||||||
for (String propertyName : properties.stringPropertyNames()) {
|
/*for (String propertyName : properties.stringPropertyNames()) {
|
||||||
if (beanWrapper.isWritableProperty(propertyName)) {
|
if (beanWrapper.isWritableProperty(propertyName)) {
|
||||||
beanWrapper.setPropertyValue(propertyName, properties.get(propertyName));
|
beanWrapper.setPropertyValue(propertyName, properties.get(propertyName));
|
||||||
} else if (propertyTypeHint != null) {
|
} else if (propertyTypeHint != null) {
|
||||||
@@ -77,6 +77,24 @@ public abstract class PropertiesUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
properties.forEach(
|
||||||
|
(n, v) -> {
|
||||||
|
String propertyName = (String) n;
|
||||||
|
if (beanWrapper.isWritableProperty(propertyName)) {
|
||||||
|
beanWrapper.setPropertyValue(propertyName, properties.get(propertyName));
|
||||||
|
} else if (propertyTypeHint != null) {
|
||||||
|
int dotPos = propertyName.lastIndexOf(Consts.S.DOT);
|
||||||
|
if (dotPos > -1) {
|
||||||
|
String prefix = propertyName.substring(0, dotPos);
|
||||||
|
Class<?> aClass = propertyTypeHint.get(prefix);
|
||||||
|
if (aClass != null && Map.class.isAssignableFrom(aClass)) {
|
||||||
|
String newPropertyName = prefix + PropertyAccessor.PROPERTY_KEY_PREFIX_CHAR + propertyName.substring(dotPos + 1) + PropertyAccessor.PROPERTY_KEY_SUFFIX_CHAR;
|
||||||
|
beanWrapper.setPropertyValue(newPropertyName, properties.get(propertyName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
package we.util;
|
package we.util;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hongqiaowei
|
* @author hongqiaowei
|
||||||
@@ -39,4 +40,10 @@ public abstract class ReflectionUtils extends org.springframework.util.Reflectio
|
|||||||
makeAccessible(f);
|
makeAccessible(f);
|
||||||
return getField(f, target);
|
return getField(f, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Object invokeMethod(String method, Object target, Object... args) {
|
||||||
|
Method m = findMethod(target.getClass(), method);
|
||||||
|
makeAccessible(m);
|
||||||
|
return invokeMethod(m, target, args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>fizz-gateway-community</artifactId>
|
<artifactId>fizz-gateway-community</artifactId>
|
||||||
<groupId>com.fizzgate</groupId>
|
<groupId>com.fizzgate</groupId>
|
||||||
<version>2.6.4</version>
|
<version>2.6.5-beta1</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -122,6 +122,13 @@ public class SystemConfig {
|
|||||||
|
|
||||||
private String fizzDedicatedLineClientId;
|
private String fizzDedicatedLineClientId;
|
||||||
|
|
||||||
|
@Value("${fizz.fast-fail-when-registry-center-down:false}")
|
||||||
|
private boolean fastFailWhenRegistryCenterDown;
|
||||||
|
|
||||||
|
public boolean isFastFailWhenRegistryCenterDown() {
|
||||||
|
return fastFailWhenRegistryCenterDown;
|
||||||
|
}
|
||||||
|
|
||||||
public int fizzDedicatedLineClientRequestTimeout() {
|
public int fizzDedicatedLineClientRequestTimeout() {
|
||||||
return fizzDedicatedLineClientRequestTimeout;
|
return fizzDedicatedLineClientRequestTimeout;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
package we.controller;
|
package we.controller;
|
||||||
|
|
||||||
import org.openjdk.jol.info.GraphLayout;
|
import org.openjdk.jol.info.GraphLayout;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
@@ -74,7 +75,7 @@ public class CacheCheckController {
|
|||||||
@Resource
|
@Resource
|
||||||
private CircuitBreakManager circuitBreakManager;
|
private CircuitBreakManager circuitBreakManager;
|
||||||
|
|
||||||
@Resource
|
@Autowired(required = false)
|
||||||
private FlowStat flowStat;
|
private FlowStat flowStat;
|
||||||
|
|
||||||
@GetMapping("/gatewayGroups")
|
@GetMapping("/gatewayGroups")
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package we.dedicated_line;
|
|||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
|
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -50,15 +51,20 @@ public class DedicatedLineInfoService {
|
|||||||
@Resource(name = AggregateRedisConfig.AGGREGATE_REACTIVE_REDIS_TEMPLATE)
|
@Resource(name = AggregateRedisConfig.AGGREGATE_REACTIVE_REDIS_TEMPLATE)
|
||||||
private ReactiveStringRedisTemplate rt;
|
private ReactiveStringRedisTemplate rt;
|
||||||
|
|
||||||
|
@Value("${fizz.dedicated-line.client.enable:true}")
|
||||||
|
private boolean fizzDedicatedLineClientEnable;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() throws Throwable {
|
public void init() throws Throwable {
|
||||||
Result<?> result = initDedicatedLineInfo();
|
if (fizzDedicatedLineClientEnable) {
|
||||||
if (result.code == Result.FAIL) {
|
Result<?> result = initDedicatedLineInfo();
|
||||||
throw new RuntimeException(result.msg, result.t);
|
if (result.code == Result.FAIL) {
|
||||||
}
|
throw new RuntimeException(result.msg, result.t);
|
||||||
result = lsnApiPairingInfoChange();
|
}
|
||||||
if (result.code == Result.FAIL) {
|
result = lsnApiPairingInfoChange();
|
||||||
throw new RuntimeException(result.msg, result.t);
|
if (result.code == Result.FAIL) {
|
||||||
|
throw new RuntimeException(result.msg, result.t);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package we.dedicated_line;
|
|||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
|
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
|
||||||
import org.springframework.http.HttpMethod;
|
import org.springframework.http.HttpMethod;
|
||||||
@@ -54,15 +55,20 @@ public class DedicatedLineService {
|
|||||||
@Resource(name = AggregateRedisConfig.AGGREGATE_REACTIVE_REDIS_TEMPLATE)
|
@Resource(name = AggregateRedisConfig.AGGREGATE_REACTIVE_REDIS_TEMPLATE)
|
||||||
private ReactiveStringRedisTemplate rt;
|
private ReactiveStringRedisTemplate rt;
|
||||||
|
|
||||||
|
@Value("${fizz.dedicated-line.server.enable:true}")
|
||||||
|
private boolean fizzDedicatedLineServerEnable;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() throws Throwable {
|
public void init() throws Throwable {
|
||||||
Result<?> result = initDedicatedLine();
|
if (fizzDedicatedLineServerEnable) {
|
||||||
if (result.code == Result.FAIL) {
|
Result<?> result = initDedicatedLine();
|
||||||
throw new RuntimeException(result.msg, result.t);
|
if (result.code == Result.FAIL) {
|
||||||
}
|
throw new RuntimeException(result.msg, result.t);
|
||||||
result = lsnDedicatedLineChange();
|
}
|
||||||
if (result.code == Result.FAIL) {
|
result = lsnDedicatedLineChange();
|
||||||
throw new RuntimeException(result.msg, result.t);
|
if (result.code == Result.FAIL) {
|
||||||
|
throw new RuntimeException(result.msg, result.t);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import com.alibaba.cloud.nacos.discovery.NacosDiscoveryAutoConfiguration;
|
|||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.env.OriginTrackedMapPropertySource;
|
import org.springframework.boot.env.OriginTrackedMapPropertySource;
|
||||||
@@ -30,6 +31,7 @@ import org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration;
|
|||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.ApplicationListener;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.core.env.ConfigurableEnvironment;
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
import org.springframework.core.env.MapPropertySource;
|
||||||
import org.springframework.core.env.PropertySource;
|
import org.springframework.core.env.PropertySource;
|
||||||
import we.config.SystemConfig;
|
import we.config.SystemConfig;
|
||||||
import we.service_registry.FizzServiceRegistration;
|
import we.service_registry.FizzServiceRegistration;
|
||||||
@@ -53,15 +55,22 @@ public class DedicatedLineServiceRegistration implements ApplicationListener<Ded
|
|||||||
|
|
||||||
private FizzServiceRegistration fizzServiceRegistration;
|
private FizzServiceRegistration fizzServiceRegistration;
|
||||||
|
|
||||||
|
@Value("${fizz.dedicated-line.client.enable:true}")
|
||||||
|
private boolean fizzDedicatedLineClientEnable;
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
@Override
|
@Override
|
||||||
public void onApplicationEvent(DedicatedLineWebServerInitializedEvent event) {
|
public void onApplicationEvent(DedicatedLineWebServerInitializedEvent event) {
|
||||||
|
|
||||||
|
if (!fizzDedicatedLineClientEnable) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ReactiveWebServerApplicationContext applicationContext = event.getApplicationContext();
|
ReactiveWebServerApplicationContext applicationContext = event.getApplicationContext();
|
||||||
ConfigurableEnvironment env = applicationContext.getEnvironment();
|
ConfigurableEnvironment env = applicationContext.getEnvironment();
|
||||||
|
|
||||||
String prefix = SystemConfig.FIZZ_DEDICATED_LINE_CLIENT_PREFIX + ".service-registration";
|
String prefix = SystemConfig.FIZZ_DEDICATED_LINE_CLIENT_PREFIX + ".service-registration";
|
||||||
boolean eureka = env.containsProperty((prefix + ".eureka.instance.appname"));
|
boolean eureka = env.containsProperty((prefix + ".eureka.client.serviceUrl.defaultZone"));
|
||||||
boolean nacos = env.containsProperty((prefix + ".nacos.discovery.server-addr"));
|
boolean nacos = env.containsProperty((prefix + ".nacos.discovery.server-addr"));
|
||||||
|
|
||||||
if (eureka || nacos) {
|
if (eureka || nacos) {
|
||||||
@@ -69,8 +78,9 @@ public class DedicatedLineServiceRegistration implements ApplicationListener<Ded
|
|||||||
Properties eurekaProperties = new Properties();
|
Properties eurekaProperties = new Properties();
|
||||||
boolean find = false;
|
boolean find = false;
|
||||||
for (PropertySource<?> propertySource : env.getPropertySources()) {
|
for (PropertySource<?> propertySource : env.getPropertySources()) {
|
||||||
if (propertySource instanceof OriginTrackedMapPropertySource) {
|
// if (propertySource instanceof OriginTrackedMapPropertySource) {
|
||||||
OriginTrackedMapPropertySource originTrackedMapPropertySource = (OriginTrackedMapPropertySource) propertySource;
|
if (MapPropertySource.class.isAssignableFrom(propertySource.getClass())) {
|
||||||
|
MapPropertySource originTrackedMapPropertySource = (MapPropertySource) propertySource;
|
||||||
String[] propertyNames = originTrackedMapPropertySource.getPropertyNames();
|
String[] propertyNames = originTrackedMapPropertySource.getPropertyNames();
|
||||||
for (String propertyName : propertyNames) {
|
for (String propertyName : propertyNames) {
|
||||||
if (propertyName.length() > 55) {
|
if (propertyName.length() > 55) {
|
||||||
@@ -97,8 +107,9 @@ public class DedicatedLineServiceRegistration implements ApplicationListener<Ded
|
|||||||
Properties nacosProperties = new Properties();
|
Properties nacosProperties = new Properties();
|
||||||
boolean find = false;
|
boolean find = false;
|
||||||
for (PropertySource<?> propertySource : env.getPropertySources()) {
|
for (PropertySource<?> propertySource : env.getPropertySources()) {
|
||||||
if (propertySource instanceof OriginTrackedMapPropertySource) {
|
// if (propertySource instanceof OriginTrackedMapPropertySource) {
|
||||||
OriginTrackedMapPropertySource originTrackedMapPropertySource = (OriginTrackedMapPropertySource) propertySource;
|
if (MapPropertySource.class.isAssignableFrom(propertySource.getClass())) {
|
||||||
|
MapPropertySource originTrackedMapPropertySource = (MapPropertySource) propertySource;
|
||||||
String[] propertyNames = originTrackedMapPropertySource.getPropertyNames();
|
String[] propertyNames = originTrackedMapPropertySource.getPropertyNames();
|
||||||
for (String propertyName : propertyNames) {
|
for (String propertyName : propertyNames) {
|
||||||
if (propertyName.length() > 64) {
|
if (propertyName.length() > 64) {
|
||||||
|
|||||||
@@ -58,26 +58,33 @@ public class DedicatedLineWebServer {
|
|||||||
@Value("${fizz.dedicated-line.client.port:8601}")
|
@Value("${fizz.dedicated-line.client.port:8601}")
|
||||||
private int port = 8601;
|
private int port = 8601;
|
||||||
|
|
||||||
|
@Value("${fizz.dedicated-line.client.enable:true}")
|
||||||
|
private boolean fizzDedicatedLineClientEnable;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void start() {
|
public void start() {
|
||||||
HttpWebHandlerAdapter adapter = (HttpWebHandlerAdapter) httpHandler;
|
if (fizzDedicatedLineClientEnable) {
|
||||||
NettyReactiveWebServerFactory factory = new NettyReactiveWebServerFactory(port);
|
HttpWebHandlerAdapter adapter = (HttpWebHandlerAdapter) httpHandler;
|
||||||
server = factory.getWebServer(
|
NettyReactiveWebServerFactory factory = new NettyReactiveWebServerFactory(port);
|
||||||
new DedicatedLineHttpHandler(
|
server = factory.getWebServer(
|
||||||
applicationContext,
|
new DedicatedLineHttpHandler(
|
||||||
new DefaultWebSessionManager(),
|
applicationContext,
|
||||||
adapter.getCodecConfigurer(),
|
new DefaultWebSessionManager(),
|
||||||
adapter.getLocaleContextResolver(),
|
adapter.getCodecConfigurer(),
|
||||||
adapter.getForwardedHeaderTransformer()
|
adapter.getLocaleContextResolver(),
|
||||||
)
|
adapter.getForwardedHeaderTransformer()
|
||||||
);
|
)
|
||||||
server.start();
|
);
|
||||||
log.info("fizz dedicated line web server listen on {}", port);
|
server.start();
|
||||||
applicationContext.publishEvent(new DedicatedLineWebServerInitializedEvent(server, applicationContext));
|
log.info("fizz dedicated line web server listen on {}", port);
|
||||||
|
applicationContext.publishEvent(new DedicatedLineWebServerInitializedEvent(server, applicationContext));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreDestroy
|
@PreDestroy
|
||||||
public void stop() {
|
public void stop() {
|
||||||
server.stop();
|
if (server != null) {
|
||||||
|
server.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public abstract class FizzWebFilter implements WebFilter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
|
||||||
if (WebUtils.isAdminReq(exchange) || WebUtils.isFizzReq(exchange)) {
|
if (WebUtils.isAdminReq(exchange) || WebUtils.isFizzReq(exchange) || WebUtils.isFavReq(exchange)) {
|
||||||
return chain.filter(exchange);
|
return chain.filter(exchange);
|
||||||
} else {
|
} else {
|
||||||
return doFilter(exchange, chain);
|
return doFilter(exchange, chain);
|
||||||
|
|||||||
@@ -78,6 +78,11 @@ public class FlowControlFilter extends FizzWebFilter {
|
|||||||
|
|
||||||
private static final String qps = "qps";
|
private static final String qps = "qps";
|
||||||
|
|
||||||
|
private static final String favPath = "/favicon.ico";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private FlowControlFilterProperties flowControlFilterProperties;
|
private FlowControlFilterProperties flowControlFilterProperties;
|
||||||
@@ -111,28 +116,37 @@ public class FlowControlFilter extends FizzWebFilter {
|
|||||||
|
|
||||||
ServerHttpRequest request = exchange.getRequest();
|
ServerHttpRequest request = exchange.getRequest();
|
||||||
String path = request.getPath().value();
|
String path = request.getPath().value();
|
||||||
int secFS = path.indexOf(Consts.S.FORWARD_SLASH, 1);
|
boolean adminReq = false, proxyTestReq = false, fizzApiReq = false, favReq = false;
|
||||||
if (secFS == -1) {
|
if (path.equals(favPath)) {
|
||||||
return WebUtils.responseError(exchange, HttpStatus.INTERNAL_SERVER_ERROR.value(), "request path should like /optional-prefix/service-name/real-biz-path");
|
exchange.getAttributes().put(WebUtils.FAV_REQUEST, Consts.S.EMPTY);
|
||||||
|
favReq = true;
|
||||||
}
|
}
|
||||||
String service = path.substring(1, secFS);
|
|
||||||
boolean adminReq = false, proxyTestReq = false, fizzApiReq = false;
|
String service = null;
|
||||||
if (service.equals(admin) || service.equals(actuator)) {
|
if (!favReq) {
|
||||||
adminReq = true;
|
int secFS = path.indexOf(Consts.S.FORWARD_SLASH, 1);
|
||||||
exchange.getAttributes().put(WebUtils.ADMIN_REQUEST, Consts.S.EMPTY);
|
if (secFS == -1) {
|
||||||
} else if (service.equals(SystemConfig.DEFAULT_GATEWAY_TEST)) {
|
return WebUtils.responseError(exchange, HttpStatus.INTERNAL_SERVER_ERROR.value(), "request path should like /optional-prefix/service-name/real-biz-path");
|
||||||
proxyTestReq = true;
|
|
||||||
} else {
|
|
||||||
service = WebUtils.getClientService(exchange);
|
|
||||||
if (service.startsWith(_fizz)) {
|
|
||||||
fizzApiReq = true;
|
|
||||||
exchange.getAttributes().put(WebUtils.FIZZ_REQUEST, Consts.S.EMPTY);
|
|
||||||
}
|
}
|
||||||
|
service = path.substring(1, secFS);
|
||||||
|
|
||||||
|
if (service.equals(admin) || service.equals(actuator)) {
|
||||||
|
adminReq = true;
|
||||||
|
exchange.getAttributes().put(WebUtils.ADMIN_REQUEST, Consts.S.EMPTY);
|
||||||
|
} else if (service.equals(SystemConfig.DEFAULT_GATEWAY_TEST)) {
|
||||||
|
proxyTestReq = true;
|
||||||
|
} else {
|
||||||
|
service = WebUtils.getClientService(exchange);
|
||||||
|
if (service.startsWith(_fizz)) {
|
||||||
|
fizzApiReq = true;
|
||||||
|
exchange.getAttributes().put(WebUtils.FIZZ_REQUEST, Consts.S.EMPTY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setTraceId(exchange);
|
||||||
}
|
}
|
||||||
|
|
||||||
setTraceId(exchange);
|
if (!favReq && flowControlFilterProperties.isFlowControl() && !adminReq && !proxyTestReq && !fizzApiReq) {
|
||||||
|
|
||||||
if (flowControlFilterProperties.isFlowControl() && !adminReq && !proxyTestReq && !fizzApiReq) {
|
|
||||||
String traceId = WebUtils.getTraceId(exchange);
|
String traceId = WebUtils.getTraceId(exchange);
|
||||||
LogService.setBizId(traceId);
|
LogService.setBizId(traceId);
|
||||||
if (!apiConfigService.serviceConfigMap.containsKey(service)) {
|
if (!apiConfigService.serviceConfigMap.containsKey(service)) {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
import we.config.AggregateRedisConfig;
|
import we.config.AggregateRedisConfig;
|
||||||
|
import we.config.SystemConfig;
|
||||||
import we.util.Consts;
|
import we.util.Consts;
|
||||||
import we.util.JacksonUtils;
|
import we.util.JacksonUtils;
|
||||||
import we.util.Result;
|
import we.util.Result;
|
||||||
@@ -42,7 +43,7 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class RegistryCenterService implements ApplicationListener<ContextRefreshedEvent> {
|
public class RegistryCenterService implements ApplicationListener<ContextRefreshedEvent> {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(RegistryCenterService.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(RegistryCenterService.class);
|
||||||
|
|
||||||
@@ -54,6 +55,9 @@ public class RegistryCenterService implements ApplicationListener<ContextRefresh
|
|||||||
@Resource(name = AggregateRedisConfig.AGGREGATE_REACTIVE_REDIS_TEMPLATE)
|
@Resource(name = AggregateRedisConfig.AGGREGATE_REACTIVE_REDIS_TEMPLATE)
|
||||||
private ReactiveStringRedisTemplate rt;
|
private ReactiveStringRedisTemplate rt;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SystemConfig systemConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||||
Result<?> result = initRegistryCenter();
|
Result<?> result = initRegistryCenter();
|
||||||
@@ -80,9 +84,19 @@ public class RegistryCenterService implements ApplicationListener<ContextRefresh
|
|||||||
json = (String) e.getValue();
|
json = (String) e.getValue();
|
||||||
RegistryCenter rc = JacksonUtils.readValue(json, RegistryCenter.class);
|
RegistryCenter rc = JacksonUtils.readValue(json, RegistryCenter.class);
|
||||||
registryCenterMap.put(rc.name, rc);
|
registryCenterMap.put(rc.name, rc);
|
||||||
LOGGER.info("init registry center {}", rc);
|
|
||||||
rc.initFizzServiceRegistration(applicationContext);
|
rc.initFizzServiceRegistration(applicationContext);
|
||||||
rc.getFizzServiceRegistration().register();
|
FizzServiceRegistration fizzServiceRegistration = rc.getFizzServiceRegistration();
|
||||||
|
try {
|
||||||
|
fizzServiceRegistration.register();
|
||||||
|
LOGGER.info("success to init registry center {}", rc);
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
if (systemConfig.isFastFailWhenRegistryCenterDown()) {
|
||||||
|
throw throwable;
|
||||||
|
} else {
|
||||||
|
LOGGER.warn("fail to init registry center {}, fast fail when registry center down is false, so continue", rc, throwable);
|
||||||
|
fizzServiceRegistration.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
result.code = Result.FAIL;
|
result.code = Result.FAIL;
|
||||||
@@ -146,7 +160,13 @@ public class RegistryCenterService implements ApplicationListener<ContextRefresh
|
|||||||
fizzServiceRegistration.close();
|
fizzServiceRegistration.close();
|
||||||
}
|
}
|
||||||
rc.initFizzServiceRegistration(applicationContext);
|
rc.initFizzServiceRegistration(applicationContext);
|
||||||
rc.getFizzServiceRegistration().register();
|
FizzServiceRegistration fsr = rc.getFizzServiceRegistration();
|
||||||
|
try {
|
||||||
|
fsr.register();
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
LOGGER.error("fail to update registry center {}", rc, throwable);
|
||||||
|
fsr.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
LOGGER.error("update registry center error, {}", message, t);
|
LOGGER.error("update registry center error, {}", message, t);
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public abstract class FizzEurekaHelper {
|
|||||||
public static FizzEurekaServiceRegistration getServiceRegistration(ApplicationContext applicationContext, Properties eurekaProperties) {
|
public static FizzEurekaServiceRegistration getServiceRegistration(ApplicationContext applicationContext, Properties eurekaProperties) {
|
||||||
|
|
||||||
Properties eurekaProps = new Properties();
|
Properties eurekaProps = new Properties();
|
||||||
for (String propertyName : eurekaProperties.stringPropertyNames()) {
|
/*for (String propertyName : eurekaProperties.stringPropertyNames()) {
|
||||||
String pn = null;
|
String pn = null;
|
||||||
if (propertyName.charAt(ecl - 1) == Consts.S.DOT) {
|
if (propertyName.charAt(ecl - 1) == Consts.S.DOT) {
|
||||||
pn = propertyName.substring(ecl);
|
pn = propertyName.substring(ecl);
|
||||||
@@ -68,7 +68,25 @@ public abstract class FizzEurekaHelper {
|
|||||||
pn = PropertiesUtils.normalize(pn);
|
pn = PropertiesUtils.normalize(pn);
|
||||||
}
|
}
|
||||||
eurekaProps.setProperty(pn, eurekaProperties.getProperty(propertyName));
|
eurekaProps.setProperty(pn, eurekaProperties.getProperty(propertyName));
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
eurekaProperties.forEach(
|
||||||
|
(n, v) -> {
|
||||||
|
String propertyName = (String) n;
|
||||||
|
String pn = null;
|
||||||
|
if (propertyName.charAt(ecl - 1) == Consts.S.DOT) {
|
||||||
|
pn = propertyName.substring(ecl);
|
||||||
|
} else if (propertyName.charAt(eil - 1) == Consts.S.DOT) {
|
||||||
|
pn = propertyName.substring(eil);
|
||||||
|
} else {
|
||||||
|
pn = propertyName.substring(el);
|
||||||
|
}
|
||||||
|
if (pn.indexOf(Consts.S.DASH) > -1) {
|
||||||
|
pn = PropertiesUtils.normalize(pn);
|
||||||
|
}
|
||||||
|
eurekaProps.put(pn, v);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
InetUtils inetUtils = null;
|
InetUtils inetUtils = null;
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public abstract class FizzNacosHelper {
|
|||||||
public static FizzNacosServiceRegistration getServiceRegistration(ApplicationContext applicationContext, Properties nacosProperties) {
|
public static FizzNacosServiceRegistration getServiceRegistration(ApplicationContext applicationContext, Properties nacosProperties) {
|
||||||
|
|
||||||
Properties ps = new Properties();
|
Properties ps = new Properties();
|
||||||
for (String propertyName : nacosProperties.stringPropertyNames()) {
|
/*for (String propertyName : nacosProperties.stringPropertyNames()) {
|
||||||
String propertyValue = nacosProperties.getProperty(propertyName);
|
String propertyValue = nacosProperties.getProperty(propertyName);
|
||||||
if (propertyName.endsWith(PropertyKeyConst.USERNAME)) {
|
if (propertyName.endsWith(PropertyKeyConst.USERNAME)) {
|
||||||
ps.setProperty(PropertyKeyConst.USERNAME, propertyValue);
|
ps.setProperty(PropertyKeyConst.USERNAME, propertyValue);
|
||||||
@@ -59,7 +59,24 @@ public abstract class FizzNacosHelper {
|
|||||||
}
|
}
|
||||||
ps.setProperty(pn, propertyValue);
|
ps.setProperty(pn, propertyValue);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
nacosProperties.forEach(
|
||||||
|
(n, propertyValue) -> {
|
||||||
|
String propertyName = (String) n;
|
||||||
|
if (propertyName.endsWith(PropertyKeyConst.USERNAME)) {
|
||||||
|
ps.put(PropertyKeyConst.USERNAME, propertyValue);
|
||||||
|
} else if (propertyName.endsWith(PropertyKeyConst.PASSWORD)) {
|
||||||
|
ps.put(PropertyKeyConst.PASSWORD, propertyValue);
|
||||||
|
} else {
|
||||||
|
String pn = propertyName.substring(ndl);
|
||||||
|
if (pn.indexOf(Consts.S.DASH) > -1) {
|
||||||
|
pn = PropertiesUtils.normalize(pn);
|
||||||
|
}
|
||||||
|
ps.put(pn, propertyValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
FizzNacosProperties fizzNacosProperties = new FizzNacosProperties(ps);
|
FizzNacosProperties fizzNacosProperties = new FizzNacosProperties(ps);
|
||||||
PropertiesUtils.setBeanPropertyValue(fizzNacosProperties, ps);
|
PropertiesUtils.setBeanPropertyValue(fizzNacosProperties, ps);
|
||||||
|
|||||||
@@ -24,13 +24,29 @@ import com.alibaba.nacos.api.exception.NacosException;
|
|||||||
import com.alibaba.nacos.api.naming.NamingService;
|
import com.alibaba.nacos.api.naming.NamingService;
|
||||||
import com.alibaba.nacos.api.naming.pojo.Instance;
|
import com.alibaba.nacos.api.naming.pojo.Instance;
|
||||||
import com.alibaba.nacos.api.naming.pojo.ListView;
|
import com.alibaba.nacos.api.naming.pojo.ListView;
|
||||||
|
import com.alibaba.nacos.client.naming.cache.ServiceInfoHolder;
|
||||||
|
import com.alibaba.nacos.client.naming.core.ServerListManager;
|
||||||
|
import com.alibaba.nacos.client.naming.core.ServiceInfoUpdateService;
|
||||||
|
import com.alibaba.nacos.client.naming.remote.NamingClientProxyDelegate;
|
||||||
|
import com.alibaba.nacos.client.naming.remote.gprc.NamingGrpcClientProxy;
|
||||||
|
import com.alibaba.nacos.client.naming.remote.gprc.redo.NamingGrpcRedoService;
|
||||||
|
import com.alibaba.nacos.client.naming.remote.http.NamingHttpClientProxy;
|
||||||
|
import com.alibaba.nacos.common.remote.client.Connection;
|
||||||
|
import com.alibaba.nacos.common.remote.client.RpcClientStatus;
|
||||||
|
import com.alibaba.nacos.common.remote.client.grpc.GrpcClient;
|
||||||
|
import com.alibaba.nacos.common.utils.ThreadUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import we.service_registry.FizzServiceRegistration;
|
import we.service_registry.FizzServiceRegistration;
|
||||||
import we.util.Consts;
|
import we.util.Consts;
|
||||||
|
import we.util.ReflectionUtils;
|
||||||
import we.util.Utils;
|
import we.util.Utils;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
import static com.alibaba.nacos.client.utils.LogUtils.NAMING_LOGGER;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author hongqiaowei
|
* @author hongqiaowei
|
||||||
@@ -67,8 +83,58 @@ public class FizzNacosServiceRegistration extends FizzServiceRegistration {
|
|||||||
return namingService;
|
return namingService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
ServiceInfoHolder serviceInfoHolder = (ServiceInfoHolder) ReflectionUtils.get(namingService, "serviceInfoHolder");
|
||||||
|
NamingClientProxyDelegate namingClientProxyDelegate = (NamingClientProxyDelegate) ReflectionUtils.get(namingService, "clientProxy");
|
||||||
|
try {
|
||||||
|
serviceInfoHolder.shutdown();
|
||||||
|
ServiceInfoUpdateService serviceInfoUpdateService = (ServiceInfoUpdateService) ReflectionUtils.get(namingClientProxyDelegate, "serviceInfoUpdateService");
|
||||||
|
serviceInfoUpdateService.shutdown();
|
||||||
|
ServerListManager serverListManager = (ServerListManager) ReflectionUtils.get(namingClientProxyDelegate, "serverListManager");
|
||||||
|
serverListManager.shutdown();
|
||||||
|
NamingHttpClientProxy namingHttpClientProxy = (NamingHttpClientProxy) ReflectionUtils.get(namingClientProxyDelegate, "httpClientProxy");
|
||||||
|
namingHttpClientProxy.shutdown();
|
||||||
|
NamingGrpcClientProxy namingGrpcClientProxy = (NamingGrpcClientProxy) ReflectionUtils.get(namingClientProxyDelegate, "grpcClientProxy");
|
||||||
|
|
||||||
|
GrpcClient grpcClient = (GrpcClient) ReflectionUtils.get(namingGrpcClientProxy, "rpcClient");
|
||||||
|
|
||||||
|
AtomicReference<RpcClientStatus> rpcClientStatus = (AtomicReference<RpcClientStatus>) ReflectionUtils.get(grpcClient, "rpcClientStatus");
|
||||||
|
rpcClientStatus.set(RpcClientStatus.SHUTDOWN);
|
||||||
|
LOGGER.info("shutdown {} grpc client ,set status to shutdown", getId());
|
||||||
|
|
||||||
|
ScheduledExecutorService clientEventExecutor = (ScheduledExecutorService) ReflectionUtils.get(grpcClient, "clientEventExecutor");
|
||||||
|
clientEventExecutor.shutdownNow();
|
||||||
|
LOGGER.info("shutdown {} client event executor {}", getId(), clientEventExecutor);
|
||||||
|
|
||||||
|
Connection currentConnection = (Connection) ReflectionUtils.get(grpcClient, "currentConnection");
|
||||||
|
if (currentConnection != null) {
|
||||||
|
ReflectionUtils.invokeMethod("closeConnection", grpcClient, currentConnection);
|
||||||
|
LOGGER.info("close {} current connection {}", getId(), currentConnection.getConnectionId());
|
||||||
|
}
|
||||||
|
|
||||||
|
NamingGrpcRedoService namingGrpcRedoService = (NamingGrpcRedoService) ReflectionUtils.get(namingGrpcClientProxy, "redoService");
|
||||||
|
namingGrpcRedoService.shutdown();
|
||||||
|
|
||||||
|
ScheduledExecutorService scheduledExecutorService = (ScheduledExecutorService) ReflectionUtils.get(namingClientProxyDelegate, "executorService");
|
||||||
|
ThreadUtils.shutdownThreadPool(scheduledExecutorService, NAMING_LOGGER);
|
||||||
|
|
||||||
|
LOGGER.info("nacos {} client resource is closed", getId());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error("nacos {} naming service shutdown exception", getId(), e);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void shutdownClient() {
|
protected void shutdownClient() {
|
||||||
|
/*try {
|
||||||
|
namingService.shutDown();
|
||||||
|
} catch (NacosException e) {
|
||||||
|
LOGGER.error("nacos {} naming service shutdown exception", getId(), e);
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -110,6 +110,8 @@ public abstract class WebUtils {
|
|||||||
|
|
||||||
public static final String FIZZ_REQUEST = "fr@";
|
public static final String FIZZ_REQUEST = "fr@";
|
||||||
|
|
||||||
|
public static final String FAV_REQUEST = "fa@";
|
||||||
|
|
||||||
public static final String BODY_ENCRYPT = "b-ecyt";
|
public static final String BODY_ENCRYPT = "b-ecyt";
|
||||||
|
|
||||||
public static final String ORIGINAL_ERROR = "origerr@";
|
public static final String ORIGINAL_ERROR = "origerr@";
|
||||||
@@ -118,6 +120,10 @@ public abstract class WebUtils {
|
|||||||
private WebUtils() {
|
private WebUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isFavReq(ServerWebExchange exchange) {
|
||||||
|
return exchange.getAttribute(FAV_REQUEST) != null;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isAdminReq(ServerWebExchange exchange) {
|
public static boolean isAdminReq(ServerWebExchange exchange) {
|
||||||
return exchange.getAttribute(ADMIN_REQUEST) != null;
|
return exchange.getAttribute(ADMIN_REQUEST) != null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>fizz-gateway-community</artifactId>
|
<artifactId>fizz-gateway-community</artifactId>
|
||||||
<groupId>com.fizzgate</groupId>
|
<groupId>com.fizzgate</groupId>
|
||||||
<version>2.6.4</version>
|
<version>2.6.5-beta1</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>fizz-gateway-community</artifactId>
|
<artifactId>fizz-gateway-community</artifactId>
|
||||||
<groupId>com.fizzgate</groupId>
|
<groupId>com.fizzgate</groupId>
|
||||||
<version>2.6.4</version>
|
<version>2.6.5-beta1</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@@ -37,7 +37,7 @@
|
|||||||
<artifactId>fizz-gateway-community</artifactId>
|
<artifactId>fizz-gateway-community</artifactId>
|
||||||
<name>${project.artifactId}</name>
|
<name>${project.artifactId}</name>
|
||||||
<description>fizz gateway community</description>
|
<description>fizz gateway community</description>
|
||||||
<version>2.6.4</version>
|
<version>2.6.5-beta1</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<modules>
|
<modules>
|
||||||
<module>fizz-common</module>
|
<module>fizz-common</module>
|
||||||
|
|||||||
Reference in New Issue
Block a user