From 3282bae0179064d3888fa0d3412856112e60a4b3 Mon Sep 17 00:00:00 2001
From: zhong-jie <70501464+zhong-jie@users.noreply.github.com>
Date: Tue, 8 Jun 2021 14:29:27 +0800
Subject: [PATCH] update Nacos by using the Spring cloud version (#225)
---
.../java/we/FizzBootstrapApplication.java | 2 -
.../src/main/resources/application.yml | 32 ++----
.../src/main/resources/bootstrap.yml | 15 +++
.../src/main/resources/log4j2-spring.xml | 2 +
fizz-core/pom.xml | 19 ++--
.../java/we/config/AggregateRedisConfig.java | 33 ++----
.../AggregateRedisConfigProperties.java | 43 ++++++++
.../java/we/config/AppConfigProperties.java | 19 ++--
.../java/we/config/FlowStatSchedConfig.java | 23 ++--
.../config/FlowStatSchedConfigProperties.java | 42 ++++++++
.../we/config/RefreshLocalCacheConfig.java | 39 ++-----
.../RefreshLocalCacheConfigProperties.java | 54 ++++++++++
.../src/main/java/we/config/SystemConfig.java | 101 +++++++++---------
.../main/java/we/config/WebFluxConfig.java | 23 +---
.../we/config/WebFluxConfigProperties.java | 44 ++++++++
.../we/controller/FlowControlController.java | 6 +-
.../controller/ManagerConfigController.java | 4 +-
.../main/java/we/filter/AggregateFilter.java | 11 +-
.../we/filter/AggregateFilterProperties.java | 36 +++++++
.../main/java/we/filter/CallbackFilter.java | 17 +--
.../we/filter/CallbackFilterProperties.java | 39 +++++++
.../java/we/filter/FlowControlFilter.java | 10 +-
.../filter/FlowControlFilterProperties.java | 36 +++++++
.../main/java/we/filter/PreprocessFilter.java | 3 +
.../src/main/java/we/fizz/ConfigLoader.java | 9 +-
.../java/we/fizz/ConfigLoaderProperties.java | 36 +++++++
.../input/extension/request/RequestInput.java | 2 +-
.../java/we/log/RedisLogSendServiceImpl.java | 11 +-
.../java/we/plugin/auth/ApiConfigService.java | 31 ++----
.../auth/ApiConfigServiceProperties.java | 41 +++++++
.../java/we/plugin/stat/StatPluginFilter.java | 23 ++--
.../stat/StatPluginFilterProperties.java | 41 +++++++
.../main/java/we/proxy/CallbackService.java | 2 +-
.../we/proxy/DisableDiscoveryUriSelector.java | 2 +-
.../src/main/java/we/proxy/FizzWebClient.java | 4 +-
.../main/java/we/proxy/NacosUriSelector.java | 30 ++----
.../dubbo/ApacheDubboGenericService.java | 12 +--
.../ApacheDubboGenericServiceProperties.java | 35 ++++++
fizz-plugin/pom.xml | 14 +--
fizz-spring-boot-starter/pom.xml | 14 +--
pom.xml | 20 ++--
41 files changed, 654 insertions(+), 326 deletions(-)
create mode 100644 fizz-bootstrap/src/main/resources/bootstrap.yml
create mode 100644 fizz-core/src/main/java/we/config/AggregateRedisConfigProperties.java
create mode 100644 fizz-core/src/main/java/we/config/FlowStatSchedConfigProperties.java
create mode 100644 fizz-core/src/main/java/we/config/RefreshLocalCacheConfigProperties.java
create mode 100644 fizz-core/src/main/java/we/config/WebFluxConfigProperties.java
create mode 100644 fizz-core/src/main/java/we/filter/AggregateFilterProperties.java
create mode 100644 fizz-core/src/main/java/we/filter/CallbackFilterProperties.java
create mode 100644 fizz-core/src/main/java/we/filter/FlowControlFilterProperties.java
create mode 100644 fizz-core/src/main/java/we/fizz/ConfigLoaderProperties.java
create mode 100644 fizz-core/src/main/java/we/plugin/auth/ApiConfigServiceProperties.java
create mode 100644 fizz-core/src/main/java/we/plugin/stat/StatPluginFilterProperties.java
create mode 100644 fizz-core/src/main/java/we/proxy/dubbo/ApacheDubboGenericServiceProperties.java
diff --git a/fizz-bootstrap/src/main/java/we/FizzBootstrapApplication.java b/fizz-bootstrap/src/main/java/we/FizzBootstrapApplication.java
index 01c8c18..08e6e68 100644
--- a/fizz-bootstrap/src/main/java/we/FizzBootstrapApplication.java
+++ b/fizz-bootstrap/src/main/java/we/FizzBootstrapApplication.java
@@ -16,7 +16,6 @@
*/
package we;
-import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
@@ -180,7 +179,6 @@ import we.log.LogSendAppender;
QuartzAutoConfiguration.class
}
)
-@NacosPropertySource(dataId = "${nacos.config.data-id}", groupId = "${nacos.config.group}", autoRefreshed = true)
@EnableDiscoveryClient
public class FizzBootstrapApplication {
private static final Logger LOGGER = LoggerFactory.getLogger(FizzBootstrapApplication.class);
diff --git a/fizz-bootstrap/src/main/resources/application.yml b/fizz-bootstrap/src/main/resources/application.yml
index 84cf88d..3d9cedb 100644
--- a/fizz-bootstrap/src/main/resources/application.yml
+++ b/fizz-bootstrap/src/main/resources/application.yml
@@ -12,30 +12,6 @@ apollo:
enabled: false #use Apollo?
################################################### Apollo config end ###################################################
-# if you do not use Nacos, ignore the follow config
-################################################## Nacos config start ###################################################
-nacos:
- config:
- # if use Nacos config set this flag to true
- enabled: false #use Nacos Config? (default:false)
- # need replace
- server-addr: localhost:8848 #please input the nacos config server-addr (default:localhost:8848)
- auto-refresh: true
- group: fizz-gateway #please input the nacos config group (default:fizz-gateway)
- data-id: application #please input the nacos config data-id (default:application)
- type: PROPERTIES #please input the nacos config type (default:PROPERTIES)
- # need replace
- namespace: null #please input the nacos config type (default:null)
- discovery:
- # if use Nacos discovery set this flag to true
- enabled: false #use Nacos Discovery? (default:false)
- # need replace
- server-addr: localhost:8848 #please input the nacos discovery server-addr (default:localhost:8848)
- auto-register: true
- register:
- group-name: fizz-gateway #please input the nacos discovery register group-name (default:fizz-gateway)
-################################################### Nacos config end ####################################################
-
# if you do not use Eureka, ignore the follow config
################################################## Eureka config start ##################################################
eureka:
@@ -62,6 +38,14 @@ spring:
loadbalancer:
ribbon:
enabled: false
+ nacos:
+ discovery:
+ # if use Nacos discovery set this flag to true
+ enabled: false #use Nacos Discovery? (default:false)
+ # need replace
+ server-addr: localhost:8848 #please input the nacos discovery server-addr (default:localhost:8848)
+ namespace: null #please input the nacos config type (default:null)
+ group: fizz-gateway #please input the nacos discovery register group (default:fizz-gateway)
aggregate:
redis:
diff --git a/fizz-bootstrap/src/main/resources/bootstrap.yml b/fizz-bootstrap/src/main/resources/bootstrap.yml
new file mode 100644
index 0000000..04d834c
--- /dev/null
+++ b/fizz-bootstrap/src/main/resources/bootstrap.yml
@@ -0,0 +1,15 @@
+spring:
+ cloud:
+ nacos:
+ config:
+ # if use Nacos config set this flag to true
+ enabled: false #use Nacos Config? (default:false)
+ # need replace
+ server-addr: localhost:8848 #please input the nacos config server-addr (default:localhost:8848)
+ namespace: null #please input the nacos config type (default:null)
+ group: fizz-gateway #please input the nacos config group (default:fizz-gateway)
+ prefix: application #please input the nacos config data-id (default:application)
+ extension-configs[0]:
+ refresh: true
+ data-id: ${spring.cloud.nacos.config.prefix}
+ group: ${spring.cloud.nacos.config.group}
\ No newline at end of file
diff --git a/fizz-bootstrap/src/main/resources/log4j2-spring.xml b/fizz-bootstrap/src/main/resources/log4j2-spring.xml
index 20da16f..b5358b9 100644
--- a/fizz-bootstrap/src/main/resources/log4j2-spring.xml
+++ b/fizz-bootstrap/src/main/resources/log4j2-spring.xml
@@ -17,6 +17,8 @@
+
+
diff --git a/fizz-core/pom.xml b/fizz-core/pom.xml
index 0c71771..b220edf 100644
--- a/fizz-core/pom.xml
+++ b/fizz-core/pom.xml
@@ -136,19 +136,13 @@
- com.alibaba.boot
- nacos-config-spring-boot-starter
-
-
- org.springframework.boot
- spring-boot-starter-logging
-
-
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-config
- com.alibaba.boot
- nacos-discovery-spring-boot-starter
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
@@ -156,6 +150,11 @@
commons-pool2
+
+ com.github.ben-manes.caffeine
+ caffeine
+
+
org.springframework.boot
spring-boot-starter-data-redis-reactive
diff --git a/fizz-core/src/main/java/we/config/AggregateRedisConfig.java b/fizz-core/src/main/java/we/config/AggregateRedisConfig.java
index 748597b..04e39ed 100644
--- a/fizz-core/src/main/java/we/config/AggregateRedisConfig.java
+++ b/fizz-core/src/main/java/we/config/AggregateRedisConfig.java
@@ -17,9 +17,7 @@
package we.config;
-import com.alibaba.nacos.api.config.annotation.NacosValue;
import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -40,10 +38,11 @@ import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSeriali
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.session.data.redis.config.annotation.SpringSessionRedisConnectionFactory;
-
import we.log.LogSendAppender;
import we.log.RedisLogSendServiceImpl;
+import javax.annotation.Resource;
+
/**
* aggregate Redis config
*
@@ -59,17 +58,8 @@ public class AggregateRedisConfig extends RedisReactiveConfig {
private static final String SEND_LOG_TYPE_REDIS = "redis";
public static ProxyLettuceConnectionFactory proxyLettuceConnectionFactory;
- @NacosValue(value = "${send-log.open:false}", autoRefreshed = true)
- @Value("${send-log.open:false}")
- private boolean sendLogOpen;
-
- @NacosValue(value = "${send-log.channel:fizz_send_log_channel}", autoRefreshed = true)
- @Value("${send-log.channel:fizz_log_channel}")
- private String sendLogChannel;
-
- @NacosValue(value = "${send-log.type:redis}", autoRefreshed = true)
- @Value("${send-log.type:redis}")
- private String sendLogType;
+ @Resource
+ private AggregateRedisConfigProperties aggregateRedisConfigProperties;
@ConfigurationProperties(prefix = "aggregate.redis")
@Configuration(AGGREGATE_REACTIVE_REDIS_PROPERTIES)
@@ -84,7 +74,7 @@ public class AggregateRedisConfig extends RedisReactiveConfig {
@Bean(AGGREGATE_REACTIVE_REDIS_CONNECTION_FACTORY)
public ReactiveRedisConnectionFactory lettuceConnectionFactory() {
LettuceConnectionFactory lettuceConnectionFactory = (LettuceConnectionFactory) super.lettuceConnectionFactory();
- if (SEND_LOG_TYPE_REDIS.equals(sendLogType)) {
+ if (SEND_LOG_TYPE_REDIS.equals(aggregateRedisConfigProperties.getSendLogType())) {
proxyLettuceConnectionFactory = new ProxyLettuceConnectionFactory(lettuceConnectionFactory);
proxyLettuceConnectionFactory.afterPropertiesSet();
return proxyLettuceConnectionFactory;
@@ -102,9 +92,10 @@ public class AggregateRedisConfig extends RedisReactiveConfig {
// test redis can connect
reactiveStringRedisTemplate.getConnectionFactory().getReactiveConnection().ping().block();
- if (SEND_LOG_TYPE_REDIS.equals(sendLogType)) {
+ if (SEND_LOG_TYPE_REDIS.equals(aggregateRedisConfigProperties.getSendLogType())) {
// set LogSendAppender.logSendService here to let send log as early as possible
- LogSendAppender.logSendService = new RedisLogSendServiceImpl(this, reactiveStringRedisTemplate);
+ LogSendAppender.logSendService = new RedisLogSendServiceImpl(aggregateRedisConfigProperties, this,
+ reactiveStringRedisTemplate);
}
return reactiveStringRedisTemplate;
@@ -149,14 +140,6 @@ public class AggregateRedisConfig extends RedisReactiveConfig {
template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
return template;
}
-
- public boolean getSendLogOpen() {
- return sendLogOpen;
- }
-
- public String getSendLogChannel() {
- return sendLogChannel;
- }
public static class ProxyLettuceConnectionFactory implements RedisConnectionFactory, ReactiveRedisConnectionFactory {
ProxyLettuceConnectionFactory(LettuceConnectionFactory lettuceConnectionFactory) {
diff --git a/fizz-core/src/main/java/we/config/AggregateRedisConfigProperties.java b/fizz-core/src/main/java/we/config/AggregateRedisConfigProperties.java
new file mode 100644
index 0000000..f1b139e
--- /dev/null
+++ b/fizz-core/src/main/java/we/config/AggregateRedisConfigProperties.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2020 the original author or authors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package we.config;
+
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Component;
+
+/**
+ * {@link AggregateRedisConfig} properties
+ *
+ * @author zhongjie
+ */
+@RefreshScope
+@Component
+@Data
+public class AggregateRedisConfigProperties {
+
+ @Value("${send-log.open:false}")
+ private boolean sendLogOpen;
+
+ @Value("${send-log.channel:fizz_log_channel}")
+ private String sendLogChannel;
+
+ @Value("${send-log.type:redis}")
+ private String sendLogType;
+
+}
diff --git a/fizz-core/src/main/java/we/config/AppConfigProperties.java b/fizz-core/src/main/java/we/config/AppConfigProperties.java
index 268131c..381d50f 100644
--- a/fizz-core/src/main/java/we/config/AppConfigProperties.java
+++ b/fizz-core/src/main/java/we/config/AppConfigProperties.java
@@ -17,27 +17,20 @@
package we.config;
-import com.alibaba.nacos.api.config.annotation.NacosValue;
+import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Configuration;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Component;
/**
* @author unknown
*/
-
-@Configuration
+@RefreshScope
+@Component
+@Data
public class AppConfigProperties {
- @NacosValue(value = "${spring.profiles.active}", autoRefreshed = true)
@Value("${spring.profiles.active}")
private String env;
-
- public String getEnv() {
- return env;
- }
- public void setEnv(String env) {
- this.env = env;
- }
-
}
diff --git a/fizz-core/src/main/java/we/config/FlowStatSchedConfig.java b/fizz-core/src/main/java/we/config/FlowStatSchedConfig.java
index 6d316ce..017322a 100644
--- a/fizz-core/src/main/java/we/config/FlowStatSchedConfig.java
+++ b/fizz-core/src/main/java/we/config/FlowStatSchedConfig.java
@@ -17,11 +17,9 @@
package we.config;
-import com.alibaba.nacos.api.config.annotation.NacosValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
@@ -70,9 +68,8 @@ public class FlowStatSchedConfig extends SchedConfig {
private static final String _minRespTime = "\"minRespTime\":";
private static final String _maxRespTime = "\"maxRespTime\":";
- @NacosValue(value = "${flowControl:false}", autoRefreshed = true)
- @Value("${flowControl:false}")
- private boolean flowControl;
+ @Resource
+ private FlowStatSchedConfigProperties flowStatSchedConfigProperties;
// @Resource
@Autowired(required = false)
@@ -81,14 +78,6 @@ public class FlowStatSchedConfig extends SchedConfig {
@Resource
private ResourceRateLimitConfigService resourceRateLimitConfigService;
- @NacosValue(value = "${flow-stat-sched.dest:redis}", autoRefreshed = true)
- @Value("${flow-stat-sched.dest:redis}")
- private String dest;
-
- @NacosValue(value = "${flow-stat-sched.queue:fizz_resource_access_stat}", autoRefreshed = true)
- @Value("${flow-stat-sched.queue:fizz_resource_access_stat}")
- private String queue;
-
@Resource(name = AggregateRedisConfig.AGGREGATE_REACTIVE_REDIS_TEMPLATE)
private ReactiveStringRedisTemplate rt;
@@ -101,7 +90,7 @@ public class FlowStatSchedConfig extends SchedConfig {
@Scheduled(cron = "${flow-stat-sched.cron}")
public void sched() {
- if (!flowControl) {
+ if (!flowStatSchedConfigProperties.isFlowControl()) {
return;
}
if (startTimeSlot == 0) {
@@ -173,10 +162,10 @@ public class FlowStatSchedConfig extends SchedConfig {
b.append(_minRespTime); b.append(w.getMin());
b.append(Constants.Symbol.RIGHT_BRACE);
String msg = b.toString();
- if ("kafka".equals(dest)) { // for internal use
- log.warn(msg, LogService.HANDLE_STGY, LogService.toKF(queue));
+ if ("kafka".equals(flowStatSchedConfigProperties.getDest())) { // for internal use
+ log.warn(msg, LogService.HANDLE_STGY, LogService.toKF(flowStatSchedConfigProperties.getQueue()));
} else {
- rt.convertAndSend(queue, msg).subscribe();
+ rt.convertAndSend(flowStatSchedConfigProperties.getQueue(), msg).subscribe();
}
if (log.isDebugEnabled()) {
log.debug("report " + toDP19(winStart) + " win10: " + msg);
diff --git a/fizz-core/src/main/java/we/config/FlowStatSchedConfigProperties.java b/fizz-core/src/main/java/we/config/FlowStatSchedConfigProperties.java
new file mode 100644
index 0000000..d4f2fcb
--- /dev/null
+++ b/fizz-core/src/main/java/we/config/FlowStatSchedConfigProperties.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2020 the original author or authors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package we.config;
+
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Component;
+
+/**
+ * {@link FlowStatSchedConfig} properties
+ *
+ * @author zhongjie
+ */
+@RefreshScope
+@Component
+@Data
+public class FlowStatSchedConfigProperties {
+
+ @Value("${flowControl:false}")
+ private boolean flowControl;
+
+ @Value("${flow-stat-sched.dest:redis}")
+ private String dest;
+
+ @Value("${flow-stat-sched.queue:fizz_resource_access_stat}")
+ private String queue;
+}
diff --git a/fizz-core/src/main/java/we/config/RefreshLocalCacheConfig.java b/fizz-core/src/main/java/we/config/RefreshLocalCacheConfig.java
index 5058cbd..e593b49 100644
--- a/fizz-core/src/main/java/we/config/RefreshLocalCacheConfig.java
+++ b/fizz-core/src/main/java/we/config/RefreshLocalCacheConfig.java
@@ -16,10 +16,8 @@
*/
package we.config;
-import com.alibaba.nacos.api.config.annotation.NacosValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;
import we.fizz.ConfigLoader;
@@ -48,27 +46,8 @@ import javax.annotation.Resource;
public class RefreshLocalCacheConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(RefreshLocalCacheConfig.class);
- @NacosValue(value = "${refresh-local-cache.api-config-enabled:false}", autoRefreshed = true)
- @Value("${refresh-local-cache.api-config-enabled:false}")
- private boolean apiConfigCacheRefreshEnabled;
- @NacosValue(value = "${refresh-local-cache.api-config-2-apps-enabled:false}", autoRefreshed = true)
- @Value("${refresh-local-cache.api-config-2-apps-enabled:false}")
- private boolean apiConfig2AppsCacheRefreshEnabled;
- @NacosValue(value = "${refresh-local-cache.aggregate-config-enabled:false}", autoRefreshed = true)
- @Value("${refresh-local-cache.aggregate-config-enabled:false}")
- private boolean aggregateConfigCacheRefreshEnabled;
- @NacosValue(value = "${refresh-local-cache.gateway-group-enabled:false}", autoRefreshed = true)
- @Value("${refresh-local-cache.gateway-group-enabled:false}")
- private boolean gatewayGroupCacheRefreshEnabled;
- @NacosValue(value = "${refresh-local-cache.app-auth-enabled:false}", autoRefreshed = true)
- @Value("${refresh-local-cache.app-auth-enabled:false}")
- private boolean appAuthCacheRefreshEnabled;
- @NacosValue(value = "${refresh-local-cache.flow-control-rule-enabled:false}", autoRefreshed = true)
- @Value("${refresh-local-cache.flow-control-rule-enabled:false}")
- private boolean flowControlRuleCacheRefreshEnabled;
- @NacosValue(value = "${refresh-local-cache.rpc-service-enabled:false}", autoRefreshed = true)
- @Value("${refresh-local-cache.rpc-service-enabled:false}")
- private boolean rpcServiceCacheRefreshEnabled;
+ @Resource
+ private RefreshLocalCacheConfigProperties refreshLocalCacheConfigProperties;
@Resource
private ConfigLoader configLoader;
@@ -94,7 +73,7 @@ public class RefreshLocalCacheConfig {
@Scheduled(initialDelayString = "${refresh-local-cache.initial-delay-millis:300000}",
fixedRateString = "${refresh-local-cache.fixed-rate-millis:300000}")
public void refreshLocalCache() {
- if (apiConfigCacheRefreshEnabled) {
+ if (refreshLocalCacheConfigProperties.isApiConfigCacheRefreshEnabled()) {
LOGGER.debug("refresh api config local cache");
try {
apiConfigService.refreshLocalCache();
@@ -103,7 +82,7 @@ public class RefreshLocalCacheConfig {
}
}
- if (apiConfig2AppsCacheRefreshEnabled) {
+ if (refreshLocalCacheConfigProperties.isApiConfig2AppsCacheRefreshEnabled()) {
LOGGER.debug("refresh api config to apps local cache");
try {
apiConifg2appsService.refreshLocalCache();
@@ -112,7 +91,7 @@ public class RefreshLocalCacheConfig {
}
}
- if (aggregateConfigCacheRefreshEnabled) {
+ if (refreshLocalCacheConfigProperties.isAggregateConfigCacheRefreshEnabled()) {
LOGGER.debug("refresh aggregate config local cache");
try {
configLoader.refreshLocalCache();
@@ -121,7 +100,7 @@ public class RefreshLocalCacheConfig {
}
}
- if (gatewayGroupCacheRefreshEnabled) {
+ if (refreshLocalCacheConfigProperties.isGatewayGroupCacheRefreshEnabled()) {
LOGGER.debug("refresh gateway group local cache");
try {
gatewayGroupService.refreshLocalCache();
@@ -130,7 +109,7 @@ public class RefreshLocalCacheConfig {
}
}
- if (appAuthCacheRefreshEnabled) {
+ if (refreshLocalCacheConfigProperties.isAppAuthCacheRefreshEnabled()) {
LOGGER.debug("refresh app auth local cache");
try {
appService.refreshLocalCache();
@@ -139,7 +118,7 @@ public class RefreshLocalCacheConfig {
}
}
- if (flowControlRuleCacheRefreshEnabled) {
+ if (refreshLocalCacheConfigProperties.isFlowControlRuleCacheRefreshEnabled()) {
LOGGER.debug("refresh flow control rule local cache");
try {
resourceRateLimitConfigService.refreshLocalCache();
@@ -148,7 +127,7 @@ public class RefreshLocalCacheConfig {
}
}
- if (rpcServiceCacheRefreshEnabled) {
+ if (refreshLocalCacheConfigProperties.isRpcServiceCacheRefreshEnabled()) {
LOGGER.debug("refresh rpc service local cache");
try {
rpcInstanceService.refreshLocalCache();
diff --git a/fizz-core/src/main/java/we/config/RefreshLocalCacheConfigProperties.java b/fizz-core/src/main/java/we/config/RefreshLocalCacheConfigProperties.java
new file mode 100644
index 0000000..dd17bac
--- /dev/null
+++ b/fizz-core/src/main/java/we/config/RefreshLocalCacheConfigProperties.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2020 the original author or authors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package we.config;
+
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Component;
+
+/**
+ * {@link RefreshLocalCacheConfig} properties
+ *
+ * @author zhongjie
+ */
+@RefreshScope
+@Component
+@Data
+public class RefreshLocalCacheConfigProperties {
+
+ @Value("${refresh-local-cache.api-config-enabled:false}")
+ private boolean apiConfigCacheRefreshEnabled;
+
+ @Value("${refresh-local-cache.api-config-2-apps-enabled:false}")
+ private boolean apiConfig2AppsCacheRefreshEnabled;
+
+ @Value("${refresh-local-cache.aggregate-config-enabled:false}")
+ private boolean aggregateConfigCacheRefreshEnabled;
+
+ @Value("${refresh-local-cache.gateway-group-enabled:false}")
+ private boolean gatewayGroupCacheRefreshEnabled;
+
+ @Value("${refresh-local-cache.app-auth-enabled:false}")
+ private boolean appAuthCacheRefreshEnabled;
+
+ @Value("${refresh-local-cache.flow-control-rule-enabled:false}")
+ private boolean flowControlRuleCacheRefreshEnabled;
+
+ @Value("${refresh-local-cache.rpc-service-enabled:false}")
+ private boolean rpcServiceCacheRefreshEnabled;
+}
diff --git a/fizz-core/src/main/java/we/config/SystemConfig.java b/fizz-core/src/main/java/we/config/SystemConfig.java
index 52d772d..261cc05 100644
--- a/fizz-core/src/main/java/we/config/SystemConfig.java
+++ b/fizz-core/src/main/java/we/config/SystemConfig.java
@@ -14,32 +14,32 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
package we.config;
-import com.alibaba.nacos.api.config.annotation.NacosValue;
-import com.ctrip.framework.apollo.model.ConfigChange;
-import com.ctrip.framework.apollo.model.ConfigChangeEvent;
-import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Configuration;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import we.util.Constants;
import we.util.WebUtils;
import javax.annotation.PostConstruct;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* @author hongqiaowei
*/
-
-@Configuration
+@RefreshScope
+@Component
public class SystemConfig {
private static final Logger log = LoggerFactory.getLogger(SystemConfig.class);
@@ -50,24 +50,25 @@ public class SystemConfig {
public static final String DEFAULT_GATEWAY_TEST_PREFIX0 = "/_proxytest/";
- public String gatewayPrefix = DEFAULT_GATEWAY_PREFIX;
+ private String gatewayPrefix = DEFAULT_GATEWAY_PREFIX;
- public List appHeaders = Stream.of("fizz-appid").collect(Collectors.toList());
+ private List appHeaders = Stream.of("fizz-appid").collect(Collectors.toList());
- public List signHeaders = Stream.of("fizz-sign") .collect(Collectors.toList());
+ private List signHeaders = Stream.of("fizz-sign") .collect(Collectors.toList());
- public List timestampHeaders = Stream.of("fizz-ts") .collect(Collectors.toList());
-
- public List proxySetHeaders = new ArrayList<>();
+ private List timestampHeaders = Stream.of("fizz-ts") .collect(Collectors.toList());
- public boolean aggregateTestAuth = false;
+ private List proxySetHeaders = new ArrayList<>();
+
+ private boolean aggregateTestAuth = false;
- @NacosValue(value = "${route-timeout:0}", autoRefreshed = true)
@Value ( "${route-timeout:0}")
- public long routeTimeout = 0;
-
-
- @NacosValue(value = "${gateway.aggr.proxy_set_headers:}", autoRefreshed = true)
+ private long routeTimeout = 0;
+
+ public long getRouteTimeout() {
+ return routeTimeout;
+ }
+
@Value("${gateway.aggr.proxy_set_headers:}")
public void setProxySetHeaders(String hdrs) {
if (StringUtils.isNotBlank(hdrs)) {
@@ -79,7 +80,10 @@ public class SystemConfig {
log.info("proxy set headers: " + hdrs);
}
- @NacosValue(value = "${gateway.prefix:/proxy}", autoRefreshed = true)
+ public List getProxySetHeaders() {
+ return proxySetHeaders;
+ }
+
@Value( "${gateway.prefix:/proxy}" )
public void setGatewayPrefix(String gp) {
gatewayPrefix = gp;
@@ -87,7 +91,10 @@ public class SystemConfig {
log.info("gateway prefix: " + gatewayPrefix);
}
- @NacosValue(value = "${custom.header.appid:}", autoRefreshed = true)
+ public String getGatewayPrefix() {
+ return gatewayPrefix;
+ }
+
@Value( "${custom.header.appid:}" )
public void setCustomAppHeaders(String hdrs) {
if (StringUtils.isNotBlank(hdrs)) {
@@ -101,7 +108,10 @@ public class SystemConfig {
log.info("app headers: " + appHeaders);
}
- @NacosValue(value = "${custom.header.sign:}", autoRefreshed = true)
+ public List getAppHeaders() {
+ return appHeaders;
+ }
+
@Value( "${custom.header.sign:}" )
public void setCustomSignHeaders(String hdrs) {
if (StringUtils.isNotBlank(hdrs)) {
@@ -114,7 +124,10 @@ public class SystemConfig {
log.info("sign headers: " + signHeaders);
}
- @NacosValue(value = "${custom.header.ts:}", autoRefreshed = true)
+ public List getSignHeaders() {
+ return signHeaders;
+ }
+
@Value( "${custom.header.ts:}" )
public void setCustomTimestampHeaders(String hdrs) {
if (StringUtils.isNotBlank(hdrs)) {
@@ -127,27 +140,35 @@ public class SystemConfig {
log.info("timestamp headers: " + timestampHeaders);
}
- @NacosValue(value = "${aggregate-test-auth:false}", autoRefreshed = true)
+ public List getTimestampHeaders() {
+ return timestampHeaders;
+ }
+
@Value( "${aggregate-test-auth:false}" )
public void setAggregateTestAuth(boolean b) {
aggregateTestAuth = b;
log.info("aggregate test auth: " + aggregateTestAuth);
}
+ public boolean isAggregateTestAuth() {
+ return aggregateTestAuth;
+ }
+
// TODO: below to X
- @Value("${log.response-body:false}")
private boolean logResponseBody;
- @Value("${log.headers:x}")
private String logHeaders;
private Set logHeaderSet = new HashSet<>();
- @NacosValue(value = "${spring.profiles.active}")
@Value("${spring.profiles.active}")
private String profile;
+ public String getProfile() {
+ return profile;
+ }
+
public Set getLogHeaderSet() {
return logHeaderSet;
}
@@ -172,24 +193,6 @@ public class SystemConfig {
log.info("log header list: " + logHeaderSet.toString());
}
- @ApolloConfigChangeListener
- private void configChangeListter(ConfigChangeEvent cce) {
- cce.changedKeys().forEach(
- k -> {
- ConfigChange c = cce.getChange(k);
- String p = c.getPropertyName();
- String ov = c.getOldValue();
- String nv = c.getNewValue();
- log.info(p + " old: " + ov + ", new: " + nv);
- if (p.equals("log.response-body")) {
- this.updateLogResponseBody(Boolean.parseBoolean(nv));
- } else if (p.equals("log.headers")) {
- this.updateLogHeaders(nv);
- }
- }
- );
- }
-
private void updateLogResponseBody(boolean newValue) {
logResponseBody = newValue;
this.afterLogResponseBodySet();
@@ -200,7 +203,7 @@ public class SystemConfig {
afterLogHeadersSet();
}
- @NacosValue(value = "${log.response-body:false}", autoRefreshed = true)
+ @Value("${log.response-body:false}")
public void setLogResponseBody(boolean logResponseBody) {
if (this.logResponseBody == logResponseBody) {
return;
@@ -209,7 +212,7 @@ public class SystemConfig {
this.updateLogResponseBody(logResponseBody);
}
- @NacosValue(value = "${log.headers:x}", autoRefreshed = true)
+ @Value("${log.headers:x}")
public void setLogHeaders(String logHeaders) {
if (ObjectUtils.nullSafeEquals(this.logHeaders, logHeaders)) {
return;
diff --git a/fizz-core/src/main/java/we/config/WebFluxConfig.java b/fizz-core/src/main/java/we/config/WebFluxConfig.java
index 70a61aa..d23f586 100644
--- a/fizz-core/src/main/java/we/config/WebFluxConfig.java
+++ b/fizz-core/src/main/java/we/config/WebFluxConfig.java
@@ -19,7 +19,6 @@ package we.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -31,7 +30,7 @@ import org.springframework.web.reactive.config.EnableWebFlux;
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer;
-import com.alibaba.nacos.api.config.annotation.NacosValue;
+import javax.annotation.Resource;
/**
* @author hongqiaowei
@@ -135,27 +134,15 @@ public class WebFluxConfig {
@Configuration
@EnableWebFlux
public static class FizzWebFluxConfigurer implements WebFluxConfigurer {
-
- /**
- * Configure the maximum amount of disk space allowed for file parts. Default 100M (104857600)
- */
- @NacosValue(value = "${server.fileUpload.maxDiskUsagePerPart:104857600}", autoRefreshed = true)
- @Value( "${server.fileUpload.maxDiskUsagePerPart:104857600}" )
- private long maxDiskUsagePerPart;
-
- /**
- * Maximum parts of multipart form-data, including form field parts; Default -1 no limit
- */
- @NacosValue(value = "${server.fileUpload.maxParts:-1}", autoRefreshed = true)
- @Value( "${server.fileUpload.maxParts:-1}" )
- private int maxParts;
+ @Resource
+ private WebFluxConfigProperties webFluxConfigProperties;
@Override
public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
configurer.defaultCodecs().maxInMemorySize(-1);
SynchronossPartHttpMessageReader partReader = new SynchronossPartHttpMessageReader();
- partReader.setMaxParts(maxParts);
- partReader.setMaxDiskUsagePerPart(maxDiskUsagePerPart);
+ partReader.setMaxParts(webFluxConfigProperties.getMaxParts());
+ partReader.setMaxDiskUsagePerPart(webFluxConfigProperties.getMaxDiskUsagePerPart());
MultipartHttpMessageReader multipartReader = new MultipartHttpMessageReader(partReader);
configurer.defaultCodecs().multipartReader(multipartReader);
}
diff --git a/fizz-core/src/main/java/we/config/WebFluxConfigProperties.java b/fizz-core/src/main/java/we/config/WebFluxConfigProperties.java
new file mode 100644
index 0000000..f8b81b8
--- /dev/null
+++ b/fizz-core/src/main/java/we/config/WebFluxConfigProperties.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2020 the original author or authors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package we.config;
+
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Component;
+
+/**
+ * {@link WebFluxConfig} properties
+ *
+ * @author zhongjie
+ */
+@RefreshScope
+@Component
+@Data
+public class WebFluxConfigProperties {
+ /**
+ * Configure the maximum amount of disk space allowed for file parts. Default 100M (104857600)
+ */
+ @Value( "${server.fileUpload.maxDiskUsagePerPart:104857600}" )
+ private long maxDiskUsagePerPart;
+
+ /**
+ * Maximum parts of multipart form-data, including form field parts; Default -1 no limit
+ */
+ @Value( "${server.fileUpload.maxParts:-1}" )
+ private int maxParts;
+}
diff --git a/fizz-core/src/main/java/we/controller/FlowControlController.java b/fizz-core/src/main/java/we/controller/FlowControlController.java
index f7ebfb4..0ea8944 100644
--- a/fizz-core/src/main/java/we/controller/FlowControlController.java
+++ b/fizz-core/src/main/java/we/controller/FlowControlController.java
@@ -17,11 +17,11 @@
package we.controller;
-import com.alibaba.nacos.api.config.annotation.NacosValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@@ -36,7 +36,6 @@ import we.util.Constants;
import we.util.DateTimeUtils;
import we.util.JacksonUtils;
-import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
@@ -45,14 +44,13 @@ import java.util.Map;
/**
* @author hongqiaowei
*/
-
+@RefreshScope
@RestController
@RequestMapping("/admin/flowStat")
public class FlowControlController {
private static final Logger log = LoggerFactory.getLogger(FlowControlController.class);
- @NacosValue(value = "${flowControl:false}", autoRefreshed = true)
@Value("${flowControl:false}")
private boolean flowControl;
diff --git a/fizz-core/src/main/java/we/controller/ManagerConfigController.java b/fizz-core/src/main/java/we/controller/ManagerConfigController.java
index 9ec623a..5608b5e 100644
--- a/fizz-core/src/main/java/we/controller/ManagerConfigController.java
+++ b/fizz-core/src/main/java/we/controller/ManagerConfigController.java
@@ -17,8 +17,8 @@
package we.controller;
-import com.alibaba.nacos.api.config.annotation.NacosValue;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -42,10 +42,10 @@ import java.util.stream.Collectors;
* Fizz管理后台通过该控制器暴露的接口获取聚合配置相关信息
* @author zhongjie
*/
+@RefreshScope
@RestController
@RequestMapping(value = "/admin/managerConfig")
public class ManagerConfigController {
- @NacosValue(value = "${fizz.manager.config.key:fizz-manager-key}", autoRefreshed = true)
@Value("${fizz.manager.config.key:fizz-manager-key}")
private String key;
diff --git a/fizz-core/src/main/java/we/filter/AggregateFilter.java b/fizz-core/src/main/java/we/filter/AggregateFilter.java
index 85ae256..c22926d 100644
--- a/fizz-core/src/main/java/we/filter/AggregateFilter.java
+++ b/fizz-core/src/main/java/we/filter/AggregateFilter.java
@@ -29,7 +29,6 @@ import javax.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
@@ -46,7 +45,6 @@ import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import com.alibaba.fastjson.JSON;
-import com.alibaba.nacos.api.config.annotation.NacosValue;
import io.netty.buffer.UnpooledByteBufAllocator;
import reactor.core.publisher.Flux;
@@ -79,9 +77,8 @@ public class AggregateFilter implements WebFilter {
@Resource
private ConfigLoader configLoader;
- @NacosValue(value = "${need-auth:true}", autoRefreshed = true)
- @Value("${need-auth:true}")
- private boolean needAuth;
+ @Resource
+ private AggregateFilterProperties aggregateFilterProperties;
@Resource
private SystemConfig systemConfig;
@@ -97,10 +94,10 @@ public class AggregateFilter implements WebFilter {
if (act == ApiConfig.Type.UNDEFINED) {
String p = exchange.getRequest().getPath().value();
if (StringUtils.startsWith(p, SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX0)) {
- if (systemConfig.aggregateTestAuth) {
+ if (systemConfig.isAggregateTestAuth()) {
return chain.filter(exchange);
}
- } else if (needAuth) {
+ } else if (aggregateFilterProperties.isNeedAuth()) {
return chain.filter(exchange);
}
} else if (act != ApiConfig.Type.SERVICE_AGGREGATE) {
diff --git a/fizz-core/src/main/java/we/filter/AggregateFilterProperties.java b/fizz-core/src/main/java/we/filter/AggregateFilterProperties.java
new file mode 100644
index 0000000..0bc7b88
--- /dev/null
+++ b/fizz-core/src/main/java/we/filter/AggregateFilterProperties.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2020 the original author or authors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package we.filter;
+
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Component;
+
+/**
+ * {@link AggregateFilter} properties
+ *
+ * @author zhongjie
+ */
+@RefreshScope
+@Component
+@Data
+public class AggregateFilterProperties {
+
+ @Value("${need-auth:true}")
+ private boolean needAuth;
+}
diff --git a/fizz-core/src/main/java/we/filter/CallbackFilter.java b/fizz-core/src/main/java/we/filter/CallbackFilter.java
index fa8578a..4639689 100644
--- a/fizz-core/src/main/java/we/filter/CallbackFilter.java
+++ b/fizz-core/src/main/java/we/filter/CallbackFilter.java
@@ -18,12 +18,10 @@
package we.filter;
import com.alibaba.fastjson.JSON;
-import com.alibaba.nacos.api.config.annotation.NacosValue;
import io.netty.buffer.UnpooledByteBufAllocator;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
@@ -74,13 +72,8 @@ public class CallbackFilter extends FizzWebFilter {
@Resource
private DiscoveryClientUriSelector discoveryClientSelector;
- @NacosValue(value = "${callback.push.dest:redis}", autoRefreshed = true)
- @Value("${callback.push.dest:redis}")
- private String dest;
-
- @NacosValue(value = "${callback.push.queue:fizz_callback_channel}", autoRefreshed = true)
- @Value("${callback.push.queue:fizz_callback_channel}")
- private String queue;
+ @Resource
+ private CallbackFilterProperties callbackFilterProperties;
@Resource(name = AggregateRedisConfig.AGGREGATE_REACTIVE_REDIS_TEMPLATE)
private ReactiveStringRedisTemplate rt;
@@ -215,10 +208,10 @@ public class CallbackFilter extends FizzWebFilter {
b.append(Constants.Symbol.RIGHT_BRACE);
String msg = b.toString();
- if ("kafka".equals(dest)) { // for internal use
- log.warn(msg, LogService.HANDLE_STGY, LogService.toKF(queue));
+ if ("kafka".equals(callbackFilterProperties.getDest())) { // for internal use
+ log.warn(msg, LogService.HANDLE_STGY, LogService.toKF(callbackFilterProperties.getQueue()));
} else {
- rt.convertAndSend(queue, msg).subscribe();
+ rt.convertAndSend(callbackFilterProperties.getQueue(), msg).subscribe();
}
if (log.isDebugEnabled()) {
log.debug("push callback req: " + msg);
diff --git a/fizz-core/src/main/java/we/filter/CallbackFilterProperties.java b/fizz-core/src/main/java/we/filter/CallbackFilterProperties.java
new file mode 100644
index 0000000..7ead8ec
--- /dev/null
+++ b/fizz-core/src/main/java/we/filter/CallbackFilterProperties.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2020 the original author or authors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package we.filter;
+
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Component;
+
+/**
+ * {@link CallbackFilter} properties
+ *
+ * @author zhongjie
+ */
+@RefreshScope
+@Component
+@Data
+public class CallbackFilterProperties {
+ @Value("${callback.push.dest:redis}")
+ private String dest;
+
+ @Value("${callback.push.queue:fizz_callback_channel}")
+ private String queue;
+
+}
diff --git a/fizz-core/src/main/java/we/filter/FlowControlFilter.java b/fizz-core/src/main/java/we/filter/FlowControlFilter.java
index d41c236..37f2832 100644
--- a/fizz-core/src/main/java/we/filter/FlowControlFilter.java
+++ b/fizz-core/src/main/java/we/filter/FlowControlFilter.java
@@ -25,7 +25,6 @@ import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
@@ -34,8 +33,6 @@ import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilterChain;
-import com.alibaba.nacos.api.config.annotation.NacosValue;
-
import reactor.core.publisher.Mono;
import reactor.core.publisher.SignalType;
import we.flume.clients.log4j2appender.LogService;
@@ -66,9 +63,8 @@ public class FlowControlFilter extends FizzWebFilter {
public static final String ADMIN_REQUEST = "$a";
- @NacosValue(value = "${flowControl:false}", autoRefreshed = true)
- @Value("${flowControl:false}")
- private boolean flowControl;
+ @Resource
+ private FlowControlFilterProperties flowControlFilterProperties;
@Resource
private ResourceRateLimitConfigService resourceRateLimitConfigService;
@@ -92,7 +88,7 @@ public class FlowControlFilter extends FizzWebFilter {
exchange.getAttributes().put(ADMIN_REQUEST, Constants.Symbol.EMPTY);
}
- if (flowControl && !adminReq) {
+ if (flowControlFilterProperties.isFlowControl() && !adminReq) {
String service = WebUtils.getClientService(exchange);
// String reqPath = WebUtils.getClientReqPath(exchange);
long currentTimeSlot = flowStat.currentTimeSlotId();
diff --git a/fizz-core/src/main/java/we/filter/FlowControlFilterProperties.java b/fizz-core/src/main/java/we/filter/FlowControlFilterProperties.java
new file mode 100644
index 0000000..b3129bb
--- /dev/null
+++ b/fizz-core/src/main/java/we/filter/FlowControlFilterProperties.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2020 the original author or authors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package we.filter;
+
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Component;
+
+/**
+ * {@link FlowControlFilter} properties
+ *
+ * @author zhongjie
+ */
+@RefreshScope
+@Component
+@Data
+public class FlowControlFilterProperties {
+
+ @Value("${flowControl:false}")
+ private boolean flowControl;
+}
diff --git a/fizz-core/src/main/java/we/filter/PreprocessFilter.java b/fizz-core/src/main/java/we/filter/PreprocessFilter.java
index b7f2b4b..ac7329f 100644
--- a/fizz-core/src/main/java/we/filter/PreprocessFilter.java
+++ b/fizz-core/src/main/java/we/filter/PreprocessFilter.java
@@ -17,6 +17,9 @@
package we.filter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
diff --git a/fizz-core/src/main/java/we/fizz/ConfigLoader.java b/fizz-core/src/main/java/we/fizz/ConfigLoader.java
index 22a68fc..632d6bd 100644
--- a/fizz-core/src/main/java/we/fizz/ConfigLoader.java
+++ b/fizz-core/src/main/java/we/fizz/ConfigLoader.java
@@ -20,8 +20,6 @@ package we.fizz;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
-import com.alibaba.nacos.api.config.annotation.NacosValue;
-
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext;
import reactor.core.publisher.Flux;
@@ -108,9 +106,8 @@ public class ConfigLoader {
@Resource(name = AGGREGATE_REACTIVE_REDIS_TEMPLATE)
private ReactiveStringRedisTemplate reactiveStringRedisTemplate;
- @NacosValue(value = "${fizz.aggregate.read-local-config-flag:false}", autoRefreshed = true)
- @Value("${fizz.aggregate.read-local-config-flag:false}")
- private Boolean readLocalConfigFlag;
+ @Resource
+ private ConfigLoaderProperties configLoaderProperties;
private String formalPathPrefix;
private int formalPathServiceNameStartIndex;
@@ -228,7 +225,7 @@ public class ConfigLoader {
Map resourceKey2ConfigInfoMapTmp = new ConcurrentHashMap<>(1024);
Map aggregateId2ResourceKeyMapTmp = new ConcurrentHashMap<>(1024);
- if (readLocalConfigFlag) {
+ if (configLoaderProperties.getReadLocalConfigFlag()) {
File dir = new File("json");
if (dir.exists() && dir.isDirectory()) {
File[] files = dir.listFiles();
diff --git a/fizz-core/src/main/java/we/fizz/ConfigLoaderProperties.java b/fizz-core/src/main/java/we/fizz/ConfigLoaderProperties.java
new file mode 100644
index 0000000..08babc4
--- /dev/null
+++ b/fizz-core/src/main/java/we/fizz/ConfigLoaderProperties.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2020 the original author or authors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package we.fizz;
+
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Component;
+
+/**
+ * {@link ConfigLoader} properties
+ *
+ * @author zhongjie
+ */
+@RefreshScope
+@Component
+@Data
+public class ConfigLoaderProperties {
+
+ @Value("${fizz.aggregate.read-local-config-flag:false}")
+ private Boolean readLocalConfigFlag;
+}
diff --git a/fizz-core/src/main/java/we/fizz/input/extension/request/RequestInput.java b/fizz-core/src/main/java/we/fizz/input/extension/request/RequestInput.java
index bb2816c..e0c32f4 100644
--- a/fizz-core/src/main/java/we/fizz/input/extension/request/RequestInput.java
+++ b/fizz-core/src/main/java/we/fizz/input/extension/request/RequestInput.java
@@ -349,7 +349,7 @@ public class RequestInput extends RPCInput implements IInput{
// add default headers
SystemConfig systemConfig = this.getCurrentApplicationContext().getBean(SystemConfig.class);
- for (String hdr : systemConfig.proxySetHeaders) {
+ for (String hdr : systemConfig.getProxySetHeaders()) {
if(inputContext.getStepContext().getInputReqHeader(hdr) != null) {
headers.addIfAbsent(hdr, (String) inputContext.getStepContext().getInputReqHeader(hdr));
}
diff --git a/fizz-core/src/main/java/we/log/RedisLogSendServiceImpl.java b/fizz-core/src/main/java/we/log/RedisLogSendServiceImpl.java
index 700e82e..10d5148 100644
--- a/fizz-core/src/main/java/we/log/RedisLogSendServiceImpl.java
+++ b/fizz-core/src/main/java/we/log/RedisLogSendServiceImpl.java
@@ -19,6 +19,7 @@ package we.log;
import com.alibaba.fastjson.JSON;
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
import we.config.AggregateRedisConfig;
+import we.config.AggregateRedisConfigProperties;
/**
* {@link LogSendService} impl class, using redis channel to send log
@@ -26,18 +27,22 @@ import we.config.AggregateRedisConfig;
* @author zhongjie
*/
public class RedisLogSendServiceImpl implements LogSendService {
- public RedisLogSendServiceImpl(AggregateRedisConfig aggregateRedisConfig, ReactiveStringRedisTemplate reactiveStringRedisTemplate) {
+
+ public RedisLogSendServiceImpl(AggregateRedisConfigProperties aggregateRedisConfigProperties,
+ AggregateRedisConfig aggregateRedisConfig, ReactiveStringRedisTemplate reactiveStringRedisTemplate) {
+ this.aggregateRedisConfigProperties = aggregateRedisConfigProperties;
this.aggregateRedisConfig = aggregateRedisConfig;
this.reactiveStringRedisTemplate = reactiveStringRedisTemplate;
}
+ private AggregateRedisConfigProperties aggregateRedisConfigProperties;
private AggregateRedisConfig aggregateRedisConfig;
private ReactiveStringRedisTemplate reactiveStringRedisTemplate;
@Override
public void send(LogSend logSend) {
- if (aggregateRedisConfig.getSendLogOpen()) {
- reactiveStringRedisTemplate.convertAndSend(aggregateRedisConfig.getSendLogChannel(), JSON.toJSONString(logSend)).subscribe();
+ if (aggregateRedisConfigProperties.isSendLogOpen()) {
+ reactiveStringRedisTemplate.convertAndSend(aggregateRedisConfigProperties.getSendLogChannel(), JSON.toJSONString(logSend)).subscribe();
}
}
}
diff --git a/fizz-core/src/main/java/we/plugin/auth/ApiConfigService.java b/fizz-core/src/main/java/we/plugin/auth/ApiConfigService.java
index a647e88..9e174e4 100644
--- a/fizz-core/src/main/java/we/plugin/auth/ApiConfigService.java
+++ b/fizz-core/src/main/java/we/plugin/auth/ApiConfigService.java
@@ -17,12 +17,10 @@
package we.plugin.auth;
-import com.alibaba.nacos.api.config.annotation.NacosValue;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
@@ -57,21 +55,12 @@ public class ApiConfigService {
public static final String AUTH_MSG = "$authMsg";
- @NacosValue(value = "${fizz-api-config.key:fizz_api_config_route}", autoRefreshed = true)
- @Value("${fizz-api-config.key:fizz_api_config_route}")
- private String fizzApiConfig;
-
- @NacosValue(value = "${fizz-api-config.channel:fizz_api_config_channel_route}", autoRefreshed = true)
- @Value("${fizz-api-config.channel:fizz_api_config_channel_route}")
- private String fizzApiConfigChannel;
-
public Map serviceConfigMap = new HashMap<>(128);
private Map apiConfigMap = new HashMap<>(128);
- @NacosValue(value = "${need-auth:true}", autoRefreshed = true)
- @Value("${need-auth:true}")
- private boolean needAuth;
+ @Resource
+ private ApiConfigServiceProperties apiConfigServiceProperties;
@Resource(name = AggregateRedisConfig.AGGREGATE_REACTIVE_REDIS_TEMPLATE)
private ReactiveStringRedisTemplate rt;
@@ -104,7 +93,7 @@ public class ApiConfigService {
Map apiConfigMapTmp = new HashMap<>(128);
Map serviceConfigMapTmp = new HashMap<>(128);
final Throwable[] throwable = new Throwable[1];
- Throwable error = Mono.just(Objects.requireNonNull(rt.opsForHash().entries(fizzApiConfig)
+ Throwable error = Mono.just(Objects.requireNonNull(rt.opsForHash().entries(apiConfigServiceProperties.getFizzApiConfig())
.defaultIfEmpty(new AbstractMap.SimpleEntry<>(ReactorUtils.OBJ, ReactorUtils.OBJ)).onErrorStop().doOnError(t -> log.info(null, t))
.concatMap(e -> {
Object k = e.getKey();
@@ -148,14 +137,14 @@ public class ApiConfigService {
private Mono lsnApiConfigChange() {
final Throwable[] throwable = new Throwable[1];
final boolean[] b = {false};
- rt.listenToChannel(fizzApiConfigChannel).doOnError(t -> {
+ rt.listenToChannel(apiConfigServiceProperties.getFizzApiConfigChannel()).doOnError(t -> {
throwable[0] = t;
b[0] = false;
- log.error("lsn " + fizzApiConfigChannel, t);
+ log.error("lsn " + apiConfigServiceProperties.getFizzApiConfigChannel(), t);
}).doOnSubscribe(
s -> {
b[0] = true;
- log.info("success to lsn on " + fizzApiConfigChannel);
+ log.info("success to lsn on " + apiConfigServiceProperties.getFizzApiConfigChannel());
}
).doOnNext(msg -> {
String json = msg.getMessage();
@@ -314,13 +303,13 @@ public class ApiConfigService {
authMsg = deny;
}
if (SystemConfig.DEFAULT_GATEWAY_TEST_PREFIX0.equals(WebUtils.getClientReqPathPrefix(exchange))) {
- if (systemConfig.aggregateTestAuth) {
+ if (systemConfig.isAggregateTestAuth()) {
return logAndResult(authMsg);
} else {
return Mono.just(Access.YES);
}
}
- if (!needAuth) {
+ if (!apiConfigServiceProperties.isNeedAuth()) {
return Mono.just(Access.YES);
} else {
return logAndResult(authMsg);
@@ -392,7 +381,7 @@ public class ApiConfigService {
}
private String getTimestamp(HttpHeaders reqHdrs) {
- List tsHdrs = systemConfig.timestampHeaders;
+ List tsHdrs = systemConfig.getTimestampHeaders();
for (int i = 0; i < tsHdrs.size(); i++) {
String a = reqHdrs.getFirst(tsHdrs.get(i));
if (a != null) {
@@ -403,7 +392,7 @@ public class ApiConfigService {
}
private String getSign(HttpHeaders reqHdrs) {
- List signHdrs = systemConfig.signHeaders;
+ List signHdrs = systemConfig.getSignHeaders();
for (int i = 0; i < signHdrs.size(); i++) {
String a = reqHdrs.getFirst(signHdrs.get(i));
if (a != null) {
diff --git a/fizz-core/src/main/java/we/plugin/auth/ApiConfigServiceProperties.java b/fizz-core/src/main/java/we/plugin/auth/ApiConfigServiceProperties.java
new file mode 100644
index 0000000..af26a9d
--- /dev/null
+++ b/fizz-core/src/main/java/we/plugin/auth/ApiConfigServiceProperties.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2020 the original author or authors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package we.plugin.auth;
+
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Component;
+
+/**
+ * {@link ApiConfigService} properties
+ *
+ * @author zhongjie
+ */
+@RefreshScope
+@Component
+@Data
+public class ApiConfigServiceProperties {
+ @Value("${fizz-api-config.key:fizz_api_config_route}")
+ private String fizzApiConfig;
+
+ @Value("${fizz-api-config.channel:fizz_api_config_channel_route}")
+ private String fizzApiConfigChannel;
+
+ @Value("${need-auth:true}")
+ private boolean needAuth;
+}
diff --git a/fizz-core/src/main/java/we/plugin/stat/StatPluginFilter.java b/fizz-core/src/main/java/we/plugin/stat/StatPluginFilter.java
index ec1dc86..688ac58 100644
--- a/fizz-core/src/main/java/we/plugin/stat/StatPluginFilter.java
+++ b/fizz-core/src/main/java/we/plugin/stat/StatPluginFilter.java
@@ -17,11 +17,9 @@
package we.plugin.stat;
-import com.alibaba.nacos.api.config.annotation.NacosValue;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
@@ -64,17 +62,8 @@ public class StatPluginFilter extends PluginFilter {
private static final String reqTime = "\"reqTime\":";
- @NacosValue(value = "${stat.open:false}", autoRefreshed = true)
- @Value("${stat.open:false}")
- private boolean statOpen = false;
-
- @NacosValue(value = "${stat.channel:fizz_access_stat}", autoRefreshed = true)
- @Value("${stat.channel:fizz_access_stat}")
- private String fizzAccessStatChannel;
-
- @NacosValue(value = "${stat.topic:}", autoRefreshed = true)
- @Value("${stat.topic:}")
- private String fizzAccessStatTopic;
+ @Resource
+ private StatPluginFilterProperties statPluginFilterProperties;
@Resource(name = AggregateRedisConfig.AGGREGATE_REACTIVE_REDIS_TEMPLATE)
private ReactiveStringRedisTemplate rt;
@@ -99,7 +88,7 @@ public class StatPluginFilter extends PluginFilter {
@Override
public Mono doFilter(ServerWebExchange exchange, Map config, String fixedConfig) {
- if (statOpen) {
+ if (statPluginFilterProperties.isStatOpen()) {
StringBuilder b = ThreadContext.getStringBuilder();
b.append(Constants.Symbol.LEFT_BRACE);
b.append(ip); toJsonStringValue(b, WebUtils.getOriginIp(exchange)); b.append(Constants.Symbol.COMMA);
@@ -116,10 +105,10 @@ public class StatPluginFilter extends PluginFilter {
b.append(reqTime) .append(System.currentTimeMillis());
b.append(Constants.Symbol.RIGHT_BRACE);
- if (StringUtils.isBlank(fizzAccessStatTopic)) {
- rt.convertAndSend(fizzAccessStatChannel, b.toString()).subscribe();
+ if (StringUtils.isBlank(statPluginFilterProperties.getFizzAccessStatTopic())) {
+ rt.convertAndSend(statPluginFilterProperties.getFizzAccessStatChannel(), b.toString()).subscribe();
} else {
- log.warn(b.toString(), LogService.HANDLE_STGY, LogService.toKF(fizzAccessStatTopic)); // for internal use
+ log.warn(b.toString(), LogService.HANDLE_STGY, LogService.toKF(statPluginFilterProperties.getFizzAccessStatTopic())); // for internal use
}
}
diff --git a/fizz-core/src/main/java/we/plugin/stat/StatPluginFilterProperties.java b/fizz-core/src/main/java/we/plugin/stat/StatPluginFilterProperties.java
new file mode 100644
index 0000000..f976867
--- /dev/null
+++ b/fizz-core/src/main/java/we/plugin/stat/StatPluginFilterProperties.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2020 the original author or authors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package we.plugin.stat;
+
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Component;
+
+/**
+ * {@link StatPluginFilter} properties
+ *
+ * @author zhongjie
+ */
+@RefreshScope
+@Component
+@Data
+public class StatPluginFilterProperties {
+ @Value("${stat.open:false}")
+ private boolean statOpen = false;
+
+ @Value("${stat.channel:fizz_access_stat}")
+ private String fizzAccessStatChannel;
+
+ @Value("${stat.topic:}")
+ private String fizzAccessStatTopic;
+}
diff --git a/fizz-core/src/main/java/we/proxy/CallbackService.java b/fizz-core/src/main/java/we/proxy/CallbackService.java
index 8d27ca7..8873bcc 100644
--- a/fizz-core/src/main/java/we/proxy/CallbackService.java
+++ b/fizz-core/src/main/java/we/proxy/CallbackService.java
@@ -75,7 +75,7 @@ public class CallbackService {
@PostConstruct
public void postConstruct() {
- aggrConfigPrefix = systemConfig.gatewayPrefix + '/';
+ aggrConfigPrefix = systemConfig.getGatewayPrefix() + '/';
}
public Mono extends Void> requestBackends(ServerWebExchange exchange, HttpHeaders headers, DataBuffer body, CallbackConfig cc, Map service2instMap) {
diff --git a/fizz-core/src/main/java/we/proxy/DisableDiscoveryUriSelector.java b/fizz-core/src/main/java/we/proxy/DisableDiscoveryUriSelector.java
index a45be06..8067d6e 100644
--- a/fizz-core/src/main/java/we/proxy/DisableDiscoveryUriSelector.java
+++ b/fizz-core/src/main/java/we/proxy/DisableDiscoveryUriSelector.java
@@ -10,7 +10,7 @@ import reactor.util.function.Tuple2;
* @author zhongjie
*/
-@ConditionalOnExpression("${nacos.discovery.enabled} == false and ${eureka.client.enabled} == false")
+@ConditionalOnExpression("${spring.cloud.nacos.discovery.enabled} == false and ${eureka.client.enabled} == false")
@Service
public class DisableDiscoveryUriSelector implements DiscoveryClientUriSelector {
@Override
diff --git a/fizz-core/src/main/java/we/proxy/FizzWebClient.java b/fizz-core/src/main/java/we/proxy/FizzWebClient.java
index b788da5..7649e1b 100644
--- a/fizz-core/src/main/java/we/proxy/FizzWebClient.java
+++ b/fizz-core/src/main/java/we/proxy/FizzWebClient.java
@@ -133,8 +133,8 @@ public class FizzWebClient {
Mono cr = req.exchange();
if (timeout == 0) {
- if (systemConfig.routeTimeout != 0) {
- timeout = systemConfig.routeTimeout;
+ if (systemConfig.getRouteTimeout() != 0) {
+ timeout = systemConfig.getRouteTimeout();
}
}
if (timeout != 0) {
diff --git a/fizz-core/src/main/java/we/proxy/NacosUriSelector.java b/fizz-core/src/main/java/we/proxy/NacosUriSelector.java
index a6e61a9..1165db6 100644
--- a/fizz-core/src/main/java/we/proxy/NacosUriSelector.java
+++ b/fizz-core/src/main/java/we/proxy/NacosUriSelector.java
@@ -1,19 +1,15 @@
package we.proxy;
-import com.alibaba.boot.nacos.discovery.properties.NacosDiscoveryProperties;
-import com.alibaba.boot.nacos.discovery.properties.Register;
+import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
-import com.netflix.appinfo.InstanceInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
-import reactor.util.function.Tuple2;
-import reactor.util.function.Tuples;
import javax.annotation.PostConstruct;
import java.util.Collections;
@@ -24,7 +20,7 @@ import java.util.List;
*
* @author zhongjie
*/
-@ConditionalOnProperty(value = "nacos.discovery.enabled")
+@ConditionalOnProperty(value = "spring.cloud.nacos.discovery.enabled")
@Service
public class NacosUriSelector extends AbstractDiscoveryClientUriSelector {
private static final Logger log = LoggerFactory.getLogger(NacosUriSelector.class);
@@ -35,7 +31,7 @@ public class NacosUriSelector extends AbstractDiscoveryClientUriSelector {
@NacosInjected
private NamingService naming;
- private NacosDiscoveryProperties discoveryProperties;
+ final private NacosDiscoveryProperties discoveryProperties;
private String groupName;
private List clusterNameList;
private boolean useGroupName;
@@ -43,18 +39,14 @@ public class NacosUriSelector extends AbstractDiscoveryClientUriSelector {
@PostConstruct
public void init() {
- Register register = discoveryProperties.getRegister();
- if (register != null) {
- this.groupName = register.getGroupName();
- if (StringUtils.hasText(groupName)) {
- this.useGroupName = true;
- }
- String clusterName = register.getClusterName();
- if (StringUtils.hasText(clusterName)) {
- this.userClusterName = true;
- this.clusterNameList = Collections.singletonList(clusterName);
- }
-
+ this.groupName = discoveryProperties.getGroup();
+ if (StringUtils.hasText(groupName)) {
+ this.useGroupName = true;
+ }
+ String clusterName = discoveryProperties.getClusterName();
+ if (StringUtils.hasText(clusterName)) {
+ this.userClusterName = true;
+ this.clusterNameList = Collections.singletonList(clusterName);
}
}
diff --git a/fizz-core/src/main/java/we/proxy/dubbo/ApacheDubboGenericService.java b/fizz-core/src/main/java/we/proxy/dubbo/ApacheDubboGenericService.java
index c3f2a0e..15ffd62 100644
--- a/fizz-core/src/main/java/we/proxy/dubbo/ApacheDubboGenericService.java
+++ b/fizz-core/src/main/java/we/proxy/dubbo/ApacheDubboGenericService.java
@@ -17,7 +17,6 @@
package we.proxy.dubbo;
-import com.alibaba.nacos.api.config.annotation.NacosValue;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.dubbo.config.ApplicationConfig;
@@ -27,7 +26,6 @@ import org.apache.dubbo.config.utils.ReferenceConfigCache;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.rpc.service.GenericException;
import org.apache.dubbo.rpc.service.GenericService;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@@ -35,9 +33,9 @@ import reactor.core.publisher.Mono;
import we.fizz.exception.FizzException;
import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
import java.time.Duration;
-import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
@@ -49,10 +47,8 @@ import java.util.concurrent.CompletableFuture;
*/
@Service
public class ApacheDubboGenericService {
-
- @NacosValue(value = "${fizz-dubbo-client.address}")
- @Value("${fizz-dubbo-client.address}")
- private String zookeeperAddress = "";
+ @Resource
+ private ApacheDubboGenericServiceProperties apacheDubboGenericServiceProperties;
@PostConstruct
public void afterPropertiesSet() {
@@ -63,7 +59,7 @@ public class ApacheDubboGenericService {
ApplicationConfig applicationConfig = new ApplicationConfig();
applicationConfig.setName("fizz_proxy");
RegistryConfig registryConfig = new RegistryConfig();
- registryConfig.setAddress(zookeeperAddress);
+ registryConfig.setAddress(apacheDubboGenericServiceProperties.getZookeeperAddress());
ReferenceConfig referenceConfig = new ReferenceConfig<>();
referenceConfig.setInterface(serviceName);
applicationConfig.setRegistry(registryConfig);
diff --git a/fizz-core/src/main/java/we/proxy/dubbo/ApacheDubboGenericServiceProperties.java b/fizz-core/src/main/java/we/proxy/dubbo/ApacheDubboGenericServiceProperties.java
new file mode 100644
index 0000000..27d413a
--- /dev/null
+++ b/fizz-core/src/main/java/we/proxy/dubbo/ApacheDubboGenericServiceProperties.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2020 the original author or authors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package we.proxy.dubbo;
+
+import lombok.Data;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.cloud.context.config.annotation.RefreshScope;
+import org.springframework.stereotype.Component;
+
+/**
+ * {@link ApacheDubboGenericService} properties
+ *
+ * @author zhongjie
+ */
+@RefreshScope
+@Component
+@Data
+public class ApacheDubboGenericServiceProperties {
+ @Value("${fizz-dubbo-client.address}")
+ private String zookeeperAddress = "";
+}
diff --git a/fizz-plugin/pom.xml b/fizz-plugin/pom.xml
index 22ccbef..648af6f 100644
--- a/fizz-plugin/pom.xml
+++ b/fizz-plugin/pom.xml
@@ -133,19 +133,13 @@
- com.alibaba.boot
- nacos-config-spring-boot-starter
-
-
- org.springframework.boot
- spring-boot-starter-logging
-
-
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-config
- com.alibaba.boot
- nacos-discovery-spring-boot-starter
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
diff --git a/fizz-spring-boot-starter/pom.xml b/fizz-spring-boot-starter/pom.xml
index 0bff45c..a35041b 100644
--- a/fizz-spring-boot-starter/pom.xml
+++ b/fizz-spring-boot-starter/pom.xml
@@ -118,19 +118,13 @@
- com.alibaba.boot
- nacos-config-spring-boot-starter
-
-
- org.springframework.boot
- spring-boot-starter-logging
-
-
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-config
- com.alibaba.boot
- nacos-discovery-spring-boot-starter
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
diff --git a/pom.xml b/pom.xml
index 8816e31..64f5ff5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,7 +9,7 @@
5.2.15.RELEASE
Dysprosium-SR20
5.3.7.RELEASE
- 0.2.7
+ 2.2.5.RELEASE
4.1.65.Final
4.4.14
2.13.3
@@ -200,9 +200,9 @@
- com.alibaba.boot
- nacos-config-spring-boot-starter
- ${nacos.version}
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-config
+ ${nacos.cloud.version}
org.springframework.boot
@@ -212,9 +212,15 @@
- com.alibaba.boot
- nacos-discovery-spring-boot-starter
- ${nacos.version}
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
+ ${nacos.cloud.version}
+
+
+ org.springframework.boot
+ spring-boot-starter-logging
+
+