diff --git a/sentinel-extension/sentinel-datasource-spring-cloud-config/README.md b/sentinel-extension/sentinel-datasource-spring-cloud-config/README.md index 5637536d..aa53afb8 100644 --- a/sentinel-extension/sentinel-datasource-spring-cloud-config/README.md +++ b/sentinel-extension/sentinel-datasource-spring-cloud-config/README.md @@ -1,9 +1,9 @@ -# Sentinel DataSource SpringCloudConfig +# Sentinel DataSource Spring Cloud Config -Sentinel DataSource SpringCloudConfig provides integration with SpringCloudConfig so that SpringCloudConfig -can be the dynamic rule data source of Sentinel. +Sentinel DataSource Spring Cloud Config provides integration with Spring Cloud Config +so that Spring Cloud Config can be the dynamic rule data source of Sentinel. -To use Sentinel DataSource SpringCloudConfig, you should add the following dependency: +To use Sentinel DataSource Spring Cloud Config, you should add the following dependency: ```xml @@ -17,32 +17,25 @@ Then you can create an `SpringCloudConfigDataSource` and register to rule manage For instance: ```Java -//flow_rule is the propery key in SpringConfigConfig -SpringCloudConfigDataSource dataSource = new SpringCloudConfigDataSource("flow_rule", new Converter>() { - @Override - public List convert(String source) { - return JSON.parseArray(source, FlowRule.class); - } - }); - FlowRuleManager.register2Property(dataSource.getProperty()); +ReadableDataSource> flowRuleDs = new SpringCloudConfigDataSource<>(ruleKey, s -> JSON.parseArray(s, FlowRule.class)); +FlowRuleManager.register2Property(flowRuleDs.getProperty()); ``` -If the client want to perceive the remote config changed, it can binding a git webhook callback with the ```com.alibaba.csp.sentinel.datasource.spring.cloud.config.SentinelRuleLocator.refresh``` - API. Like test demo ```com.alibaba.csp.sentinel.datasource.spring.cloud.config.test.SpringCouldDataSourceTest.refresh``` do. +To notify the client that the remote config has changed, we could bind a git webhook callback with the +`com.alibaba.csp.sentinel.datasource.spring.cloud.config.SentinelRuleLocator.refresh` API. +We may refer to the the sample `com.alibaba.csp.sentinel.datasource.spring.cloud.config.test.SpringCouldDataSourceTest#refresh` in test cases. - -We offer test cases and demo in: -[com.alibaba.csp.sentinel.datasource.spring.cloud.config.test]. -When you run test cases, please follow the steps: +We offer test cases and demo in the package: `com.alibaba.csp.sentinel.datasource.spring.cloud.config.test`. +When you are running test cases, please follow the steps: ``` -//first start config server +// First, start the Spring Cloud config server com.alibaba.csp.sentinel.datasource.spring.cloud.config.server.ConfigServer -//second start config client +// Second, start the Spring Cloud config client com.alibaba.csp.sentinel.datasource.spring.cloud.config.client.ConfigClient -//third run test cases and demo +// Third, run the test cases and demo com.alibaba.csp.sentinel.datasource.spring.cloud.config.test.SentinelRuleLocatorTests com.alibaba.csp.sentinel.datasource.spring.cloud.config.test.SpringCouldDataSourceTest ``` \ No newline at end of file diff --git a/sentinel-extension/sentinel-datasource-spring-cloud-config/src/main/java/com/alibaba/csp/sentinel/datasource/spring/cloud/config/SpringCloudConfigDataSource.java b/sentinel-extension/sentinel-datasource-spring-cloud-config/src/main/java/com/alibaba/csp/sentinel/datasource/spring/cloud/config/SpringCloudConfigDataSource.java index 085e3634..093dcf88 100644 --- a/sentinel-extension/sentinel-datasource-spring-cloud-config/src/main/java/com/alibaba/csp/sentinel/datasource/spring/cloud/config/SpringCloudConfigDataSource.java +++ b/sentinel-extension/sentinel-datasource-spring-cloud-config/src/main/java/com/alibaba/csp/sentinel/datasource/spring/cloud/config/SpringCloudConfigDataSource.java @@ -24,25 +24,29 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; /** - * ${@link SpringCloudConfigDataSource} A read-only {@code DataSource} with spring-cloud-config backend - * It retrieve the spring-cloud-config data stored in ${@link SentinelRuleStorage} - * When the data in backend has been modified, ${@link SentinelRuleStorage} will invoke ${@link SpringCloudConfigDataSource#updateValues()} - * to dynamic update values + *

A read-only {@code DataSource} with Spring Cloud Config backend.

+ *

+ * It retrieves the Spring Cloud Config data stored in {@link SentinelRuleStorage}. + * When the data in the backend has been modified, {@link SentinelRuleStorage} will + * invoke {@link SpringCloudConfigDataSource#updateValues()} to update values dynamically. + *

+ *

+ * To notify the client that the remote config has changed, users could bind a git + * webhook callback with the {@link SentinelRuleLocator#refresh()} API. + *

* * @author lianglin * @since 1.7.0 */ public class SpringCloudConfigDataSource extends AbstractDataSource { - private final static Map listeners; static { listeners = new ConcurrentHashMap<>(); } - private String ruleKey; - + private final String ruleKey; public SpringCloudConfigDataSource(final String ruleKey, Converter converter) { super(converter); @@ -103,7 +107,5 @@ public class SpringCloudConfigDataSource extends AbstractDataSource