From a31cc6ee70e517fdc408b3b888ded862bca5987a Mon Sep 17 00:00:00 2001 From: hongqiaowei Date: Tue, 7 Jun 2022 18:32:47 +0800 Subject: [PATCH 1/7] FlowStat is optional --- .../we/controller/CacheCheckController.java | 3 +- .../main/java/we/filter/FizzWebFilter.java | 2 +- .../java/we/filter/FlowControlFilter.java | 50 ++++++++++++------- fizz-core/src/main/java/we/util/WebUtils.java | 6 +++ 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/fizz-core/src/main/java/we/controller/CacheCheckController.java b/fizz-core/src/main/java/we/controller/CacheCheckController.java index 4f0aa71..7d62fa6 100644 --- a/fizz-core/src/main/java/we/controller/CacheCheckController.java +++ b/fizz-core/src/main/java/we/controller/CacheCheckController.java @@ -18,6 +18,7 @@ package we.controller; 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.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -74,7 +75,7 @@ public class CacheCheckController { @Resource private CircuitBreakManager circuitBreakManager; - @Resource + @Autowired(required = false) private FlowStat flowStat; @GetMapping("/gatewayGroups") diff --git a/fizz-core/src/main/java/we/filter/FizzWebFilter.java b/fizz-core/src/main/java/we/filter/FizzWebFilter.java index c348584..2f3b21a 100644 --- a/fizz-core/src/main/java/we/filter/FizzWebFilter.java +++ b/fizz-core/src/main/java/we/filter/FizzWebFilter.java @@ -31,7 +31,7 @@ public abstract class FizzWebFilter implements WebFilter { @Override public Mono 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); } else { return doFilter(exchange, chain); diff --git a/fizz-core/src/main/java/we/filter/FlowControlFilter.java b/fizz-core/src/main/java/we/filter/FlowControlFilter.java index 637abdf..77c4c43 100644 --- a/fizz-core/src/main/java/we/filter/FlowControlFilter.java +++ b/fizz-core/src/main/java/we/filter/FlowControlFilter.java @@ -78,6 +78,11 @@ public class FlowControlFilter extends FizzWebFilter { private static final String qps = "qps"; + private static final String favPath = "/favicon.ico"; + + + + @Resource private FlowControlFilterProperties flowControlFilterProperties; @@ -111,28 +116,37 @@ public class FlowControlFilter extends FizzWebFilter { ServerHttpRequest request = exchange.getRequest(); String path = request.getPath().value(); - int secFS = path.indexOf(Consts.S.FORWARD_SLASH, 1); - if (secFS == -1) { - return WebUtils.responseError(exchange, HttpStatus.INTERNAL_SERVER_ERROR.value(), "request path should like /optional-prefix/service-name/real-biz-path"); + boolean adminReq = false, proxyTestReq = false, fizzApiReq = false, favReq = false; + if (path.equals(favPath)) { + exchange.getAttributes().put(WebUtils.FAV_REQUEST, Consts.S.EMPTY); + favReq = true; } - String service = path.substring(1, secFS); - boolean adminReq = false, proxyTestReq = false, fizzApiReq = false; - 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); + + String service = null; + if (!favReq) { + int secFS = path.indexOf(Consts.S.FORWARD_SLASH, 1); + if (secFS == -1) { + return WebUtils.responseError(exchange, HttpStatus.INTERNAL_SERVER_ERROR.value(), "request path should like /optional-prefix/service-name/real-biz-path"); } + 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 (flowControlFilterProperties.isFlowControl() && !adminReq && !proxyTestReq && !fizzApiReq) { + if (!favReq && flowControlFilterProperties.isFlowControl() && !adminReq && !proxyTestReq && !fizzApiReq) { String traceId = WebUtils.getTraceId(exchange); LogService.setBizId(traceId); if (!apiConfigService.serviceConfigMap.containsKey(service)) { diff --git a/fizz-core/src/main/java/we/util/WebUtils.java b/fizz-core/src/main/java/we/util/WebUtils.java index d02f8f2..983ca76 100644 --- a/fizz-core/src/main/java/we/util/WebUtils.java +++ b/fizz-core/src/main/java/we/util/WebUtils.java @@ -110,6 +110,8 @@ public abstract class WebUtils { 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 ORIGINAL_ERROR = "origerr@"; @@ -118,6 +120,10 @@ public abstract class WebUtils { private WebUtils() { } + public static boolean isFavReq(ServerWebExchange exchange) { + return exchange.getAttribute(FAV_REQUEST) != null; + } + public static boolean isAdminReq(ServerWebExchange exchange) { return exchange.getAttribute(ADMIN_REQUEST) != null; } From 73b6e56f537eaf1161dc76e4a74a4134b95a23dc Mon Sep 17 00:00:00 2001 From: hongqiaowei Date: Wed, 8 Jun 2022 12:29:57 +0800 Subject: [PATCH 2/7] Comment dedicated-line config --- .../src/main/resources/application.yml | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/fizz-bootstrap/src/main/resources/application.yml b/fizz-bootstrap/src/main/resources/application.yml index c1efce3..2474eba 100644 --- a/fizz-bootstrap/src/main/resources/application.yml +++ b/fizz-bootstrap/src/main/resources/application.yml @@ -116,19 +116,19 @@ fizz: code-field: "msgCode" message-field: "message" - dedicated-line: - server: - enable: true - client: - enable: true - port: 8601 - request: - timeliness: 300 # default 300 sec - timeout: 0 # default no timeout - retry-count: 0 # default no retry - retry-interval: 0 # default no retry interval - crypto: true # if true, client will encrypt request body and decrypt response body - service-registration: +# dedicated-line: +# server: +# enable: true +# client: +# enable: true +# port: 8601 +# request: +# timeliness: 300 # default 300 sec +# timeout: 0 # default no timeout +# retry-count: 0 # default no retry +# retry-interval: 0 # default no retry interval +# crypto: true # if true, client will encrypt request body and decrypt response body +# service-registration: # eureka: # server-port: 8601 # client: From e9ef6cca926d4d301980c666bfb5207d818e0467 Mon Sep 17 00:00:00 2001 From: hongqiaowei Date: Thu, 9 Jun 2022 18:37:27 +0800 Subject: [PATCH 3/7] Fallback and go on when nacos server down --- .../src/main/resources/application.yml | 2 + .../main/java/we/util/PropertiesUtils.java | 22 ++++++- .../main/java/we/util/ReflectionUtils.java | 7 ++ .../src/main/java/we/config/SystemConfig.java | 7 ++ .../DedicatedLineInfoService.java | 20 ++++-- .../dedicated_line/DedicatedLineService.java | 20 ++++-- .../DedicatedLineServiceRegistration.java | 21 ++++-- .../DedicatedLineWebServer.java | 37 ++++++----- .../RegistryCenterService.java | 28 ++++++-- .../eureka/FizzEurekaHelper.java | 22 ++++++- .../nacos/FizzNacosHelper.java | 21 +++++- .../nacos/FizzNacosServiceRegistration.java | 66 +++++++++++++++++++ 12 files changed, 229 insertions(+), 44 deletions(-) diff --git a/fizz-bootstrap/src/main/resources/application.yml b/fizz-bootstrap/src/main/resources/application.yml index 2474eba..7ca2e1a 100644 --- a/fizz-bootstrap/src/main/resources/application.yml +++ b/fizz-bootstrap/src/main/resources/application.yml @@ -116,6 +116,8 @@ fizz: code-field: "msgCode" message-field: "message" + fast-fail-when-registry-center-down: false + # dedicated-line: # server: # enable: true diff --git a/fizz-common/src/main/java/we/util/PropertiesUtils.java b/fizz-common/src/main/java/we/util/PropertiesUtils.java index db7c46b..4260b77 100644 --- a/fizz-common/src/main/java/we/util/PropertiesUtils.java +++ b/fizz-common/src/main/java/we/util/PropertiesUtils.java @@ -63,7 +63,7 @@ public abstract class PropertiesUtils { public static void setBeanPropertyValue(Object bean, Properties properties, Map> propertyTypeHint) { BeanWrapperImpl beanWrapper = new BeanWrapperImpl(bean); - for (String propertyName : properties.stringPropertyNames()) { + /*for (String propertyName : properties.stringPropertyNames()) { if (beanWrapper.isWritableProperty(propertyName)) { beanWrapper.setPropertyValue(propertyName, properties.get(propertyName)); } 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)); + } + } + } + } + ); } } diff --git a/fizz-common/src/main/java/we/util/ReflectionUtils.java b/fizz-common/src/main/java/we/util/ReflectionUtils.java index 3c95b8a..8e3b86d 100644 --- a/fizz-common/src/main/java/we/util/ReflectionUtils.java +++ b/fizz-common/src/main/java/we/util/ReflectionUtils.java @@ -18,6 +18,7 @@ package we.util; import java.lang.reflect.Field; +import java.lang.reflect.Method; /** * @author hongqiaowei @@ -39,4 +40,10 @@ public abstract class ReflectionUtils extends org.springframework.util.Reflectio makeAccessible(f); 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); + } } diff --git a/fizz-core/src/main/java/we/config/SystemConfig.java b/fizz-core/src/main/java/we/config/SystemConfig.java index 649542b..7965139 100644 --- a/fizz-core/src/main/java/we/config/SystemConfig.java +++ b/fizz-core/src/main/java/we/config/SystemConfig.java @@ -122,6 +122,13 @@ public class SystemConfig { private String fizzDedicatedLineClientId; + @Value("${fizz.fast-fail-when-registry-center-down:false}") + private boolean fastFailWhenRegistryCenterDown; + + public boolean isFastFailWhenRegistryCenterDown() { + return fastFailWhenRegistryCenterDown; + } + public int fizzDedicatedLineClientRequestTimeout() { return fizzDedicatedLineClientRequestTimeout; } diff --git a/fizz-core/src/main/java/we/dedicated_line/DedicatedLineInfoService.java b/fizz-core/src/main/java/we/dedicated_line/DedicatedLineInfoService.java index c0e1f51..b3822d1 100644 --- a/fizz-core/src/main/java/we/dedicated_line/DedicatedLineInfoService.java +++ b/fizz-core/src/main/java/we/dedicated_line/DedicatedLineInfoService.java @@ -19,6 +19,7 @@ package we.dedicated_line; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.data.redis.core.ReactiveStringRedisTemplate; import org.springframework.stereotype.Service; @@ -50,15 +51,20 @@ public class DedicatedLineInfoService { @Resource(name = AggregateRedisConfig.AGGREGATE_REACTIVE_REDIS_TEMPLATE) private ReactiveStringRedisTemplate rt; + @Value("${fizz.dedicated-line.client.enable:true}") + private boolean fizzDedicatedLineClientEnable; + @PostConstruct public void init() throws Throwable { - Result result = initDedicatedLineInfo(); - if (result.code == Result.FAIL) { - throw new RuntimeException(result.msg, result.t); - } - result = lsnApiPairingInfoChange(); - if (result.code == Result.FAIL) { - throw new RuntimeException(result.msg, result.t); + if (fizzDedicatedLineClientEnable) { + Result result = initDedicatedLineInfo(); + if (result.code == Result.FAIL) { + throw new RuntimeException(result.msg, result.t); + } + result = lsnApiPairingInfoChange(); + if (result.code == Result.FAIL) { + throw new RuntimeException(result.msg, result.t); + } } } diff --git a/fizz-core/src/main/java/we/dedicated_line/DedicatedLineService.java b/fizz-core/src/main/java/we/dedicated_line/DedicatedLineService.java index d04ee83..a88728b 100644 --- a/fizz-core/src/main/java/we/dedicated_line/DedicatedLineService.java +++ b/fizz-core/src/main/java/we/dedicated_line/DedicatedLineService.java @@ -19,6 +19,7 @@ package we.dedicated_line; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.data.redis.core.ReactiveStringRedisTemplate; import org.springframework.http.HttpMethod; @@ -54,15 +55,20 @@ public class DedicatedLineService { @Resource(name = AggregateRedisConfig.AGGREGATE_REACTIVE_REDIS_TEMPLATE) private ReactiveStringRedisTemplate rt; + @Value("${fizz.dedicated-line.server.enable:true}") + private boolean fizzDedicatedLineServerEnable; + @PostConstruct public void init() throws Throwable { - Result result = initDedicatedLine(); - if (result.code == Result.FAIL) { - throw new RuntimeException(result.msg, result.t); - } - result = lsnDedicatedLineChange(); - if (result.code == Result.FAIL) { - throw new RuntimeException(result.msg, result.t); + if (fizzDedicatedLineServerEnable) { + Result result = initDedicatedLine(); + if (result.code == Result.FAIL) { + throw new RuntimeException(result.msg, result.t); + } + result = lsnDedicatedLineChange(); + if (result.code == Result.FAIL) { + throw new RuntimeException(result.msg, result.t); + } } } diff --git a/fizz-core/src/main/java/we/dedicated_line/DedicatedLineServiceRegistration.java b/fizz-core/src/main/java/we/dedicated_line/DedicatedLineServiceRegistration.java index 4869c0a..19e4283 100644 --- a/fizz-core/src/main/java/we/dedicated_line/DedicatedLineServiceRegistration.java +++ b/fizz-core/src/main/java/we/dedicated_line/DedicatedLineServiceRegistration.java @@ -21,6 +21,7 @@ import com.alibaba.cloud.nacos.discovery.NacosDiscoveryAutoConfiguration; import lombok.SneakyThrows; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; 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.annotation.Configuration; import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.PropertySource; import we.config.SystemConfig; import we.service_registry.FizzServiceRegistration; @@ -53,15 +55,22 @@ public class DedicatedLineServiceRegistration implements ApplicationListener propertySource : env.getPropertySources()) { - if (propertySource instanceof OriginTrackedMapPropertySource) { - OriginTrackedMapPropertySource originTrackedMapPropertySource = (OriginTrackedMapPropertySource) propertySource; + // if (propertySource instanceof OriginTrackedMapPropertySource) { + if (MapPropertySource.class.isAssignableFrom(propertySource.getClass())) { + MapPropertySource originTrackedMapPropertySource = (MapPropertySource) propertySource; String[] propertyNames = originTrackedMapPropertySource.getPropertyNames(); for (String propertyName : propertyNames) { if (propertyName.length() > 55) { @@ -97,8 +107,9 @@ public class DedicatedLineServiceRegistration implements ApplicationListener propertySource : env.getPropertySources()) { - if (propertySource instanceof OriginTrackedMapPropertySource) { - OriginTrackedMapPropertySource originTrackedMapPropertySource = (OriginTrackedMapPropertySource) propertySource; + // if (propertySource instanceof OriginTrackedMapPropertySource) { + if (MapPropertySource.class.isAssignableFrom(propertySource.getClass())) { + MapPropertySource originTrackedMapPropertySource = (MapPropertySource) propertySource; String[] propertyNames = originTrackedMapPropertySource.getPropertyNames(); for (String propertyName : propertyNames) { if (propertyName.length() > 64) { diff --git a/fizz-core/src/main/java/we/dedicated_line/DedicatedLineWebServer.java b/fizz-core/src/main/java/we/dedicated_line/DedicatedLineWebServer.java index f99601d..6698a53 100644 --- a/fizz-core/src/main/java/we/dedicated_line/DedicatedLineWebServer.java +++ b/fizz-core/src/main/java/we/dedicated_line/DedicatedLineWebServer.java @@ -58,26 +58,33 @@ public class DedicatedLineWebServer { @Value("${fizz.dedicated-line.client.port:8601}") private int port = 8601; + @Value("${fizz.dedicated-line.client.enable:true}") + private boolean fizzDedicatedLineClientEnable; + @PostConstruct public void start() { - HttpWebHandlerAdapter adapter = (HttpWebHandlerAdapter) httpHandler; - NettyReactiveWebServerFactory factory = new NettyReactiveWebServerFactory(port); - server = factory.getWebServer( - new DedicatedLineHttpHandler( - applicationContext, - new DefaultWebSessionManager(), - adapter.getCodecConfigurer(), - adapter.getLocaleContextResolver(), - adapter.getForwardedHeaderTransformer() - ) - ); - server.start(); - log.info("fizz dedicated line web server listen on {}", port); - applicationContext.publishEvent(new DedicatedLineWebServerInitializedEvent(server, applicationContext)); + if (fizzDedicatedLineClientEnable) { + HttpWebHandlerAdapter adapter = (HttpWebHandlerAdapter) httpHandler; + NettyReactiveWebServerFactory factory = new NettyReactiveWebServerFactory(port); + server = factory.getWebServer( + new DedicatedLineHttpHandler( + applicationContext, + new DefaultWebSessionManager(), + adapter.getCodecConfigurer(), + adapter.getLocaleContextResolver(), + adapter.getForwardedHeaderTransformer() + ) + ); + server.start(); + log.info("fizz dedicated line web server listen on {}", port); + applicationContext.publishEvent(new DedicatedLineWebServerInitializedEvent(server, applicationContext)); + } } @PreDestroy public void stop() { - server.stop(); + if (server != null) { + server.stop(); + } } } diff --git a/fizz-core/src/main/java/we/service_registry/RegistryCenterService.java b/fizz-core/src/main/java/we/service_registry/RegistryCenterService.java index bceff00..670eb3a 100644 --- a/fizz-core/src/main/java/we/service_registry/RegistryCenterService.java +++ b/fizz-core/src/main/java/we/service_registry/RegistryCenterService.java @@ -27,6 +27,7 @@ import org.springframework.stereotype.Service; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import we.config.AggregateRedisConfig; +import we.config.SystemConfig; import we.util.Consts; import we.util.JacksonUtils; import we.util.Result; @@ -42,7 +43,7 @@ import java.util.Map; */ @Service -public class RegistryCenterService implements ApplicationListener { +public class RegistryCenterService implements ApplicationListener { private static final Logger LOGGER = LoggerFactory.getLogger(RegistryCenterService.class); @@ -54,6 +55,9 @@ public class RegistryCenterService implements ApplicationListener result = initRegistryCenter(); @@ -80,9 +84,19 @@ public class RegistryCenterService implements ApplicationListener { + 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; try { diff --git a/fizz-core/src/main/java/we/service_registry/nacos/FizzNacosHelper.java b/fizz-core/src/main/java/we/service_registry/nacos/FizzNacosHelper.java index 1d93e0f..8f70636 100644 --- a/fizz-core/src/main/java/we/service_registry/nacos/FizzNacosHelper.java +++ b/fizz-core/src/main/java/we/service_registry/nacos/FizzNacosHelper.java @@ -46,7 +46,7 @@ public abstract class FizzNacosHelper { public static FizzNacosServiceRegistration getServiceRegistration(ApplicationContext applicationContext, Properties nacosProperties) { Properties ps = new Properties(); - for (String propertyName : nacosProperties.stringPropertyNames()) { + /*for (String propertyName : nacosProperties.stringPropertyNames()) { String propertyValue = nacosProperties.getProperty(propertyName); if (propertyName.endsWith(PropertyKeyConst.USERNAME)) { ps.setProperty(PropertyKeyConst.USERNAME, propertyValue); @@ -59,7 +59,24 @@ public abstract class FizzNacosHelper { } 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); PropertiesUtils.setBeanPropertyValue(fizzNacosProperties, ps); diff --git a/fizz-core/src/main/java/we/service_registry/nacos/FizzNacosServiceRegistration.java b/fizz-core/src/main/java/we/service_registry/nacos/FizzNacosServiceRegistration.java index 59c3e9e..1cd5e25 100644 --- a/fizz-core/src/main/java/we/service_registry/nacos/FizzNacosServiceRegistration.java +++ b/fizz-core/src/main/java/we/service_registry/nacos/FizzNacosServiceRegistration.java @@ -24,13 +24,29 @@ import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.pojo.Instance; 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 we.service_registry.FizzServiceRegistration; import we.util.Consts; +import we.util.ReflectionUtils; import we.util.Utils; import java.util.Collections; 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 @@ -67,8 +83,58 @@ public class FizzNacosServiceRegistration extends FizzServiceRegistration { 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 = (AtomicReference) 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 protected void shutdownClient() { + /*try { + namingService.shutDown(); + } catch (NacosException e) { + LOGGER.error("nacos {} naming service shutdown exception", getId(), e); + throw new RuntimeException(e); + }*/ } @Override From f2652175d964ef430eaf49a477cbadc5f9597643 Mon Sep 17 00:00:00 2001 From: dxfeng10 Date: Wed, 8 Jun 2022 09:51:40 +0800 Subject: [PATCH 4/7] Update README.md (cherry picked from commit 1d15c3462d410450f2b39ccc7cdff01f99650061) --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 9e76be7..99c19bb 100644 --- a/README.md +++ b/README.md @@ -260,6 +260,29 @@ Fizz官方微信群(请加入群之后再询问群主) [高阶程序员必备技能:Fizz Gateway网关的二次开发](https://my.oschina.net/linwaiwai/blog/4696133) +[Fizz网关入门教程-安装](https://zhuanlan.zhihu.com/p/501305059) + +[Fizz网关入门教程-路由初体验](https://zhuanlan.zhihu.com/p/501381970) + +[Fizz网关入门教程-权限校验](https://zhuanlan.zhihu.com/p/501384396) + +[Fizz网关入门教程-快速聚合多接口,提高页面数据的加载速度](https://zhuanlan.zhihu.com/p/501387154) + +[Fizz网关入门教程-服务编排,祭出终结BFF层的大杀器](https://zhuanlan.zhihu.com/p/501389075) + +[企业级微服务API网关Fizz-常用插件介绍](https://zhuanlan.zhihu.com/p/513656382) + +[企业级微服务API网关Fizz-如何自定义插件](https://zhuanlan.zhihu.com/p/513662893) + +[企业级微服务API网关Fizz-服务编排内置函数](https://zhuanlan.zhihu.com/p/513404417) + +[Fizz企业级微服务API网关进阶系列教程-服务编排处理列表数据(上)-展开与合并](https://zhuanlan.zhihu.com/p/515056309) + +[Fizz企业级微服务API网关进阶系列教程-服务编排处理列表数据(中)-数据提取与数据关联](https://zhuanlan.zhihu.com/p/515070075) + +[Fizz企业级微服务API网关进阶系列教程-服务编排处理列表数据(下)-字段重命名&字段移除](https://zhuanlan.zhihu.com/p/515509832) + + ## 授权说明 1. 网关核心项目fizz-gateway-community社区版本以GNU v3的方式进行的开放,在遵循GNU协议的非商业化项目中可以免费使用。 From 10a93e04c6c0188ef886b6df202c301b06460943 Mon Sep 17 00:00:00 2001 From: dxfeng10 Date: Wed, 8 Jun 2022 09:52:29 +0800 Subject: [PATCH 5/7] Update README.en-us.md (cherry picked from commit 3d51b6f2b526acce6ec0c6f5ef89b0e532407c74) --- README.en-us.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.en-us.md b/README.en-us.md index 344cfae..0c54926 100644 --- a/README.en-us.md +++ b/README.en-us.md @@ -261,6 +261,28 @@ Fizz官方技术交流③群:512164278 [高阶程序员必备技能:Fizz Gateway网关的二次开发](https://my.oschina.net/linwaiwai/blog/4696133) +[Fizz网关入门教程-安装](https://zhuanlan.zhihu.com/p/501305059) + +[Fizz网关入门教程-路由初体验](https://zhuanlan.zhihu.com/p/501381970) + +[Fizz网关入门教程-权限校验](https://zhuanlan.zhihu.com/p/501384396) + +[Fizz网关入门教程-快速聚合多接口,提高页面数据的加载速度](https://zhuanlan.zhihu.com/p/501387154) + +[Fizz网关入门教程-服务编排,祭出终结BFF层的大杀器](https://zhuanlan.zhihu.com/p/501389075) + +[企业级微服务API网关Fizz-常用插件介绍](https://zhuanlan.zhihu.com/p/513656382) + +[企业级微服务API网关Fizz-如何自定义插件](https://zhuanlan.zhihu.com/p/513662893) + +[企业级微服务API网关Fizz-服务编排内置函数](https://zhuanlan.zhihu.com/p/513404417) + +[Fizz企业级微服务API网关进阶系列教程-服务编排处理列表数据(上)-展开与合并](https://zhuanlan.zhihu.com/p/515056309) + +[Fizz企业级微服务API网关进阶系列教程-服务编排处理列表数据(中)-数据提取与数据关联](https://zhuanlan.zhihu.com/p/515070075) + +[Fizz企业级微服务API网关进阶系列教程-服务编排处理列表数据(下)-字段重命名&字段移除](https://zhuanlan.zhihu.com/p/515509832) + ## Authorization instructions 1. The fizz-gateway-community community version of the gateway core project is opened in the form of GNU V3 and can be used free of charge in non-commercial projects following the GNU protocol. From 58c8d1b163433a9be3e25a973e0a4186b2812754 Mon Sep 17 00:00:00 2001 From: linwaiwai Date: Thu, 9 Jun 2022 14:53:00 +0800 Subject: [PATCH 6/7] Update README.md (cherry picked from commit 81750bc305111f34e6a61d982467760cd8adcf31) --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 99c19bb..65edd02 100644 --- a/README.md +++ b/README.md @@ -285,10 +285,11 @@ Fizz官方微信群(请加入群之后再询问群主) ## 授权说明 -1. 网关核心项目fizz-gateway-community社区版本以GNU v3的方式进行的开放,在遵循GNU协议的非商业化项目中可以免费使用。 +1. 网关核心项目fizz-gateway-community社区版本以GNU v3的方式进行的开放,在遵循GNU协议的个人非商业化项目中可以免费使用。 2. 管理后台项目(fizz-manager-professional)作为商业版本仅开放二进制包 [免费下载](https://wj.qq.com/s2/8682608/8fe2/),而商业项目请注明公司名称联系我们(sale@fizzgate.com)进行授权,了解商业授权规则请点击[商业授权规则](https://github.com/wehotel/fizz-gateway-community/wiki/%E5%95%86%E4%B8%9A%E6%8E%88%E6%9D%83) +3. 在选择Fizz Gateway之前,我们强烈建议您先试用一下我们的DEMO站点,试用我们的产品,并且思考与自身的业务结合,并且考虑产品推行落地方式,在查阅我们的官网价格(https://www.fizzgate.com)之后再进一步与我们联系。 ## 系统截图 From ef7b5459b8b77abe5e33e3cdf8fe5e48548dd0e3 Mon Sep 17 00:00:00 2001 From: hongqiaowei Date: Fri, 10 Jun 2022 14:34:10 +0800 Subject: [PATCH 7/7] Release 2.6.5-beta1 --- fizz-bootstrap/pom.xml | 2 +- fizz-common/pom.xml | 2 +- fizz-core/pom.xml | 2 +- fizz-plugin/pom.xml | 2 +- fizz-spring-boot-starter/pom.xml | 2 +- pom.xml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fizz-bootstrap/pom.xml b/fizz-bootstrap/pom.xml index b504ac3..441d368 100644 --- a/fizz-bootstrap/pom.xml +++ b/fizz-bootstrap/pom.xml @@ -12,7 +12,7 @@ com.fizzgate fizz-bootstrap - 2.6.4 + 2.6.5-beta1 1.8 diff --git a/fizz-common/pom.xml b/fizz-common/pom.xml index afe40ab..f90d580 100644 --- a/fizz-common/pom.xml +++ b/fizz-common/pom.xml @@ -5,7 +5,7 @@ fizz-gateway-community com.fizzgate - 2.6.4 + 2.6.5-beta1 ../pom.xml 4.0.0 diff --git a/fizz-core/pom.xml b/fizz-core/pom.xml index c5c5c0a..5ba3cbc 100644 --- a/fizz-core/pom.xml +++ b/fizz-core/pom.xml @@ -5,7 +5,7 @@ fizz-gateway-community com.fizzgate - 2.6.4 + 2.6.5-beta1 ../pom.xml 4.0.0 diff --git a/fizz-plugin/pom.xml b/fizz-plugin/pom.xml index 5a08e35..e5ad632 100644 --- a/fizz-plugin/pom.xml +++ b/fizz-plugin/pom.xml @@ -5,7 +5,7 @@ fizz-gateway-community com.fizzgate - 2.6.4 + 2.6.5-beta1 ../pom.xml 4.0.0 diff --git a/fizz-spring-boot-starter/pom.xml b/fizz-spring-boot-starter/pom.xml index 65436cf..fee8e70 100644 --- a/fizz-spring-boot-starter/pom.xml +++ b/fizz-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ fizz-gateway-community com.fizzgate - 2.6.4 + 2.6.5-beta1 ../pom.xml 4.0.0 diff --git a/pom.xml b/pom.xml index 18f31b2..dc82cd4 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ fizz-gateway-community ${project.artifactId} fizz gateway community - 2.6.4 + 2.6.5-beta1 pom fizz-common