Refine the document and javadoc for Spring Cloud Config data-source module

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
This commit is contained in:
Eric Zhao 2019-08-20 10:04:58 +08:00
parent 30158bcac0
commit 976ddf8c48
2 changed files with 25 additions and 30 deletions

View File

@ -1,9 +1,9 @@
# Sentinel DataSource SpringCloudConfig # Sentinel DataSource Spring Cloud Config
Sentinel DataSource SpringCloudConfig provides integration with SpringCloudConfig so that SpringCloudConfig Sentinel DataSource Spring Cloud Config provides integration with Spring Cloud Config
can be the dynamic rule data source of Sentinel. 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 ```xml
<dependency> <dependency>
@ -17,32 +17,25 @@ Then you can create an `SpringCloudConfigDataSource` and register to rule manage
For instance: For instance:
```Java ```Java
//flow_rule is the propery key in SpringConfigConfig ReadableDataSource<String, List<FlowRule>> flowRuleDs = new SpringCloudConfigDataSource<>(ruleKey, s -> JSON.parseArray(s, FlowRule.class));
SpringCloudConfigDataSource dataSource = new SpringCloudConfigDataSource("flow_rule", new Converter<String, List<FlowRule>>() { FlowRuleManager.register2Property(flowRuleDs.getProperty());
@Override
public List<FlowRule> convert(String source) {
return JSON.parseArray(source, FlowRule.class);
}
});
FlowRuleManager.register2Property(dataSource.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``` To notify the client that the remote config has changed, we could bind a git webhook callback with the
API. Like test demo ```com.alibaba.csp.sentinel.datasource.spring.cloud.config.test.SpringCouldDataSourceTest.refresh``` do. `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 the package: `com.alibaba.csp.sentinel.datasource.spring.cloud.config.test`.
We offer test cases and demo in: When you are running test cases, please follow the steps:
[com.alibaba.csp.sentinel.datasource.spring.cloud.config.test].
When you run 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 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 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.SentinelRuleLocatorTests
com.alibaba.csp.sentinel.datasource.spring.cloud.config.test.SpringCouldDataSourceTest com.alibaba.csp.sentinel.datasource.spring.cloud.config.test.SpringCouldDataSourceTest
``` ```

View File

@ -24,25 +24,29 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/** /**
* ${@link SpringCloudConfigDataSource} A read-only {@code DataSource} with spring-cloud-config backend * <p>A read-only {@code DataSource} with Spring Cloud Config backend.</p>
* It retrieve the spring-cloud-config data stored in ${@link SentinelRuleStorage} * <p>
* When the data in backend has been modified, ${@link SentinelRuleStorage} will invoke ${@link SpringCloudConfigDataSource#updateValues()} * It retrieves the Spring Cloud Config data stored in {@link SentinelRuleStorage}.
* to dynamic update values * When the data in the backend has been modified, {@link SentinelRuleStorage} will
* invoke {@link SpringCloudConfigDataSource#updateValues()} to update values dynamically.
* </p>
* <p>
* To notify the client that the remote config has changed, users could bind a git
* webhook callback with the {@link SentinelRuleLocator#refresh()} API.
* </p>
* *
* @author lianglin * @author lianglin
* @since 1.7.0 * @since 1.7.0
*/ */
public class SpringCloudConfigDataSource<T> extends AbstractDataSource<String, T> { public class SpringCloudConfigDataSource<T> extends AbstractDataSource<String, T> {
private final static Map<SpringCloudConfigDataSource, SpringConfigListener> listeners; private final static Map<SpringCloudConfigDataSource, SpringConfigListener> listeners;
static { static {
listeners = new ConcurrentHashMap<>(); listeners = new ConcurrentHashMap<>();
} }
private String ruleKey; private final String ruleKey;
public SpringCloudConfigDataSource(final String ruleKey, Converter<String, T> converter) { public SpringCloudConfigDataSource(final String ruleKey, Converter<String, T> converter) {
super(converter); super(converter);
@ -103,7 +107,5 @@ public class SpringCloudConfigDataSource<T> extends AbstractDataSource<String, T
RecordLog.warn("[SpringConfigListener] load config error: ", e); RecordLog.warn("[SpringConfigListener] load config error: ", e);
} }
} }
} }
} }