1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

Merge pull request #4 from spring-cloud-incubator/1.x

Merge
This commit is contained in:
Neptune 2018-10-21 18:07:06 +08:00 committed by GitHub
commit 5bb5375bef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
74 changed files with 910 additions and 595 deletions

View File

@ -48,7 +48,7 @@ Example 列表:
[Nacos Discovery Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme-zh.md) [Nacos Discovery Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme-zh.md)
[AliCloud OSS Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/storage-example/readme-zh.md) [AliCloud OSS Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/oss-example/readme-zh.md)
## 版本管理规范 ## 版本管理规范
项目的版本号格式为 x.x.x 的形式,其中 x 的数值类型为数字从0开始取值且不限于 0~9 这个范围。项目处于孵化器阶段时第一位版本号固定使用0即版本号为 0.x.x 的格式。 项目的版本号格式为 x.x.x 的形式,其中 x 的数值类型为数字从0开始取值且不限于 0~9 这个范围。项目处于孵化器阶段时第一位版本号固定使用0即版本号为 0.x.x 的格式。

View File

@ -47,7 +47,7 @@ Examples
[Nacos Discovery Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme.md) [Nacos Discovery Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/nacos-example/nacos-discovery-example/readme.md)
[AliCloud OSS Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/storage-example/readme.md) [AliCloud OSS Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/oss-example/readme.md)
## Version control guidelines ## Version control guidelines
The version number of the project is in the form of x.x.x, where x is a number, starting from 0, and is not limited to the range 0~9. When the project is in the incubator phase, the first version number is fixed to 0, that is, the version number is 0.x.x. The version number of the project is in the form of x.x.x, where x is a number, starting from 0, and is not limited to the range 0~9. When the project is in the incubator phase, the first version number is fixed to 0, that is, the version number is 0.x.x.

View File

@ -8,13 +8,13 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-build</artifactId> <artifactId>spring-cloud-build</artifactId>
<version>1.3.8.RELEASE</version> <version>1.3.10.RELEASE</version>
<relativePath/> <relativePath/>
</parent> </parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba</artifactId> <artifactId>spring-cloud-alibaba</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>Spring Cloud Alibaba</name> <name>Spring Cloud Alibaba</name>
@ -73,12 +73,14 @@
<modules> <modules>
<module>spring-cloud-alibaba-dependencies</module> <module>spring-cloud-alibaba-dependencies</module>
<module>spring-cloud-alibaba-sentinel</module> <module>spring-cloud-alibaba-sentinel</module>
<module>spring-cloud-alibaba-storage</module>
<module>spring-cloud-alibaba-nacos-config</module> <module>spring-cloud-alibaba-nacos-config</module>
<module>spring-cloud-alibaba-nacos-discovery</module> <module>spring-cloud-alibaba-nacos-discovery</module>
<module>spring-cloud-alibaba-examples</module> <module>spring-cloud-alibaba-examples</module>
<module>spring-cloud-alibaba-test</module> <module>spring-cloud-alibaba-test</module>
<module>spring-cloud-starter-alibaba</module> <module>spring-cloud-starter-alibaba</module>
<module>spring-cloud-starter-alicloud</module>
<module>spring-cloud-alicloud-oss</module>
</modules> </modules>
<dependencyManagement> <dependencyManagement>

View File

@ -6,19 +6,19 @@
<parent> <parent>
<artifactId>spring-cloud-dependencies-parent</artifactId> <artifactId>spring-cloud-dependencies-parent</artifactId>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<version>1.3.3.BUILD-SNAPSHOT</version> <version>1.3.10.RELEASE</version>
<relativePath/> <relativePath/>
</parent> </parent>
<artifactId>spring-cloud-alibaba-dependencies</artifactId> <artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>Spring Cloud Alibaba Dependencies</name> <name>Spring Cloud Alibaba Dependencies</name>
<description>Spring Cloud Alibaba Dependencies</description> <description>Spring Cloud Alibaba Dependencies</description>
<properties> <properties>
<sentinel.version>0.1.1</sentinel.version> <sentinel.version>0.2.0</sentinel.version>
<oss.version>3.1.0</oss.version> <oss.version>3.1.0</oss.version>
<nacos.version>0.2.1-RC1</nacos.version> <nacos.version>0.2.1</nacos.version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
@ -98,7 +98,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-storage</artifactId> <artifactId>spring-cloud-alicloud-oss</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
@ -120,7 +120,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-storage</artifactId> <artifactId>spring-cloud-starter-alicloud-oss</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId> <artifactId>spring-cloud-alibaba-examples</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>nacos-discovery-example</artifactId> <artifactId>nacos-discovery-example</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>nacos-discovery-example</artifactId> <artifactId>nacos-discovery-example</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId> <artifactId>spring-cloud-alibaba-examples</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,14 +5,14 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId> <artifactId>spring-cloud-alibaba-examples</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>storage-example</artifactId> <artifactId>oss-example</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<description>Example demonstrating how to use storage</description> <description>Example demonstrating how to use alicloud oss</description>
<dependencies> <dependencies>
@ -22,7 +22,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-storage</artifactId> <artifactId>spring-cloud-starter-alicloud-oss</artifactId>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -13,11 +13,11 @@
**注意:本节只是为了便于您理解接入方式,本示例代码中已经完成接入工作,您只需修改 accessKeyId、secretAccessKey、region 即可。** **注意:本节只是为了便于您理解接入方式,本示例代码中已经完成接入工作,您只需修改 accessKeyId、secretAccessKey、region 即可。**
1. 修改 pom.xml 文件,引入 Storage starter。 1. 修改 pom.xml 文件,引入 OSS starter。
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-storage</artifactId> <artifactId>spring-cloud-starter-alicloud-oss</artifactId>
</dependency> </dependency>
2. 在配置文件中配置 OSS 服务对应的 accessKeyId、secretAccessKey 和 region。 2. 在配置文件中配置 OSS 服务对应的 accessKeyId、secretAccessKey 和 region。

View File

@ -1,4 +1,4 @@
# Storage Example # OSS Example
## Introduction ## Introduction
If your applications are Spring Cloud applications and you need to use Alibaba Cloud's OSS service for file storage (for example, storing commodity image for your e-commerce business), you can use OSS starter. This topic provides an example to illustrate how to use OSS starter to implement object storage for Spring Cloud applications. If your applications are Spring Cloud applications and you need to use Alibaba Cloud's OSS service for file storage (for example, storing commodity image for your e-commerce business), you can use OSS starter. This topic provides an example to illustrate how to use OSS starter to implement object storage for Spring Cloud applications.
@ -13,11 +13,11 @@ If your applications are Spring Cloud applications and you need to use Alibaba C
Before we start the demo, let's learn how to connect OSS to a Spring Cloud application. Before we start the demo, let's learn how to connect OSS to a Spring Cloud application.
**Note: This section is to show you how to connect to oss. The actual configurations have been completed in the following example, and you only need to specify your accessKeyId, secretAccessKey and region.** **Note: This section is to show you how to connect to oss. The actual configurations have been completed in the following example, and you only need to specify your accessKeyId, secretAccessKey and region.**
1. Add dependency spring-cloud-starter-alibaba-storage in the pom.xml file in your Spring Cloud project. 1. Add dependency spring-cloud-starter-alicloud-oss in the pom.xml file in your Spring Cloud project.
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-storage</artifactId> <artifactId>spring-cloud-starter-alicloud-oss</artifactId>
</dependency> </dependency>
2. Configure accessKeyId, secretAccessKey and region in application.properties. 2. Configure accessKeyId, secretAccessKey and region in application.properties.

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba</artifactId> <artifactId>spring-cloud-alibaba</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@ -22,7 +22,7 @@
<module>sentinel-example/sentinel-dubbo-example/sentinel-dubbo-api</module> <module>sentinel-example/sentinel-dubbo-example/sentinel-dubbo-api</module>
<module>nacos-example/nacos-discovery-example</module> <module>nacos-example/nacos-discovery-example</module>
<module>nacos-example/nacos-config-example</module> <module>nacos-example/nacos-config-example</module>
<module>storage-example</module> <module>oss-example</module>
</modules> </modules>
<build> <build>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId> <artifactId>spring-cloud-alibaba-examples</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
<relativePath>../../pom.xml</relativePath> <relativePath>../../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -78,7 +78,7 @@
``` ```
spring.application.name=sentinel-example spring.application.name=sentinel-example
server.port=18083 server.port=18083
spring.cloud.sentinel.dashboard=localhost:8080 spring.cloud.sentinel.transport.dashboard=localhost:8080
``` ```
2. 启动应用,支持 IDE 直接启动和编译打包后启动。 2. 启动应用,支持 IDE 直接启动和编译打包后启动。
@ -204,7 +204,7 @@ Sentinel starter 整合了目前存在的几类 DataSource。只需要在配置
spring.cloud.sentinel.datasource.recommendRefreshMs=2000 spring.cloud.sentinel.datasource.recommendRefreshMs=2000
spring.cloud.sentinel.datasource.bufSize=2048 spring.cloud.sentinel.datasource.bufSize=2048
spring.cloud.sentinel.datasource.charset=utf-8 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 spring.cloud.sentinel.datasource.file=/Users/you/rule.json
然后使用`@SentinelDataSource` 注解修饰 DataSource 即可注入: 然后使用`@SentinelDataSource` 注解修饰 DataSource 即可注入:
@ -220,7 +220,7 @@ Sentinel starter 整合了目前存在的几类 DataSource。只需要在配置
`spring.cloud.sentinel.datasource.recommendRefreshMs` 里的 `recommendRefreshMs` 对应相关 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。 type目前支持file, nacos, zk, apollo。
@ -260,7 +260,7 @@ type目前支持file, nacos, zk, apollo。
spring.cloud.sentinel.datasource.fieldA = valueA spring.cloud.sentinel.datasource.fieldA = valueA
spring.cloud.sentinel.datasource.fieldB = valueB spring.cloud.sentinel.datasource.fieldB = valueB
注意由于目前Sentinel的AbstractDataSource需要有个ConfigParser作为构造函数中的参数并且它的子类的构造都是通过多个参数的构造函数构造的。 注意由于目前Sentinel的AbstractDataSource需要有个Converter作为构造函数中的参数并且它的子类的构造都是通过多个参数的构造函数构造的。
所以目前所有的Sentinel starter中的DataSource都是基于FactoryBean并且通过设置属性构造的。如果有这方面的需求需要再多加一个registerFactoryBean过程。 所以目前所有的Sentinel starter中的DataSource都是基于FactoryBean并且通过设置属性构造的。如果有这方面的需求需要再多加一个registerFactoryBean过程。
SentinelDataSourceRegistry.registerFactoryBean("custeom", CustomDataSourceFactoryBean.class); SentinelDataSourceRegistry.registerFactoryBean("custeom", CustomDataSourceFactoryBean.class);

View File

@ -66,7 +66,7 @@ Before we start the demo, let's learn how to connect Sentinel to a Spring Cloud
spring.application.name=sentinel-example spring.application.name=sentinel-example
server.port=18083 server.port=18083
spring.cloud.sentinel.dashboard=localhost:8080 spring.cloud.sentinel.transport.dashboard=localhost:8080
2. Start the application in IDE or by building a fatjar. 2. Start the application in IDE or by building a fatjar.
@ -177,7 +177,7 @@ If you want to define FileRefreshableDataSource:
spring.cloud.sentinel.datasource.recommendRefreshMs=2000 spring.cloud.sentinel.datasource.recommendRefreshMs=2000
spring.cloud.sentinel.datasource.bufSize=2048 spring.cloud.sentinel.datasource.bufSize=2048
spring.cloud.sentinel.datasource.charset=utf-8 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 spring.cloud.sentinel.datasource.file=/Users/you/rule.json
then use `@SentinelDataSource` to annotate DataSource: 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.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. 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.fieldA = valueA
spring.cloud.sentinel.datasource.fieldB = valueB 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. 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); SentinelDataSourceRegistry.registerFactoryBean("custeom", CustomDataSourceFactoryBean.class);

View File

@ -2,7 +2,7 @@ package org.springframework.cloud.alibaba.cloud.examples;
import java.util.List; import java.util.List;
import com.alibaba.csp.sentinel.datasource.ConfigParser; import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule; import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.TypeReference;
@ -10,9 +10,10 @@ import com.alibaba.fastjson.TypeReference;
/** /**
* @author fangjian * @author fangjian
*/ */
public class JsonFlowRuleListParser implements ConfigParser<String, List<FlowRule>> { public class JsonFlowRuleListParser implements Converter<String, List<FlowRule>> {
@Override @Override
public List<FlowRule> parse(String source) { public List<FlowRule> convert(String source) {
return JSON.parseObject(source, new TypeReference<List<FlowRule>>() {}); return JSON.parseObject(source, new TypeReference<List<FlowRule>>() {
});
} }
} }

View File

@ -6,7 +6,7 @@ import org.springframework.cloud.alibaba.sentinel.annotation.SentinelProtect;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import com.alibaba.csp.sentinel.datasource.ConfigParser; import com.alibaba.csp.sentinel.datasource.Converter;
/** /**
* @author xiaojing * @author xiaojing
@ -26,7 +26,7 @@ public class ServiceApplication {
} }
@Bean @Bean
public ConfigParser myParser() { public Converter myParser() {
return new JsonFlowRuleListParser(); return new JsonFlowRuleListParser();
} }

View File

@ -1,8 +1,8 @@
spring.application.name=sentinel-example spring.application.name=sentinel-example
server.port=18083 server.port=18083
management.security.enabled=false management.security.enabled=false
spring.cloud.sentinel.port=8721 spring.cloud.sentinel.transport.port=8721
spring.cloud.sentinel.dashboard=localhost:8080 spring.cloud.sentinel.transport.dashboard=localhost:8080

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId> <artifactId>spring-cloud-alibaba-examples</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
<relativePath>../../../pom.xml</relativePath> <relativePath>../../../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId> <artifactId>spring-cloud-alibaba-examples</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
<relativePath>../../../pom.xml</relativePath> <relativePath>../../../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId> <artifactId>spring-cloud-alibaba-examples</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
<relativePath>../../../pom.xml</relativePath> <relativePath>../../../pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba</artifactId> <artifactId>spring-cloud-alibaba</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -28,6 +28,8 @@ import com.alibaba.nacos.api.exception.NacosException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
@ -83,12 +85,23 @@ public class NacosPropertySourceBuilder {
data = configService.getConfig(dataId, group, timeout); data = configService.getConfig(dataId, group, timeout);
// todo add file extension yaml support // todo add file extension yaml support
if (!StringUtils.isEmpty(data)) { if (!StringUtils.isEmpty(data)) {
Properties properties = new Properties();
logger.info(String.format("Loading nacos data, dataId: '%s', group: '%s'", logger.info(String.format("Loading nacos data, dataId: '%s', group: '%s'",
dataId, group)); dataId, group));
if (fileExtension.equalsIgnoreCase("properties")) {
Properties properties = new Properties();
properties.load(new StringReader(data)); properties.load(new StringReader(data));
return properties; return properties;
} }
else if (fileExtension.equalsIgnoreCase("yaml")
|| fileExtension.equalsIgnoreCase("yml")) {
YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
yamlFactory.setResources(new ByteArrayResource(data.getBytes()));
return yamlFactory.getObject();
}
}
} }
catch (NacosException e) { catch (NacosException e) {
logger.error("get data from Nacos error,dataId:{}, ", dataId, e); logger.error("get data from Nacos error,dataId:{}, ", dataId, e);

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba</artifactId> <artifactId>spring-cloud-alibaba</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -16,7 +16,6 @@
package org.springframework.cloud.alibaba.nacos; package org.springframework.cloud.alibaba.nacos;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@ -48,12 +47,6 @@ public class NacosDiscoveryAutoConfiguration {
return new NacosServiceRegistry(); return new NacosServiceRegistry();
} }
@Bean
@ConditionalOnMissingBean
public NacosDiscoveryProperties nacosProperties() {
return new NacosDiscoveryProperties();
}
@Bean @Bean
@ConditionalOnBean(AutoServiceRegistrationProperties.class) @ConditionalOnBean(AutoServiceRegistrationProperties.class)
public NacosRegistration nacosRegistration() { public NacosRegistration nacosRegistration() {

View File

@ -19,13 +19,15 @@ package org.springframework.cloud.alibaba.nacos;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.alibaba.nacos.registry.NacosRegistration; import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient; import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.core.env.Environment;
import java.net.URI;
import java.util.*; import java.util.*;
import javax.annotation.PostConstruct;
import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance; import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ListView; import com.alibaba.nacos.api.naming.pojo.ListView;
@ -40,53 +42,38 @@ public class NacosDiscoveryClient implements DiscoveryClient {
public static final String DESCRIPTION = "Spring Cloud Nacos Discovery Client"; public static final String DESCRIPTION = "Spring Cloud Nacos Discovery Client";
@Autowired @Autowired
private NacosRegistration nacosRegistration; private NacosDiscoveryProperties discoveryProperties;
@Autowired
private Environment environment;
private NamingService namingService;
@Override @Override
public String description() { public String description() {
return DESCRIPTION; return DESCRIPTION;
} }
@PostConstruct
public void init() {
discoveryProperties.overrideFromEnv(environment);
namingService = discoveryProperties.getNamingService();
}
@Override @Override
public ServiceInstance getLocalServiceInstance() { public ServiceInstance getLocalServiceInstance() {
return new ServiceInstance() { String serviceId = discoveryProperties.getService();
@Override String host = discoveryProperties.getIp();
public String getServiceId() { int port = discoveryProperties.getPort();
return nacosRegistration.getServiceId(); boolean secure = discoveryProperties.isSecure();
} Map<String, String> metadata = discoveryProperties.getMetadata();
return new DefaultServiceInstance(serviceId, host, port, secure, metadata);
@Override
public String getHost() {
return nacosRegistration.getHost();
}
@Override
public int getPort() {
return nacosRegistration.getPort();
}
@Override
public boolean isSecure() {
return nacosRegistration.isSecure();
}
@Override
public URI getUri() {
return nacosRegistration.getUri();
}
@Override
public Map<String, String> getMetadata() {
return nacosRegistration.getMetadata();
}
};
} }
@Override @Override
public List<ServiceInstance> getInstances(String serviceId) { public List<ServiceInstance> getInstances(String serviceId) {
try { try {
NamingService namingService = nacosRegistration.getNacosNamingService(); List<Instance> instances = namingService.getAllInstances(serviceId);
List<Instance> instances = namingService.selectInstances(serviceId, true);
return hostToServiceInstanceList(instances, serviceId); return hostToServiceInstanceList(instances, serviceId);
} }
catch (Exception e) { catch (Exception e) {
@ -115,8 +102,10 @@ public class NacosDiscoveryClient implements DiscoveryClient {
List<Instance> instances, String serviceId) { List<Instance> instances, String serviceId) {
List<ServiceInstance> result = new ArrayList<ServiceInstance>(instances.size()); List<ServiceInstance> result = new ArrayList<ServiceInstance>(instances.size());
for (Instance instance : instances) { for (Instance instance : instances) {
if (instance.isHealthy()) {
result.add(hostToServiceInstance(instance, serviceId)); result.add(hostToServiceInstance(instance, serviceId));
} }
}
return result; return result;
} }
@ -124,7 +113,6 @@ public class NacosDiscoveryClient implements DiscoveryClient {
public List<String> getServices() { public List<String> getServices() {
try { try {
NamingService namingService = nacosRegistration.getNacosNamingService();
ListView<String> services = namingService.getServicesOfServer(1, ListView<String> services = namingService.getServicesOfServer(1,
Integer.MAX_VALUE); Integer.MAX_VALUE);
return services.getData(); return services.getData();
@ -135,4 +123,7 @@ public class NacosDiscoveryClient implements DiscoveryClient {
} }
} }
public NamingService getNamingService() {
return namingService;
}
} }

View File

@ -36,4 +36,10 @@ public class NacosDiscoveryClientAutoConfiguration {
return new NacosDiscoveryClient(); return new NacosDiscoveryClient();
} }
@Bean
@ConditionalOnMissingBean
public NacosDiscoveryProperties nacosProperties() {
return new NacosDiscoveryProperties();
}
} }

View File

@ -16,6 +16,8 @@
package org.springframework.cloud.alibaba.nacos; package org.springframework.cloud.alibaba.nacos;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
@ -33,6 +35,18 @@ import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Properties;
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
import static com.alibaba.nacos.api.PropertyKeyConst.ACCESS_KEY;
import static com.alibaba.nacos.api.PropertyKeyConst.CLUSTER_NAME;
import static com.alibaba.nacos.api.PropertyKeyConst.ENDPOINT;
import static com.alibaba.nacos.api.PropertyKeyConst.NAMESPACE;
import static com.alibaba.nacos.api.PropertyKeyConst.SECRET_KEY;
import static com.alibaba.nacos.api.PropertyKeyConst.SERVER_ADDR;
/** /**
* @author dungu.zpf * @author dungu.zpf
@ -42,6 +56,9 @@ import java.util.Objects;
@ConfigurationProperties("spring.cloud.nacos.discovery") @ConfigurationProperties("spring.cloud.nacos.discovery")
public class NacosDiscoveryProperties { public class NacosDiscoveryProperties {
private static final Logger LOGGER = LoggerFactory
.getLogger(NacosDiscoveryProperties.class);
/** /**
* nacos discovery server address * nacos discovery server address
*/ */
@ -333,4 +350,22 @@ public class NacosDiscoveryProperties {
} }
} }
public NamingService getNamingService() {
Properties properties = new Properties();
properties.put(SERVER_ADDR, serverAddr);
properties.put(NAMESPACE, namespace);
properties.put(UtilAndComs.NACOS_NAMING_LOG_NAME, logName);
properties.put(ENDPOINT, endpoint);
properties.put(ACCESS_KEY, accessKey);
properties.put(SECRET_KEY, secretKey);
properties.put(CLUSTER_NAME, clusterName);
try {
return NacosFactory.createNamingService(properties);
}
catch (Exception e) {
LOGGER.error("create naming service error!properties={},e=,", this, e);
return null;
}
}
} }

View File

@ -28,8 +28,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.AbstractEndpoint; import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryClient;
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties; import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties;
import org.springframework.cloud.alibaba.nacos.registry.NacosRegistration;
/** /**
* Endpoint for nacos discovery, get nacos properties and subscribed services * Endpoint for nacos discovery, get nacos properties and subscribed services
@ -44,7 +44,7 @@ public class NacosDiscoveryEndpoint extends AbstractEndpoint<Map<String, Object>
private NacosDiscoveryProperties nacosDiscoveryProperties; private NacosDiscoveryProperties nacosDiscoveryProperties;
@Autowired @Autowired
private NacosRegistration nacosRegistration; private NacosDiscoveryClient discoveryClient;
public NacosDiscoveryEndpoint() { public NacosDiscoveryEndpoint() {
super("nacos_discovery", false); super("nacos_discovery", false);
@ -58,7 +58,7 @@ public class NacosDiscoveryEndpoint extends AbstractEndpoint<Map<String, Object>
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
result.put("NacosDiscoveryProperties", nacosDiscoveryProperties); result.put("NacosDiscoveryProperties", nacosDiscoveryProperties);
NamingService namingService = nacosRegistration.getNacosNamingService(); NamingService namingService = discoveryClient.getNamingService();
List<ServiceInfo> subscribe = Collections.emptyList(); List<ServiceInfo> subscribe = Collections.emptyList();
try { try {

View File

@ -26,7 +26,6 @@ import org.springframework.context.annotation.Configuration;
* @author xiaojing * @author xiaojing
*/ */
@Configuration @Configuration
@ConditionalOnProperty(value = "spring.cloud.service-registry.auto-registration.enabled", matchIfMissing = true)
@ConditionalOnClass(name = "org.springframework.boot.actuate.endpoint.AbstractEndpoint") @ConditionalOnClass(name = "org.springframework.boot.actuate.endpoint.AbstractEndpoint")
public class NacosDiscoveryEndpointAutoConfiguration { public class NacosDiscoveryEndpointAutoConfiguration {

View File

@ -20,52 +20,55 @@ import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.DefaultServiceInstance; import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.ManagementServerPortUtils;
import org.springframework.cloud.client.serviceregistry.Registration; import org.springframework.cloud.client.serviceregistry.Registration;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.naming.NamingService; import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.client.naming.utils.UtilAndComs;
import static com.alibaba.nacos.api.PropertyKeyConst.*;
/** /**
* @author xiaojing * @author xiaojing
*/ */
public class NacosRegistration implements Registration, ServiceInstance { public class NacosRegistration implements Registration, ServiceInstance {
private static final String MANAGEMENT_PORT = "management.port";
private static final String MANAGEMENT_CONTEXT_PATH = "management.context-path";
private static final String MANAGEMENT_ADDRESS = "management.address";
@Autowired @Autowired
private NacosDiscoveryProperties nacosDiscoveryProperties; private NacosDiscoveryProperties nacosDiscoveryProperties;
private NamingService nacosNamingService;
@Autowired @Autowired
private Environment environment; private ApplicationContext context;
private NamingService nacosNamingService;
@PostConstruct @PostConstruct
public void init() { public void init() {
nacosDiscoveryProperties.overrideFromEnv(environment);
Properties properties = new Properties(); Environment env = context.getEnvironment();
properties.put(SERVER_ADDR, nacosDiscoveryProperties.getServerAddr()); nacosDiscoveryProperties.overrideFromEnv(context.getEnvironment());
properties.put(NAMESPACE, nacosDiscoveryProperties.getNamespace()); nacosNamingService = nacosDiscoveryProperties.getNamingService();
properties.put(UtilAndComs.NACOS_NAMING_LOG_NAME,
nacosDiscoveryProperties.getLogName()); Integer managementPort = ManagementServerPortUtils.getPort(context);
properties.put(ENDPOINT, nacosDiscoveryProperties.getEndpoint()); if (null != managementPort) {
properties.put(ACCESS_KEY, nacosDiscoveryProperties.getAccessKey()); Map<String, String> metadata = nacosDiscoveryProperties.getMetadata();
properties.put(SECRET_KEY, nacosDiscoveryProperties.getSecretKey()); metadata.put(MANAGEMENT_PORT, managementPort.toString());
properties.put(CLUSTER_NAME, nacosDiscoveryProperties.getClusterName()); String contextPath = env.getProperty("management.context-path");
try { String address = env.getProperty("management.address");
nacosNamingService = NacosFactory.createNamingService(properties); if (!StringUtils.isEmpty(contextPath)) {
metadata.put(MANAGEMENT_CONTEXT_PATH, contextPath);
}
if (!StringUtils.isEmpty(address)) {
metadata.put(MANAGEMENT_ADDRESS, address);
} }
catch (Exception e) {
} }
} }
@ -85,10 +88,8 @@ public class NacosRegistration implements Registration, ServiceInstance {
} }
public void setPort(int port) { public void setPort(int port) {
if (nacosDiscoveryProperties.getPort() < 0) {
this.nacosDiscoveryProperties.setPort(port); this.nacosDiscoveryProperties.setPort(port);
} }
}
@Override @Override
public boolean isSecure() { public boolean isSecure() {

View File

@ -19,7 +19,9 @@ package org.springframework.cloud.alibaba.nacos.ribbon;
import com.netflix.client.config.IClientConfig; import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.AbstractServerList; import com.netflix.loadbalancer.AbstractServerList;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryClient;
import org.springframework.cloud.alibaba.nacos.registry.NacosRegistration; import org.springframework.cloud.alibaba.nacos.registry.NacosRegistration;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -32,7 +34,7 @@ import com.alibaba.nacos.api.naming.pojo.Instance;
public class NacosServerList extends AbstractServerList<NacosServer> { public class NacosServerList extends AbstractServerList<NacosServer> {
@Autowired @Autowired
private NacosRegistration registration; private NacosDiscoveryClient discoveryClient;
private String serviceId; private String serviceId;
@ -55,7 +57,7 @@ public class NacosServerList extends AbstractServerList<NacosServer> {
private List<NacosServer> getServers() { private List<NacosServer> getServers() {
try { try {
List<Instance> instances = registration.getNacosNamingService() List<Instance> instances = discoveryClient.getNamingService()
.getAllInstances(serviceId); .getAllInstances(serviceId);
return instancesToServerList(instances); return instancesToServerList(instances);
} }

View File

@ -42,6 +42,7 @@ public class NacosDiscoveryAutoConfigurationTests {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
this.context = new SpringApplicationBuilder(NacosDiscoveryTestConfiguration.class, this.context = new SpringApplicationBuilder(NacosDiscoveryTestConfiguration.class,
NacosDiscoveryClientAutoConfiguration.class,
NacosDiscoveryAutoConfiguration.class).web(false).run( NacosDiscoveryAutoConfiguration.class).web(false).run(
"--spring.cloud.nacos.discovery.server-addr=127.0.0.1:8080", "--spring.cloud.nacos.discovery.server-addr=127.0.0.1:8080",
"--spring.cloud.nacos.discovery.port=18080", "--spring.cloud.nacos.discovery.port=18080",

View File

@ -9,6 +9,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryAutoConfiguration; import org.springframework.cloud.alibaba.nacos.NacosDiscoveryAutoConfiguration;
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryClientAutoConfiguration;
import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties; import org.springframework.cloud.alibaba.nacos.NacosDiscoveryProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.cloud.client.loadbalancer.LoadBalanced;
@ -33,6 +34,7 @@ public class NacosRibbonClientConfigurationTests {
public void setUp() throws Exception { public void setUp() throws Exception {
this.context = new SpringApplicationBuilder(NacosRibbonTestConfiguration.class, this.context = new SpringApplicationBuilder(NacosRibbonTestConfiguration.class,
NacosDiscoveryAutoConfiguration.class, NacosDiscoveryAutoConfiguration.class,
NacosDiscoveryClientAutoConfiguration.class,
NacosRibbonClientConfiguration.class, RibbonNacosAutoConfiguration.class) NacosRibbonClientConfiguration.class, RibbonNacosAutoConfiguration.class)
.web(false).run("--server.port=18080", .web(false).run("--server.port=18080",
"--spring.cloud.nacos.discovery.server-addr=127.0.0.1:8080", "--spring.cloud.nacos.discovery.server-addr=127.0.0.1:8080",

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba</artifactId> <artifactId>spring-cloud-alibaba</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -29,23 +29,95 @@ import org.springframework.core.Ordered;
@ConfigurationProperties(prefix = SentinelConstants.PROPERTY_PREFIX) @ConfigurationProperties(prefix = SentinelConstants.PROPERTY_PREFIX)
public class SentinelProperties { public class SentinelProperties {
/**
* 是否提前初始化心跳连接
*/
private boolean eager = false;
/** /**
* Enable sentinel auto configure, the default value is true * Enable sentinel auto configure, the default value is true
*/ */
private boolean enabled = true; private boolean enabled = true;
/** /**
* sentinel api port,default value is 8721 * 字符编码集
*/ */
private String port = "8721"; private String charset = "UTF-8";
/** /**
* Sentinel dashboard address, won't try to connect dashboard when address is empty * 通信相关配置
*/ */
private String dashboard = ""; @NestedConfigurationProperty
private Transport transport = new Transport();
/**
* 监控数据相关配置
*/
@NestedConfigurationProperty
private Metric metric = new Metric();
/**
* web 相关配置
*/
@NestedConfigurationProperty
private Servlet servlet = new Servlet();
/**
* 限流相关
*/
@NestedConfigurationProperty
private Filter filter = new Filter();
@NestedConfigurationProperty @NestedConfigurationProperty
private Filter filter; private Flow flow = new Flow();
public boolean isEager() {
return eager;
}
public void setEager(boolean eager) {
this.eager = eager;
}
public Flow getFlow() {
return flow;
}
public void setFlow(Flow flow) {
this.flow = flow;
}
public String getCharset() {
return charset;
}
public void setCharset(String charset) {
this.charset = charset;
}
public Transport getTransport() {
return transport;
}
public void setTransport(Transport transport) {
this.transport = transport;
}
public Metric getMetric() {
return metric;
}
public void setMetric(Metric metric) {
this.metric = metric;
}
public Servlet getServlet() {
return servlet;
}
public void setServlet(Servlet servlet) {
this.servlet = servlet;
}
public boolean isEnabled() { public boolean isEnabled() {
return enabled; return enabled;
@ -55,6 +127,102 @@ public class SentinelProperties {
this.enabled = enabled; this.enabled = enabled;
} }
public Filter getFilter() {
return filter;
}
public void setFilter(Filter filter) {
this.filter = filter;
}
public static class Flow {
/**
* 限流冷启动因子
*/
private String coldFactor = "3";
public String getColdFactor() {
return coldFactor;
}
public void setColdFactor(String coldFactor) {
this.coldFactor = coldFactor;
}
}
public static class Servlet {
/**
* url 限流后的处理页面
*/
private String blockPage;
public String getBlockPage() {
return blockPage;
}
public void setBlockPage(String blockPage) {
this.blockPage = blockPage;
}
}
public static class Metric {
/**
* 监控数据写磁盘时单个文件的大小
*/
private String fileSingleSize;
/**
* 监控数据在磁盘上的总数量
*/
private String fileTotalCount;
public String getFileSingleSize() {
return fileSingleSize;
}
public void setFileSingleSize(String fileSingleSize) {
this.fileSingleSize = fileSingleSize;
}
public String getFileTotalCount() {
return fileTotalCount;
}
public void setFileTotalCount(String fileTotalCount) {
this.fileTotalCount = fileTotalCount;
}
}
public static class Transport {
/**
* sentinel api port,default value is 8721
*/
private String port = "8721";
/**
* Sentinel dashboard address, won't try to connect dashboard when address is
* empty
*/
private String dashboard = "";
/**
* 客户端和DashBord心跳发送时间
*/
private String heartbeatIntervalMs;
public String getHeartbeatIntervalMs() {
return heartbeatIntervalMs;
}
public void setHeartbeatIntervalMs(String heartbeatIntervalMs) {
this.heartbeatIntervalMs = heartbeatIntervalMs;
}
public String getPort() { public String getPort() {
return port; return port;
} }
@ -71,12 +239,6 @@ public class SentinelProperties {
this.dashboard = dashboard; this.dashboard = dashboard;
} }
public Filter getFilter() {
return filter;
}
public void setFilter(Filter filter) {
this.filter = filter;
} }
public static class Filter { public static class Filter {

View File

@ -21,6 +21,8 @@ import java.util.List;
import javax.servlet.Filter; import javax.servlet.Filter;
import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -31,8 +33,6 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter;
/** /**
* @author xiaojing * @author xiaojing
*/ */
@ -41,6 +41,7 @@ import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter;
@ConditionalOnProperty(name = "spring.cloud.sentinel.enabled", matchIfMissing = true) @ConditionalOnProperty(name = "spring.cloud.sentinel.enabled", matchIfMissing = true)
@EnableConfigurationProperties(SentinelProperties.class) @EnableConfigurationProperties(SentinelProperties.class)
public class SentinelWebAutoConfiguration { public class SentinelWebAutoConfiguration {
private static final Logger logger = LoggerFactory private static final Logger logger = LoggerFactory
.getLogger(SentinelWebAutoConfiguration.class); .getLogger(SentinelWebAutoConfiguration.class);
@ -74,4 +75,5 @@ public class SentinelWebAutoConfiguration {
return registration; return registration;
} }
} }

View File

@ -16,17 +16,23 @@
package org.springframework.cloud.alibaba.sentinel.annotation; 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; 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 * into a Spring Bean. The Properties of DataSource bean get from config files with
* specific prefix. * specific prefix.
* *
* @author fangjian * @author fangjian
* @see com.alibaba.csp.sentinel.datasource.DataSource * @see ReadableDataSource
*/ */
@Target({ElementType.FIELD}) @Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)

View File

@ -16,8 +16,18 @@
package org.springframework.cloud.alibaba.sentinel.custom; package org.springframework.cloud.alibaba.sentinel.custom;
import javax.annotation.PostConstruct;
import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlBlockHandler;
import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlCleaner;
import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager;
import com.alibaba.csp.sentinel.adapter.servlet.config.WebServletConfig;
import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect;
import com.alibaba.csp.sentinel.config.SentinelConfig;
import com.alibaba.csp.sentinel.init.InitExecutor;
import com.alibaba.csp.sentinel.transport.config.TransportConfig; import com.alibaba.csp.sentinel.transport.config.TransportConfig;
import com.alibaba.csp.sentinel.util.AppNameUtil; import com.alibaba.csp.sentinel.util.AppNameUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@ -29,11 +39,6 @@ import org.springframework.cloud.alibaba.sentinel.datasource.SentinelDataSourceP
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect;
import javax.annotation.PostConstruct;
/** /**
* @author xiaojing * @author xiaojing
@ -49,16 +54,69 @@ public class SentinelAutoConfiguration {
@Autowired @Autowired
private SentinelProperties properties; private SentinelProperties properties;
@Autowired(required = false)
private UrlCleaner urlCleaner;
@Autowired(required = false)
private UrlBlockHandler urlBlockHandler;
@PostConstruct @PostConstruct
private void init() { private void init() {
if (StringUtils.isEmpty(System.getProperty(AppNameUtil.APP_NAME))) { if (StringUtils.isEmpty(System.getProperty(AppNameUtil.APP_NAME))
&& StringUtils.hasText(projectName)) {
System.setProperty(AppNameUtil.APP_NAME, projectName); System.setProperty(AppNameUtil.APP_NAME, projectName);
} }
if (StringUtils.isEmpty(System.getProperty(TransportConfig.SERVER_PORT))) { if (StringUtils.isEmpty(System.getProperty(TransportConfig.SERVER_PORT))
System.setProperty(TransportConfig.SERVER_PORT, properties.getPort()); && StringUtils.hasText(properties.getTransport().getPort())) {
System.setProperty(TransportConfig.SERVER_PORT,
properties.getTransport().getPort());
} }
if (StringUtils.isEmpty(System.getProperty(TransportConfig.CONSOLE_SERVER))) { if (StringUtils.isEmpty(System.getProperty(TransportConfig.CONSOLE_SERVER))
System.setProperty(TransportConfig.CONSOLE_SERVER, properties.getDashboard()); && StringUtils.hasText(properties.getTransport().getDashboard())) {
System.setProperty(TransportConfig.CONSOLE_SERVER,
properties.getTransport().getDashboard());
}
if (StringUtils.isEmpty(System.getProperty(TransportConfig.HEARTBEAT_INTERVAL_MS))
&& StringUtils
.hasText(properties.getTransport().getHeartbeatIntervalMs())) {
System.setProperty(TransportConfig.HEARTBEAT_INTERVAL_MS,
properties.getTransport().getHeartbeatIntervalMs());
}
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.CHARSET))
&& StringUtils.hasText(properties.getCharset())) {
System.setProperty(SentinelConfig.CHARSET, properties.getCharset());
}
if (StringUtils
.isEmpty(System.getProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE))
&& StringUtils.hasText(properties.getMetric().getFileSingleSize())) {
System.setProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE,
properties.getMetric().getFileSingleSize());
}
if (StringUtils
.isEmpty(System.getProperty(SentinelConfig.TOTAL_METRIC_FILE_COUNT))
&& StringUtils.hasText(properties.getMetric().getFileTotalCount())) {
System.setProperty(SentinelConfig.TOTAL_METRIC_FILE_COUNT,
properties.getMetric().getFileTotalCount());
}
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.COLD_FACTOR))
&& StringUtils.hasText(properties.getFlow().getColdFactor())) {
System.setProperty(SentinelConfig.COLD_FACTOR,
properties.getFlow().getColdFactor());
}
if (StringUtils.hasText(properties.getServlet().getBlockPage())) {
WebServletConfig.setBlockPage(properties.getServlet().getBlockPage());
}
if (urlBlockHandler != null) {
WebCallbackManager.setUrlBlockHandler(urlBlockHandler);
}
if (urlCleaner != null) {
WebCallbackManager.setUrlCleaner(urlCleaner);
}
// earlier initialize
if (properties.isEager()) {
InitExecutor.doInit();
} }
} }

View File

@ -34,10 +34,10 @@ import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import com.alibaba.csp.sentinel.datasource.DataSource; import com.alibaba.csp.sentinel.datasource.ReadableDataSource;
/** /**
* {@link DataSource} Loader * {@link ReadableDataSource} Loader
* *
* @author fangjian * @author fangjian
*/ */
@ -50,20 +50,20 @@ public class DataSourceLoader {
private final static String ALL_PROPERTIES_RESOURCES_LOCATION = CLASSPATH_ALL_URL_PREFIX private final static String ALL_PROPERTIES_RESOURCES_LOCATION = CLASSPATH_ALL_URL_PREFIX
+ PROPERTIES_RESOURCE_LOCATION; + PROPERTIES_RESOURCE_LOCATION;
private final static ConcurrentMap<String, Class<? extends DataSource>> dataSourceClassesCache = new ConcurrentHashMap<String, Class<? extends DataSource>>( private final static ConcurrentMap<String, Class<? extends ReadableDataSource>> dataSourceClassesCache = new ConcurrentHashMap<String, Class<? extends ReadableDataSource>>(
4); 4);
static void loadAllDataSourceClassesCache() { static void loadAllDataSourceClassesCache() {
Map<String, Class<? extends DataSource>> dataSourceClassesMap = loadAllDataSourceClassesCache( Map<String, Class<? extends ReadableDataSource>> dataSourceClassesMap = loadAllDataSourceClassesCache(
ALL_PROPERTIES_RESOURCES_LOCATION); ALL_PROPERTIES_RESOURCES_LOCATION);
dataSourceClassesCache.putAll(dataSourceClassesMap); dataSourceClassesCache.putAll(dataSourceClassesMap);
} }
static Map<String, Class<? extends DataSource>> loadAllDataSourceClassesCache( static Map<String, Class<? extends ReadableDataSource>> loadAllDataSourceClassesCache(
String resourcesLocation) { String resourcesLocation) {
Map<String, Class<? extends DataSource>> dataSourcesMap = new HashMap<String, Class<? extends DataSource>>( Map<String, Class<? extends ReadableDataSource>> dataSourcesMap = new HashMap<String, Class<? extends ReadableDataSource>>(
4); 4);
ClassLoader classLoader = DataSourceLoader.class.getClassLoader(); ClassLoader classLoader = DataSourceLoader.class.getClassLoader();
@ -102,10 +102,10 @@ public class DataSourceLoader {
Class<?> dataSourceClass = ClassUtils.resolveClassName(className, Class<?> dataSourceClass = ClassUtils.resolveClassName(className,
classLoader); classLoader);
Assert.isAssignable(DataSource.class, dataSourceClass); Assert.isAssignable(ReadableDataSource.class, dataSourceClass);
dataSourcesMap.put(type, dataSourcesMap.put(type,
(Class<? extends DataSource>) dataSourceClass); (Class<? extends ReadableDataSource>) dataSourceClass);
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Sentinel DataSource implementation [ type : " logger.debug("Sentinel DataSource implementation [ type : "
@ -126,10 +126,11 @@ public class DataSourceLoader {
return dataSourcesMap; return dataSourcesMap;
} }
public static Class<? extends DataSource> loadClass(String type) public static Class<? extends ReadableDataSource> loadClass(String type)
throws IllegalArgumentException { throws IllegalArgumentException {
Class<? extends DataSource> dataSourceClass = dataSourceClassesCache.get(type); Class<? extends ReadableDataSource> dataSourceClass = dataSourceClassesCache
.get(type);
if (dataSourceClass == null) { if (dataSourceClass == null) {
if (dataSourceClassesCache.isEmpty()) { if (dataSourceClassesCache.isEmpty()) {

View File

@ -44,13 +44,13 @@ import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import com.alibaba.csp.sentinel.datasource.ConfigParser; import com.alibaba.csp.sentinel.datasource.Converter;
/** /**
* {@link SentinelDataSource @SentinelDataSource} Post Processor * {@link SentinelDataSource @SentinelDataSource} Post Processor
* *
* @author fangjian * @author fangjian
* @see com.alibaba.csp.sentinel.datasource.DataSource * @see com.alibaba.csp.sentinel.datasource.ReadableDataSource
* @see SentinelDataSource * @see SentinelDataSource
*/ */
public class SentinelDataSourcePostProcessor public class SentinelDataSourcePostProcessor
@ -170,8 +170,8 @@ public class SentinelDataSourcePostProcessor
for (String propertyName : propertyMap.keySet()) { for (String propertyName : propertyMap.keySet()) {
Field field = ReflectionUtils.findField(targetClass, propertyName); Field field = ReflectionUtils.findField(targetClass, propertyName);
if (field != null) { if (field != null) {
if (field.getType().isAssignableFrom(ConfigParser.class)) { if (field.getType().isAssignableFrom(Converter.class)) {
// ConfigParser get from ApplicationContext // Converter get from ApplicationContext
builder.addPropertyReference(propertyName, builder.addPropertyReference(propertyName,
propertyMap.get(propertyName).toString()); propertyMap.get(propertyName).toString());
} }

View File

@ -18,6 +18,8 @@ package org.springframework.cloud.alibaba.sentinel.datasource;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import com.alibaba.csp.sentinel.datasource.ReadableDataSource;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import org.springframework.cloud.alibaba.sentinel.datasource.factorybean.ApolloDataSourceFactoryBean; import org.springframework.cloud.alibaba.sentinel.datasource.factorybean.ApolloDataSourceFactoryBean;
import org.springframework.cloud.alibaba.sentinel.datasource.factorybean.FileRefreshableDataSourceFactoryBean; 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 * Registry to save DataSource FactoryBean
* *
* @author fangjian * @author fangjian
* @see com.alibaba.csp.sentinel.datasource.DataSource * @see ReadableDataSource
* @see FileRefreshableDataSourceFactoryBean * @see FileRefreshableDataSourceFactoryBean
* @see ZookeeperDataSourceFactoryBean * @see ZookeeperDataSourceFactoryBean
* @see NacosDataSourceFactoryBean * @see NacosDataSourceFactoryBean

View File

@ -2,7 +2,7 @@ package org.springframework.cloud.alibaba.sentinel.datasource.factorybean;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import com.alibaba.csp.sentinel.datasource.ConfigParser; import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.datasource.apollo.ApolloDataSource; import com.alibaba.csp.sentinel.datasource.apollo.ApolloDataSource;
/** /**
@ -14,12 +14,12 @@ public class ApolloDataSourceFactoryBean implements FactoryBean<ApolloDataSource
private String namespaceName; private String namespaceName;
private String flowRulesKey; private String flowRulesKey;
private String defaultFlowRuleValue; private String defaultFlowRuleValue;
private ConfigParser configParser; private Converter converter;
@Override @Override
public ApolloDataSource getObject() throws Exception { public ApolloDataSource getObject() throws Exception {
return new ApolloDataSource(namespaceName, flowRulesKey, defaultFlowRuleValue, return new ApolloDataSource(namespaceName, flowRulesKey, defaultFlowRuleValue,
configParser); converter);
} }
@Override @Override
@ -56,11 +56,11 @@ public class ApolloDataSourceFactoryBean implements FactoryBean<ApolloDataSource
this.defaultFlowRuleValue = defaultFlowRuleValue; this.defaultFlowRuleValue = defaultFlowRuleValue;
} }
public ConfigParser getConfigParser() { public Converter getConverter() {
return configParser; return converter;
} }
public void setConfigParser(ConfigParser configParser) { public void setConverter(Converter converter) {
this.configParser = configParser; this.converter = converter;
} }
} }

View File

@ -5,7 +5,7 @@ import java.nio.charset.Charset;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import com.alibaba.csp.sentinel.datasource.ConfigParser; import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.datasource.FileRefreshableDataSource; import com.alibaba.csp.sentinel.datasource.FileRefreshableDataSource;
/** /**
@ -18,11 +18,11 @@ public class FileRefreshableDataSourceFactoryBean implements FactoryBean<FileRef
private String charset; private String charset;
private long recommendRefreshMs; private long recommendRefreshMs;
private int bufSize; private int bufSize;
private ConfigParser configParser; private Converter converter;
@Override @Override
public FileRefreshableDataSource getObject() throws Exception { public FileRefreshableDataSource getObject() throws Exception {
return new FileRefreshableDataSource(new File(file), configParser, return new FileRefreshableDataSource(new File(file), converter,
recommendRefreshMs, bufSize, Charset.forName(charset)); recommendRefreshMs, bufSize, Charset.forName(charset));
} }
@ -68,11 +68,11 @@ public class FileRefreshableDataSourceFactoryBean implements FactoryBean<FileRef
this.bufSize = bufSize; this.bufSize = bufSize;
} }
public ConfigParser getConfigParser() { public Converter getConverter() {
return configParser; return converter;
} }
public void setConfigParser(ConfigParser configParser) { public void setConverter(Converter converter) {
this.configParser = configParser; this.converter = converter;
} }
} }

View File

@ -2,7 +2,7 @@ package org.springframework.cloud.alibaba.sentinel.datasource.factorybean;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import com.alibaba.csp.sentinel.datasource.ConfigParser; import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource; import com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource;
/** /**
@ -14,11 +14,11 @@ public class NacosDataSourceFactoryBean implements FactoryBean<NacosDataSource>
private String serverAddr; private String serverAddr;
private String groupId; private String groupId;
private String dataId; private String dataId;
private ConfigParser configParser; private Converter converter;
@Override @Override
public NacosDataSource getObject() throws Exception { public NacosDataSource getObject() throws Exception {
return new NacosDataSource(serverAddr, groupId, dataId, configParser); return new NacosDataSource(serverAddr, groupId, dataId, converter);
} }
@Override @Override
@ -55,11 +55,11 @@ public class NacosDataSourceFactoryBean implements FactoryBean<NacosDataSource>
this.dataId = dataId; this.dataId = dataId;
} }
public ConfigParser getConfigParser() { public Converter getConverter() {
return configParser; return converter;
} }
public void setConfigParser(ConfigParser configParser) { public void setConverter(Converter converter) {
this.configParser = configParser; this.converter = converter;
} }
} }

View File

@ -3,7 +3,7 @@ package org.springframework.cloud.alibaba.sentinel.datasource.factorybean;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBean;
import com.alibaba.csp.sentinel.datasource.ConfigParser; import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource; import com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource;
/** /**
@ -19,17 +19,17 @@ public class ZookeeperDataSourceFactoryBean implements FactoryBean<ZookeeperData
private String groupId; private String groupId;
private String dataId; private String dataId;
private ConfigParser configParser; private Converter converter;
@Override @Override
public ZookeeperDataSource getObject() throws Exception { public ZookeeperDataSource getObject() throws Exception {
if (StringUtils.isNotEmpty(groupId) && StringUtils.isNotEmpty(dataId)) { if (StringUtils.isNotEmpty(groupId) && StringUtils.isNotEmpty(dataId)) {
// the path will be /{groupId}/{dataId} // the path will be /{groupId}/{dataId}
return new ZookeeperDataSource(serverAddr, groupId, dataId, configParser); return new ZookeeperDataSource(serverAddr, groupId, dataId, converter);
} }
else { else {
// using path directly // using path directly
return new ZookeeperDataSource(serverAddr, path, configParser); return new ZookeeperDataSource(serverAddr, path, converter);
} }
} }
@ -75,11 +75,11 @@ public class ZookeeperDataSourceFactoryBean implements FactoryBean<ZookeeperData
this.dataId = dataId; this.dataId = dataId;
} }
public ConfigParser getConfigParser() { public Converter getConverter() {
return configParser; return converter;
} }
public void setConfigParser(ConfigParser configParser) { public void setConverter(Converter converter) {
this.configParser = configParser; this.converter = converter;
} }
} }

View File

@ -7,26 +7,59 @@
"description": "enable or disable sentinel auto configure." "description": "enable or disable sentinel auto configure."
}, },
{ {
"name": "spring.cloud.sentinel.port", "name": "spring.cloud.sentinel.eager",
"type": "java.lang.Boolean",
"defaultValue": false,
"description": "earlier initialize heart-beat when the spring container starts when the transport dependency is on classpath, the configuration is effective."
},
{
"name": "spring.cloud.sentinel.charset",
"type": "java.lang.String",
"defaultValue": "UTF-8",
"description": "charset when sentinel write or search metric file."
},
{
"name": "spring.cloud.sentinel.transport.port",
"type": "java.lang.String", "type": "java.lang.String",
"defaultValue": "8721", "defaultValue": "8721",
"description": "sentinel api port." "description": "sentinel api port."
}, },
{ {
"name": "spring.cloud.sentinel.dashboard", "name": "spring.cloud.sentinel.transport.dashboard",
"type": "java.lang.String", "type": "java.lang.String",
"description": "sentinel dashboard address, won't try to connect dashboard when address is empty." "description": "sentinel dashboard address, won't try to connect dashboard when address is empty."
}, },
{
"name": "spring.cloud.sentinel.transport.heartbeatIntervalMs",
"type": "java.lang.String",
"description": "send heartbeat interval millisecond."
},
{ {
"name": "spring.cloud.sentinel.filter.order", "name": "spring.cloud.sentinel.filter.order",
"type": "java.lang.Integer", "type": "java.lang.Integer",
"defaultValue": "Integer.MIN_VALUE", "defaultValue": "Integer.MIN_VALUE",
"description": "Sentinel filter chain order, will be set to FilterRegistrationBean." "description": "sentinel filter chain order, will be set to FilterRegistrationBean."
}, },
{ {
"name": "spring.cloud.sentinel.filter.urlPatterns", "name": "spring.cloud.sentinel.metric.fileSingleSize",
"type": "java.util.List", "type": "java.lang.String",
"description": "URL pattern for Sentinel filter, default contains '/*'." "description": "the metric file size."
},
{
"name": "spring.cloud.sentinel.metric.fileTotalCount",
"type": "java.lang.String",
"description": "the total metric file count."
},
{
"name": "spring.cloud.sentinel.servlet.blockPage",
"type": "java.lang.String",
"description": "the process page when the flow control is triggered."
},
{
"name": "spring.cloud.sentinel.flow.coldFactor",
"type": "java.lang.String",
"defaultValue": "3",
"description": "sentinel the cold factor."
} }
] ]
} }

View File

@ -17,6 +17,7 @@
package org.springframework.cloud.alibaba.sentinel; package org.springframework.cloud.alibaba.sentinel;
import com.alibaba.csp.sentinel.slots.block.BlockException; import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -33,7 +34,6 @@ import org.springframework.web.context.support.AnnotationConfigWebApplicationCon
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* @author fangjian * @author fangjian
*/ */
@ -43,9 +43,10 @@ public class SentinelAutoConfigurationTests {
@Before @Before
public void init() { public void init() {
context.register(SentinelAutoConfiguration.class, SentinelWebAutoConfiguration.class, SentinelTestConfiguration.class); context.register(SentinelAutoConfiguration.class, SentinelWebAutoConfiguration.class,
SentinelTestConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, EnvironmentTestUtils.addEnvironment(this.context,
"spring.cloud.sentinel.port=8888", "spring.cloud.sentinel.transport.port=8888",
"spring.cloud.sentinel.filter.order=123", "spring.cloud.sentinel.filter.order=123",
"spring.cloud.sentinel.filter.urlPatterns=/*,/test"); "spring.cloud.sentinel.filter.urlPatterns=/*,/test");
this.context.refresh(); this.context.refresh();
@ -72,7 +73,7 @@ public class SentinelAutoConfigurationTests {
public void testProperties() { public void testProperties() {
SentinelProperties sentinelProperties = context.getBean(SentinelProperties.class); SentinelProperties sentinelProperties = context.getBean(SentinelProperties.class);
assertThat(sentinelProperties).isNotNull(); assertThat(sentinelProperties).isNotNull();
assertThat(sentinelProperties.getPort()).isEqualTo("8888"); assertThat(sentinelProperties.getTransport().getPort()).isEqualTo("8888");
assertThat(sentinelProperties.getFilter().getUrlPatterns().size()).isEqualTo(2); assertThat(sentinelProperties.getFilter().getUrlPatterns().size()).isEqualTo(2);
assertThat(sentinelProperties.getFilter().getUrlPatterns().get(0)).isEqualTo("/*"); assertThat(sentinelProperties.getFilter().getUrlPatterns().get(0)).isEqualTo("/*");
assertThat(sentinelProperties.getFilter().getUrlPatterns().get(1)).isEqualTo("/test"); assertThat(sentinelProperties.getFilter().getUrlPatterns().get(1)).isEqualTo("/test");
@ -111,5 +112,4 @@ public class SentinelAutoConfigurationTests {
} }
} }
} }

View File

@ -1,5 +0,0 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.alibaba.storage.OSSAutoConfiguration,\
org.springframework.cloud.alibaba.storage.endpoint.OSSEndpointAutoConfiguration
org.springframework.context.ApplicationListener=\
org.springframework.cloud.alibaba.storage.OSSApplicationListener

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-test</artifactId> <artifactId>spring-cloud-alibaba-test</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba</artifactId> <artifactId>spring-cloud-alibaba</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-test</artifactId> <artifactId>spring-cloud-alibaba-test</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,13 +5,13 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba</artifactId> <artifactId>spring-cloud-alibaba</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-storage</artifactId> <artifactId>spring-cloud-alicloud-oss</artifactId>
<name>Spring Cloud Alibaba Storage Autoconfigure</name> <name>Spring Cloud Alibaba Cloud OSS Autoconfigure</name>
<dependencies> <dependencies>

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cloud.alibaba.storage; package org.springframework.cloud.alibaba.oss;
import java.util.Map; import java.util.Map;

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cloud.alibaba.storage; package org.springframework.cloud.alibaba.oss;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -22,7 +22,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.alibaba.storage.resource.OSSStorageProtocolResolver; import org.springframework.cloud.alibaba.oss.resource.OSSStorageProtocolResolver;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cloud.alibaba.storage; package org.springframework.cloud.alibaba.oss;
/** /**
* OSS constants * OSS constants

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cloud.alibaba.storage; package org.springframework.cloud.alibaba.oss;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cloud.alibaba.storage.endpoint; package org.springframework.cloud.alibaba.oss.endpoint;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;

View File

@ -14,14 +14,14 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cloud.alibaba.storage.endpoint; package org.springframework.cloud.alibaba.oss.endpoint;
import org.springframework.boot.actuate.condition.ConditionalOnEnabledEndpoint; import org.springframework.boot.actuate.condition.ConditionalOnEnabledEndpoint;
import org.springframework.boot.actuate.endpoint.Endpoint; import org.springframework.boot.actuate.endpoint.Endpoint;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.alibaba.storage.OSSProperties; import org.springframework.cloud.alibaba.oss.OSSProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cloud.alibaba.storage.resource; package org.springframework.cloud.alibaba.oss.resource;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cloud.alibaba.storage.resource; package org.springframework.cloud.alibaba.oss.resource;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;

View File

@ -0,0 +1,5 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.cloud.alibaba.oss.OSSAutoConfiguration,\
org.springframework.cloud.alibaba.oss.endpoint.OSSEndpointAutoConfiguration
org.springframework.context.ApplicationListener=\
org.springframework.cloud.alibaba.oss.OSSApplicationListener

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cloud.alibaba.storage; package org.springframework.cloud.alibaba.oss;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.cloud.alibaba.storage; package org.springframework.cloud.alibaba.oss;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba</artifactId> <artifactId>spring-cloud-alibaba</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
</parent> </parent>
@ -17,21 +17,6 @@
<module>spring-cloud-starter-alibaba-nacos-config</module> <module>spring-cloud-starter-alibaba-nacos-config</module>
<module>spring-cloud-starter-alibaba-nacos-discovery</module> <module>spring-cloud-starter-alibaba-nacos-discovery</module>
<module>spring-cloud-starter-alibaba-sentinel</module> <module>spring-cloud-starter-alibaba-sentinel</module>
<module>spring-cloud-starter-alibaba-storage</module>
</modules> </modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>${maven-deploy-plugin.version}</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project> </project>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba</artifactId> <artifactId>spring-cloud-starter-alibaba</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
</parent> </parent>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<name>Spring Cloud Starter Alibaba Nacos Config</name> <name>Spring Cloud Starter Alibaba Nacos Config</name>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba</artifactId> <artifactId>spring-cloud-starter-alibaba</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
</parent> </parent>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<name>Spring Cloud Starter Alibaba Nacos Discovery</name> <name>Spring Cloud Starter Alibaba Nacos Discovery</name>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba</artifactId> <artifactId>spring-cloud-starter-alibaba</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
</parent> </parent>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
<name>Spring Cloud Starter Alibaba Sentinel</name> <name>Spring Cloud Starter Alibaba Sentinel</name>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba</artifactId>
<version>0.1.0</version>
</parent>
<artifactId>spring-cloud-starter-alicloud</artifactId>
<packaging>pom</packaging>
<name>Spring Cloud Alibaba Cloud Starters</name>
<description>Spring Cloud Alibaba Cloud Starters</description>
<modules>
<module>spring-cloud-starter-alicloud-oss</module>
</modules>
</project>

View File

@ -4,16 +4,16 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba</artifactId> <artifactId>spring-cloud-starter-alicloud</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version> <version>0.1.0</version>
</parent> </parent>
<artifactId>spring-cloud-starter-alibaba-storage</artifactId> <artifactId>spring-cloud-starter-alicloud-oss</artifactId>
<name>Spring Cloud Starter Alibaba Storage</name> <name>Spring Cloud Starter Alibaba Cloud OSS</name>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-alibaba-storage</artifactId> <artifactId>spring-cloud-alicloud-oss</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.aliyun.oss</groupId> <groupId>com.aliyun.oss</groupId>