diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme-zh.md b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme-zh.md index a4b4d87ac..47b4a51dc 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme-zh.md +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme-zh.md @@ -204,7 +204,7 @@ Sentinel starter 整合了目前存在的几类 DataSource。只需要在配置 spring.cloud.sentinel.datasource.recommendRefreshMs=2000 spring.cloud.sentinel.datasource.bufSize=2048 spring.cloud.sentinel.datasource.charset=utf-8 - spring.cloud.sentinel.datasource.configParser=myParser + spring.cloud.sentinel.datasource.converter=myParser spring.cloud.sentinel.datasource.file=/Users/you/rule.json 然后使用`@SentinelDataSource` 注解修饰 DataSource 即可注入: @@ -220,7 +220,7 @@ Sentinel starter 整合了目前存在的几类 DataSource。只需要在配置 `spring.cloud.sentinel.datasource.recommendRefreshMs` 里的 `recommendRefreshMs` 对应相关 DataSource 的属性。 -`spring.cloud.sentinel.datasource.configParser`代表 `ConfigParser` 在 Spring 容器里的 name。如果没找到,会抛出异常。 +`spring.cloud.sentinel.datasource.converter`代表 `Converter` 在 Spring 容器里的 name。如果没找到,会抛出异常。 type目前支持file, nacos, zk, apollo。 @@ -260,7 +260,7 @@ type目前支持file, nacos, zk, apollo。 spring.cloud.sentinel.datasource.fieldA = valueA spring.cloud.sentinel.datasource.fieldB = valueB - 注意:由于目前Sentinel的AbstractDataSource需要有个ConfigParser作为构造函数中的参数,并且它的子类的构造都是通过多个参数的构造函数构造的。 + 注意:由于目前Sentinel的AbstractDataSource需要有个Converter作为构造函数中的参数,并且它的子类的构造都是通过多个参数的构造函数构造的。 所以目前所有的Sentinel starter中的DataSource都是基于FactoryBean并且通过设置属性构造的。如果有这方面的需求,需要再多加一个registerFactoryBean过程。 SentinelDataSourceRegistry.registerFactoryBean("custeom", CustomDataSourceFactoryBean.class); diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme.md b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme.md index cc0e3d730..06e189b9f 100644 --- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme.md +++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-core-example/readme.md @@ -177,7 +177,7 @@ If you want to define FileRefreshableDataSource: spring.cloud.sentinel.datasource.recommendRefreshMs=2000 spring.cloud.sentinel.datasource.bufSize=2048 spring.cloud.sentinel.datasource.charset=utf-8 - spring.cloud.sentinel.datasource.configParser=myParser + spring.cloud.sentinel.datasource.converter=myParser spring.cloud.sentinel.datasource.file=/Users/you/rule.json then use `@SentinelDataSource` to annotate DataSource: @@ -191,7 +191,7 @@ spring.cloud.sentinel.datasource.type means the type of DataSource. spring.cloud.sentinel.datasource.recommendRefreshMs means the recommendRefreshMs property of specified DataSource. -spring.cloud.sentinel.datasource.configParser means the name of spring bean that type is ConfigParser. If the bean is not exists, will throw exception. +spring.cloud.sentinel.datasource.converter means the name of spring bean that type is Converter. If the bean is not exists, will throw exception. Now datasource type support 4 categories: file, nacos, zk, apollo. @@ -230,7 +230,7 @@ User-defined DataSource need 2 steps. spring.cloud.sentinel.datasource.fieldA = valueA spring.cloud.sentinel.datasource.fieldB = valueB -Note: The AbstractDataSource of Sentinel need a ConfigParser as a constructor param and the subclass of AbstractDataSource was construct by multi-param constructor. +Note: The AbstractDataSource of Sentinel need a Converter as a constructor param and the subclass of AbstractDataSource was construct by multi-param constructor. Now All DataSources in starter was construct by FactoryBean. If you want to do it in this way, you should register FactoryBean by SentinelDataSourceRegistry. SentinelDataSourceRegistry.registerFactoryBean("custeom", CustomDataSourceFactoryBean.class); diff --git a/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/annotation/SentinelDataSource.java b/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/annotation/SentinelDataSource.java index 73a8ee173..93ef1bdb9 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/annotation/SentinelDataSource.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/annotation/SentinelDataSource.java @@ -16,19 +16,25 @@ package org.springframework.cloud.alibaba.sentinel.annotation; -import java.lang.annotation.*; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import com.alibaba.csp.sentinel.datasource.ReadableDataSource; import org.springframework.core.annotation.AliasFor; /** - * An annotation to inject {@link com.alibaba.csp.sentinel.datasource.DataSource} instance + * An annotation to inject {@link ReadableDataSource} instance * into a Spring Bean. The Properties of DataSource bean get from config files with * specific prefix. * * @author fangjian - * @see com.alibaba.csp.sentinel.datasource.DataSource + * @see ReadableDataSource */ -@Target({ ElementType.FIELD }) +@Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface SentinelDataSource { diff --git a/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/SentinelDataSourceRegistry.java b/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/SentinelDataSourceRegistry.java index f9917a806..ceb90ee1f 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/SentinelDataSourceRegistry.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/datasource/SentinelDataSourceRegistry.java @@ -18,6 +18,8 @@ package org.springframework.cloud.alibaba.sentinel.datasource; import java.util.concurrent.ConcurrentHashMap; +import com.alibaba.csp.sentinel.datasource.ReadableDataSource; + import org.springframework.beans.factory.FactoryBean; import org.springframework.cloud.alibaba.sentinel.datasource.factorybean.ApolloDataSourceFactoryBean; import org.springframework.cloud.alibaba.sentinel.datasource.factorybean.FileRefreshableDataSourceFactoryBean; @@ -28,7 +30,7 @@ import org.springframework.cloud.alibaba.sentinel.datasource.factorybean.Zookeep * Registry to save DataSource FactoryBean * * @author fangjian - * @see com.alibaba.csp.sentinel.datasource.DataSource + * @see ReadableDataSource * @see FileRefreshableDataSourceFactoryBean * @see ZookeeperDataSourceFactoryBean * @see NacosDataSourceFactoryBean @@ -37,17 +39,17 @@ import org.springframework.cloud.alibaba.sentinel.datasource.factorybean.Zookeep public class SentinelDataSourceRegistry { private static ConcurrentHashMap> cache = new ConcurrentHashMap<>( - 32); + 32); static { SentinelDataSourceRegistry.registerFactoryBean("file", - FileRefreshableDataSourceFactoryBean.class); + FileRefreshableDataSourceFactoryBean.class); SentinelDataSourceRegistry.registerFactoryBean("zk", - ZookeeperDataSourceFactoryBean.class); + ZookeeperDataSourceFactoryBean.class); SentinelDataSourceRegistry.registerFactoryBean("nacos", - NacosDataSourceFactoryBean.class); + NacosDataSourceFactoryBean.class); SentinelDataSourceRegistry.registerFactoryBean("apollo", - ApolloDataSourceFactoryBean.class); + ApolloDataSourceFactoryBean.class); } public static synchronized void registerFactoryBean(String alias,