mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
6f37bace55
12
README-zh.md
12
README-zh.md
@ -25,9 +25,9 @@ Spring Cloud Alibaba 致力于提供微服务开发的一站式解决方案。
|
||||
|
||||
**[RocketMQ](https://rocketmq.apache.org/)**:一款开源的分布式消息系统,基于高可用分布式集群技术,提供低延时的、高可靠的消息发布与订阅服务。
|
||||
|
||||
**[AliCloud ACM](https://www.aliyun.com/product/acm)**:一款在分布式架构环境中对应用配置进行集中管理和推送的应用配置中心产品。
|
||||
**[Alibaba Cloud ACM](https://www.aliyun.com/product/acm)**:一款在分布式架构环境中对应用配置进行集中管理和推送的应用配置中心产品。
|
||||
|
||||
**[AliCloud OSS](https://www.aliyun.com/product/oss)**: 阿里云对象存储服务(Object Storage Service,简称 OSS),是阿里云提供的海量、安全、低成本、高可靠的云存储服务。您可以在任何应用、任何时间、任何地点存储和访问任意类型的数据。
|
||||
**[Alibaba Cloud OSS](https://www.aliyun.com/product/oss)**: 阿里云对象存储服务(Object Storage Service,简称 OSS),是阿里云提供的海量、安全、低成本、高可靠的云存储服务。您可以在任何应用、任何时间、任何地点存储和访问任意类型的数据。
|
||||
|
||||
更多组件请参考 [Roadmap](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/Roadmap-zh.md)。
|
||||
|
||||
@ -90,11 +90,11 @@ Example 列表:
|
||||
|
||||
[RocketMQ Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/rocketmq-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)
|
||||
[Alibaba Cloud OSS Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/oss-example/readme-zh.md)
|
||||
|
||||
[AliCloud ANS Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/ans-example/ans-provider-example/readme-zh.md)
|
||||
[Alibaba Cloud ANS Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/ans-example/ans-provider-example/readme-zh.md)
|
||||
|
||||
[AliCloud ACM Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/acm-example/acm-local-example/readme-zh.md)
|
||||
[Alibaba Cloud ACM Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/acm-example/acm-local-example/readme-zh.md)
|
||||
|
||||
## 版本管理规范
|
||||
项目的版本号格式为 x.x.x 的形式,其中 x 的数值类型为数字,从0开始取值,且不限于 0~9 这个范围。项目处于孵化器阶段时,第一位版本号固定使用0,即版本号为 0.x.x 的格式。
|
||||
@ -116,4 +116,4 @@ spring-cloud-alibaba@googlegroups.com,欢迎通过此邮件列表讨论与 spr
|
||||
|
||||
### 钉钉群
|
||||
|
||||

|
||||

|
||||
|
@ -15,7 +15,7 @@ With Spring Cloud Alibaba, you only need to add some annotations and a small amo
|
||||
* **Service registration and discovery**:Service can be registered and clients can discover the instances using Spring-managed beans, auto integration Ribbon.
|
||||
* **Distributed configuration**:support for externalized configuration in a distributed system, auto refresh when configuration changes.
|
||||
* **Event-driven**:support for building highly scalable event-driven microservices connected with shared messaging systems.
|
||||
* **AliCloud Object Storage**:massive, secure, low-cost, and highly reliable cloud storage services. Support for storing and accessing any type of data in any application, anytime, anywhere.
|
||||
* **Alibaba Cloud Object Storage**:massive, secure, low-cost, and highly reliable cloud storage services. Support for storing and accessing any type of data in any application, anytime, anywhere.
|
||||
For more features, please refer to [Roadmap](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/Roadmap.md).
|
||||
|
||||
## Components
|
||||
@ -26,9 +26,9 @@ For more features, please refer to [Roadmap](https://github.com/spring-cloud-inc
|
||||
|
||||
**[RocketMQ](https://rocketmq.apache.org/)**:a distributed messaging and streaming platform with low latency, high performance and reliability, trillion-level capacity and flexible scalability.
|
||||
|
||||
**[AliCloud ACM](https://www.aliyun.com/product/acm)**:an application configuration center that enables you to centralize the management of application configurations, and accomplish real-time configuration push in a distributed environment.
|
||||
**[Alibaba Cloud ACM](https://www.aliyun.com/product/acm)**:an application configuration center that enables you to centralize the management of application configurations, and accomplish real-time configuration push in a distributed environment.
|
||||
|
||||
**[AliCloud OSS](https://www.aliyun.com/product/oss)**: An encrypted and secure cloud storage service which stores, processes and accesses massive amounts of data from anywhere in the world.
|
||||
**[Alibaba Cloud OSS](https://www.aliyun.com/product/oss)**: An encrypted and secure cloud storage service which stores, processes and accesses massive amounts of data from anywhere in the world.
|
||||
|
||||
For more features please refer to [Roadmap](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/Roadmap.md).
|
||||
|
||||
@ -102,7 +102,7 @@ Examples:
|
||||
|
||||
[RocketMQ Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/rocketmq-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)
|
||||
[Alibaba Cloud OSS Example](https://github.com/spring-cloud-incubator/spring-cloud-alibaba/blob/master/spring-cloud-alibaba-examples/oss-example/readme.md)
|
||||
|
||||
## 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.
|
||||
|
@ -15,7 +15,7 @@ Spring Cloud Alibaba 致力于提供分布式应用服务开发的一站式解
|
||||
**Nacos**
|
||||
阿里巴巴开源产品,一个更易于构建云原生应用的动态服务发现、配置管理和服务管理平台。
|
||||
|
||||
**AliCloud OSS**
|
||||
**Alibaba Cloud OSS**
|
||||
阿里云对象存储服务(Object Storage Service,简称 OSS),是阿里云提供的海量、安全、低成本、高可靠的云存储服务。您可以在任何应用、任何时间、任何地点存储和访问任意类型的数据。
|
||||
|
||||
## 即将加入的组件
|
||||
@ -25,8 +25,8 @@ Apache Dubbo™ (incubating) 是一款高性能Java RPC框架。
|
||||
**RocketMQ**
|
||||
Apache RocketMQ™ 基于Java的高性能、高吞吐量的分布式消息和流计算平台。
|
||||
|
||||
**Schedulerx**
|
||||
**Alibaba Cloud Schedulerx**
|
||||
阿里中间件团队开发的一款分布式任务调度产品,支持周期性的任务与固定时间点触发任务。
|
||||
|
||||
**AliCloud SLS**
|
||||
**Alibaba Cloud SLS**
|
||||
针对日志类数据的一站式服务,在阿里巴巴集团经历大量大数据场景锤炼而成。您无需开发就能快捷完成日志数据采集、消费、投递以及查询分析等功能,提升运维、运营效率,建立 DT 时代海量日志处理能力。
|
@ -20,9 +20,9 @@ An open-source project of Alibaba, Sentinel takes "flow" as breakthrough point,
|
||||
|
||||
An opensource project of Alibaba, an easy-to-use dynamic service discovery, configuration and service management platform for building cloud native applications.
|
||||
|
||||
**AliCloud OSS**
|
||||
**Alibaba Cloud OSS**
|
||||
|
||||
AliCloud Object Storage Service, An encrypted and secure cloud storage service which stores, processes and accesses massive amounts of data from anywhere in the world.
|
||||
Alibaba Cloud Object Storage Service, An encrypted and secure cloud storage service which stores, processes and accesses massive amounts of data from anywhere in the world.
|
||||
|
||||
More components will be supported by Spring Cloud Alibaba in the future, which may include but are not limited to the following:
|
||||
|
||||
@ -32,8 +32,8 @@ Apache Dubbo™ (incubating) is a high-performance, Java based open source RPC f
|
||||
**RocketMQ**
|
||||
Apache RocketMQ™ is an open source distributed messaging and streaming data platform.
|
||||
|
||||
**Schedulerx**
|
||||
**Alibaba Cloud Schedulerx**
|
||||
A distributed task scheduling product developed by Alibaba Middleware team. It supports both periodical tasks and tasks to be triggered at specified time points.
|
||||
|
||||
**AliCloud SLS**
|
||||
**Alibaba Cloud SLS**
|
||||
Aliyun Log Service is an all-in-one service for log-type data. It helps increase Operations & Management and operational efficiency, as well as build the processing capability to deal with massive logs.
|
1
pom.xml
1
pom.xml
@ -100,6 +100,7 @@
|
||||
<module>spring-cloud-alicloud-oss</module>
|
||||
<module>spring-cloud-alicloud-acm</module>
|
||||
<module>spring-cloud-alicloud-ans</module>
|
||||
<module>spring-cloud-alicloud-schedulerx</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
|
@ -19,13 +19,14 @@
|
||||
<properties>
|
||||
<sentinel.version>1.3.0-GA</sentinel.version>
|
||||
<oss.version>3.1.0</oss.version>
|
||||
<nacos.version>0.5.0</nacos.version>
|
||||
<nacos.version>0.6.0</nacos.version>
|
||||
<acm.version>1.0.8</acm.version>
|
||||
<ans.version>0.1.1</ans.version>
|
||||
<ans.version>1.0.1</ans.version>
|
||||
<aliyun.sdk.version>4.0.1</aliyun.sdk.version>
|
||||
<alicloud.context.version>1.0.0</alicloud.context.version>
|
||||
<alicloud.context.version>1.0.2</alicloud.context.version>
|
||||
<aliyun.sdk.edas.version>2.16.0</aliyun.sdk.edas.version>
|
||||
<rocketmq.version>4.3.1</rocketmq.version>
|
||||
<schedulerX.client.version>2.1.6</schedulerX.client.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
@ -63,7 +64,13 @@
|
||||
<artifactId>acm-sdk</artifactId>
|
||||
<version>${acm.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.edas</groupId>
|
||||
<artifactId>schedulerX-client</artifactId>
|
||||
<version>${schedulerX.client.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--Nacos-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
@ -175,6 +182,11 @@
|
||||
<artifactId>spring-cloud-alibaba-nacos-config</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-nacos-config-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-alicloud-acm</artifactId>
|
||||
@ -185,6 +197,11 @@
|
||||
<artifactId>spring-cloud-alicloud-ans</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-alicloud-schedulerx</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-alicloud-context</artifactId>
|
||||
@ -219,6 +236,11 @@
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
@ -232,6 +254,12 @@
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alicloud-schedulerx</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-stream-rocketmq</artifactId>
|
||||
|
@ -1,53 +1,17 @@
|
||||
= Spring Cloud AliCloud ACM
|
||||
== Spring Cloud Alibaba Cloud ACM
|
||||
|
||||
Spring Cloud AliCloud ACM 提供了和阿里云上的ACM的集成。使得在项目中如果需要上云的用户可以非常方便无缝的对接阿里云,来享受云端提供的稳定服务。
|
||||
Spring Cloud AliCloud ACM 是阿里云提供的商业版应用配置管理(Application Configuration Management) 产品 在 Spring Cloud 应用侧的客户端实现,且目前完全免费。
|
||||
|
||||
=== 快速开始
|
||||
Spring Cloud AliCloud ACM 是 Config Server 和 Client 的替代方案,客户端和服务器上的概念与 Spring Environment 和 PropertySource 有着一致的抽象,在特殊的 bootstrap 阶段,配置被加载到 Spring 环境中。当应用程序通过部署管道从开发到测试再到生产时,您可以管理这些环境之间的配置,并确保应用程序具有迁移时需要运行的所有内容。
|
||||
|
||||
为了能够在本地开发时可以使用和云上具有相同功能的ACM服务,我们提供了用于本地开发测试的轻量版配置中心。轻量版配置中心你可以理解为用于方便的本地开发测试的Saas平台。
|
||||
=== 如何引入 Spring Cloud AliCloud ACM
|
||||
|
||||
==== 基于properties文件扩展名的配置
|
||||
|
||||
===== 轻量版配置中心服务端初始化
|
||||
|
||||
1、轻量版配置中心的下载和启动方式可参考 https://help.aliyun.com/document_detail/44163.html?spm=a2c4g.11186623.6.677.5f206b82Z2mTCF[这里]
|
||||
|
||||
2、启动好轻量版配置中心之后,在控制台中添加如下的配置。
|
||||
|
||||
[source,subs="normal"]
|
||||
----
|
||||
Group: DEFAULT_GROOUP
|
||||
|
||||
DataId: acm-config.properties
|
||||
|
||||
Content: user.name=alibaba
|
||||
user.age=56
|
||||
----
|
||||
|
||||
NOTE: data id是以 `properties` 为扩展名(默认的文件扩展名方式)。Group 的值目前只支持 DEFAULT_GROUP,注意在使用的过程中无需更改其默认值。
|
||||
|
||||
===== 客户端使用方式
|
||||
|
||||
为了能够在应用程序中使用ACM作为Sping Cloud Config的后端存储服务,在您构建Spring Boot 应用的同时添加一个Spring Boot Starter org.springframework.cloud:spring-cloud-starter-alicloud-acm。以下是一个基础的maven 依赖配置:
|
||||
Spring Cloud Alibaba 已经发布了 0.2.0.RELEASE 版本,需要首先导入依赖管理POM。
|
||||
|
||||
[source,xml]
|
||||
----
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.0.5.RELEASE</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>Finchley.SR1</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
@ -57,20 +21,23 @@ NOTE: data id是以 `properties` 为扩展名(默认的文件扩展名方式)。
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alicloud-acm</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
----
|
||||
|
||||
现在你就可以创建一个标准的Spring Boot的应用。
|
||||
接下来引入 Spring Cloud AliCloud ACM Starter 即可。
|
||||
|
||||
[source,xml]
|
||||
----
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alicloud-acm</artifactId>
|
||||
</dependency>
|
||||
----
|
||||
|
||||
=== 使用 ACM 进行配置管理
|
||||
|
||||
当客户端引入了 Spring Cloud AliCloud ACM Starter 以后,应用启动时会自动从配置管理的服务端获取配置信息,并注入到 Spring 的 Environment 中。
|
||||
|
||||
以下是一个简单的应用示例。
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@ -86,204 +53,133 @@ public class ProviderApplication {
|
||||
}
|
||||
----
|
||||
|
||||
spring-cloud-starter-alicloud-acm 对于ACM服务端的基础配置有默认值(默认配置绑定到的ip和端口为127.0.0.1和8080),因此在运行此Example 之前, 你只需在 bootstrap.properties 配置文件配置spring.application.name即可,例如:
|
||||
既然需要从配置中心服务端获取配置信息,那么肯定需要配置服务端的地址,在 bootstrap.properties 中,还需要配置上以下信息。
|
||||
|
||||
[source,properties]
|
||||
----
|
||||
spring.application.name=acm-config #注意,spring.application.name 必须要放在bootstrap.properties中
|
||||
# 必选,应用名会被作为从服务端获取配置 key 的关键词组成部分
|
||||
spring.application.name=acm-config
|
||||
server.port=18081
|
||||
# 以下就是配置中心服务端的IP和端口配置
|
||||
spring.cloud.alicloud.acm.server-list=127.0.0.1
|
||||
spring.cloud.alicloud.acm.server-port=8080
|
||||
----
|
||||
|
||||
NOTE: 此时没有启动配置中心,启动应用会报错,因此在应用启动之前,应当首先启动配置中心。
|
||||
|
||||
|
||||
=== 启动配置中心
|
||||
|
||||
ACM 使用的配置中心有两种,一种是完全免费的轻量版配置中心,主要用于开发和本地调试,一种是云上配置中心ACM。通常情况下,可以使用轻量版配置中心作为开发和测试环境,使用云上的 ACM 作为灰度和生产环境。
|
||||
|
||||
==== 启动轻量版配置中心
|
||||
|
||||
轻量版配置中心的下载和启动方式可参考 https://help.aliyun.com/document_detail/44163.html?spm=a2c4g.11186623.6.677.5f206b82Z2mTCF[这里]
|
||||
|
||||
NOTE: 只需要进行第1步(下载轻量配置中心)和第2步(启动轻量配置中心)即可,第3步(配置hosts)在与 ACM 结合使用时,不需要操作。
|
||||
|
||||
|
||||
==== 使用云上配置中心
|
||||
|
||||
使用云上 ACM ,可以省去服务端的维护工作,同时稳定性也会更有保障。当使用云上配置中心时,代码部分和使用轻量配置中心并没有区别,但是配置上会有一些区别。
|
||||
|
||||
以下是一个简单的使用云上配置中心的配置示例,配置详情需要在 https://acm.console.aliyun.com[ACM控制台查询]
|
||||
|
||||
[source,properties]
|
||||
----
|
||||
# 应用名会被作为从服务端获取配置 key 的关键词组成部分,因此是必选
|
||||
spring.application.name=ans-provider
|
||||
# 端口配置自由配置即可
|
||||
server.port=18081
|
||||
# 以下就是配置中心的IP和端口配置
|
||||
spring.cloud.alicloud.acm.server-mode=EDAS
|
||||
spring.cloud.alicloud.access-key=你的阿里云AK
|
||||
spring.cloud.alicloud.secret-key=你的阿里云SK
|
||||
spring.cloud.alicloud.acm.endpoint=acm.aliyun.com
|
||||
spring.cloud.alicloud.acm.namespace=你的 ACM namespace,需要在 ACM 控制台查询
|
||||
----
|
||||
|
||||
NOTE: EDAS 提供应用托管服务,如果你将应用托管到 EDAS,那么 EDAS 将会自动为你填充所有配置。
|
||||
|
||||
=== 在配置中心添加配置
|
||||
|
||||
1. 启动好轻量版配置中心之后,在控制台中添加如下的配置。
|
||||
|
||||
[source,subs="normal"]
|
||||
----
|
||||
Group: DEFAULT_GROOUP
|
||||
|
||||
DataId: acm-config.properties
|
||||
|
||||
Content: user.name=james
|
||||
user.age=18
|
||||
----
|
||||
|
||||
NOTE: DataId 的格式为 `{prefix}. {file-extension}`,prefix 默认从配置 spring.application.name 中取值,file-extension 默认的值为 "properties"。
|
||||
|
||||
=== 启动应用验证
|
||||
|
||||
启动这个Example,可以在控制台看到打印出的值正是我们在轻量版配置中心上预先配置的值。
|
||||
|
||||
[source,subs="normal"]
|
||||
----
|
||||
2018-11-05 11:41:50.661 INFO 1541 --- [main] com.alibaba.demo.normal.ProviderApp : Started ProviderApp in 15.809 seconds (JVM running for 16.513)
|
||||
user name :alibaba; age: 56
|
||||
2018-11-05 11:41:50.710 INFO 1541 --- [gPullingdefault] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@1f854e9e: startup date [Mon Nov 05 11:41:50 CST 2018]; root of context hierarchy
|
||||
user name :james; age: 18
|
||||
----
|
||||
|
||||
==== 基于yaml文件扩展名的配置
|
||||
=== 更改配置文件扩展名
|
||||
|
||||
spring-cloud-starter-alicloud-acm 默认对文件扩展名为properties的支持,如果你习惯使用yaml格式来作为您的基础配置,也是可以支持的。这个时候你只需要在bootstrap.properties配置文件中显示的来声明使用的文件扩展名,如下所示
|
||||
spring-cloud-starter-alicloud-acm 中 DataId 默认的文件扩展名是 properties。除去 properties 格式之外,也支持 yaml 格式。
|
||||
支持通过 spring.cloud.nacos.config.file-extension 来配置文件的扩展名,yaml 格式可以配置成 `yaml` 或 `yml`。
|
||||
|
||||
[source,properties]
|
||||
----
|
||||
spring.application.name=acm-config
|
||||
spring.cloud.nacos.config.file-extension=yaml #显示的声明使用的文件扩展名
|
||||
----
|
||||
NOTE: 修改文件扩展名后,在配置中心中的 DataID 以及 Content 的格式都必须做相应的修改。
|
||||
|
||||
同时还需在轻量版配置中心的控制台新增一个dataid为yaml为扩展名的配置,如下所示:
|
||||
=== 支持配置的动态更新
|
||||
|
||||
[source,subs="normal"]
|
||||
----
|
||||
Group: DEFAULT_GROUP
|
||||
spring-cloud-starter-alicloud-acm 默认支持配置的动态更新,当您在配置中心修改配置的内容时,会触发 Spring 中的 Context Refresh 动作。
|
||||
带有 @RefreshScope 和 @ConfigurationProperties 注解的类会自动刷新。
|
||||
|
||||
DataId: acm-config.yaml
|
||||
NOTE: 你可以通过配置 spring.cloud.nacos.config.refresh.enabled=false 来关闭动态刷新
|
||||
|
||||
Content: user.name: yaml-alibaba
|
||||
user.age: 102
|
||||
----
|
||||
=== profile 粒度的配置
|
||||
|
||||
NOTE: 这里的DataId的命名规则。${spring.application.name}.${spring.cloud.nacos.config.file-extension}。因为配置中配置的是 acm-config和yaml,因此根据规则这里的DataId的命名是:acm-config.yaml。
|
||||
spring-cloud-starter-alicloud-acm 在加载配置的时候,首先会尝试去加载 dataid 为{spring.application.name}.{file-extension}的配置,当设置了 spring.profiles.active 中配置有内容时,还会尝试依次去加载 spring.profile 对应的内容, dataid 的格式为{spring.application.name}-{profile}.{file-extension}的配置,且后者的优先级高于前者。
|
||||
|
||||
完成之后,重启测试程序,可以在控制台看到输出的结果的值。
|
||||
|
||||
[source,subs="normal"]
|
||||
----
|
||||
2018-11-05 11:50:13.829 INFO 1674 --- [main] com.alibaba.demo.normal.ProviderApp : Started ProviderApp in 15.091 seconds (JVM running for 15.626)
|
||||
user name :yaml-alibaba; age: 102
|
||||
2018-11-05 11:50:13.868 INFO 1674 --- [gPullingdefault] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@7f64acf5: startup date [Mon Nov 05 11:50:13 CST 2018]; root of context hierarchy
|
||||
----
|
||||
|
||||
==== 支持配置的动态更新
|
||||
|
||||
spring-cloud-starter-alicloud-acm 也支持配置的动态更新,如下所示,当变更user.name时,应用程序中能够获取到最新的值:
|
||||
|
||||
[source,subs="normal"]
|
||||
----
|
||||
user name :yaml-alibaba; age: 102
|
||||
user name :yaml-alibaba; age: 102
|
||||
2018-11-05 11:52:15.192 INFO 1707 --- [gPullingdefault] o.s.boot.SpringApplication : Started application in 0.162 seconds (JVM running for 26.869)
|
||||
2018-11-05 11:52:15.193 INFO 1707 --- [gPullingdefault] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@36b222ff: startup date [Mon Nov 05 11:52:15 CST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@5cfd2308
|
||||
2018-11-05 11:52:15.193 INFO 1707 --- [gPullingdefault] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@5cfd2308: startup date [Mon Nov 05 11:52:15 CST 2018]; root of context hierarchy
|
||||
//感知到配置发生变更
|
||||
user name :yaml-alibaba-update; age: 1020
|
||||
----
|
||||
|
||||
==== 可支持profile粒度的配置
|
||||
|
||||
spring-cloud-starter-alicloud 在加载配置的时候,不仅仅加载了以dataid为${spring.application.name}.${file-extension:properties}为前缀的基础配置,还加载了dataid为${spring.application.name}-${profile}.${file-extension:properties}的基础配置。在我们日常开发中如果遇到多套环境下的不同配置,我们可以打开Spring自带的配置功能,放置在application.properties 配置文件中。如下所示:
|
||||
spring.profiles.active 属于配置的元数据,所以也必须配置在 bootstrap.properties 或 bootstrap.yaml 中。比如可以在 bootstrap.properties 中增加如下内容。
|
||||
|
||||
[sources,properties]
|
||||
----
|
||||
spring.profiles.active=${deploy.env}
|
||||
spring.application.name=acm-config
|
||||
spring.cloud.nacos.config.file-extension=yaml #显示的声明使用的文件扩展名
|
||||
spring.profiles.active={profile-name}
|
||||
----
|
||||
|
||||
其中 ${deploy.env}变量的值可以在启动应用时通过-Ddeploy.env=<env>来动态指定。比如现在在轻量版配置中心上新增了一个dataid为:acm-config-develop.yaml的基础配置,如下所示:
|
||||
Note: 也可以通过 JVM 参数 -Dspring.profiles.active=develop 或者 --spring.profiles.active=develop 这类优先级更高的方式来配置,只需遵循 Spring Boot 规范即可。
|
||||
|
||||
[source,subs="normal"]
|
||||
----
|
||||
Group: DEFAULT_GROUP
|
||||
|
||||
DataId: acm-config-develop.yaml
|
||||
|
||||
Content: deploy.env: develop
|
||||
----
|
||||
=== 支持自定义 Group 的配置
|
||||
|
||||
同时启动应用的时候通过-Ddeploy.env=develop 来指定当前spring.profiles.active的值。
|
||||
|
||||
NOTE: 特别关注下这里的DataId 的命名。因为DataId的命名规则为 ${spring.application.name}-${profile}.${file-extension:properties}。而案例中配置的值依次为 acm-config、develop、yaml,因此这里的DataId为 acm-config-develop.yaml。Group的配置目前只支持 DEFAULT_GROUP,注意在使用的过程中不要更改其他的值。
|
||||
|
||||
启动 Spring Boot 应用测试的代码如下:
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@SpringBootApplication
|
||||
public class ProviderApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
ConfigurableApplicationContext applicationContext = SpringApplication.run(ProviderApp.class, args);
|
||||
|
||||
while (true) {
|
||||
String userName = applicationContext.getEnvironment().getProperty("user.name");
|
||||
String userAge = applicationContext.getEnvironment().getProperty("user.age");
|
||||
//获取当前的部署环境
|
||||
String deployEnv = applicationContext.getEnvironment().getProperty("deploy.env");
|
||||
System.err.println("Deploy Env:"+deployEnv+"\n \t user name :" + userName + "; age: " + userAge);
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
启动后,可见控制台的输出结果:
|
||||
|
||||
[source,subs="normal"]
|
||||
----
|
||||
2018-11-05 14:06:25.898 INFO 1852 --- [main] com.alibaba.demo.normal.ProviderApp : Started ProviderApp in 14.947 seconds (JVM running for 15.471)
|
||||
Deploy Env:develop
|
||||
user name :yaml-alibaba-update; age: 1020
|
||||
2018-11-05 14:06:25.939 INFO 1852 --- [gPullingdefault] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@75d62d18: startup date [Mon Nov 05 14:06:25 CST 2018]; root of context hierarchy
|
||||
2018-11-05 14:06:25.967 INFO 1852 --- [gPullingdefault] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
|
||||
----
|
||||
|
||||
如果我们要切换到生产环境,那么只需要更改启动的-Ddeploy.env=product 参数即可。前提是生产环境 模式下轻量版配置中心已经添加了该环境的基础配置。例如dataid为:acm-config-product.yaml的配置:
|
||||
|
||||
[source,subs="normal"]
|
||||
----
|
||||
Group: DEFAULT_GROUP
|
||||
|
||||
DataId: acm-config-product.yaml
|
||||
|
||||
Content: deploy.env: Product
|
||||
----
|
||||
|
||||
以-Ddeploy.env=product 启动测试程序,输出结果如下:
|
||||
|
||||
[source,subs="normal"]
|
||||
----
|
||||
2018-11-05 14:10:05.481 INFO 1857 --- [gPullingdefault] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@455d34c2: startup date [Mon Nov 05 14:10:05 CST 2018]; root of context hierarchy
|
||||
Deploy Env:Product
|
||||
user name :yaml-alibaba-update; age: 1020
|
||||
2018-11-05 14:10:06.798 INFO 1857 --- [ Thread-20] ConfigServletWebServerApplicationContext : Closing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@3899782c: startup date [Mon Nov 05 14:10:01 CST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@245b4bdc
|
||||
----
|
||||
|
||||
==== 基于组级别配置的高级功能
|
||||
|
||||
当你习惯使用application.properties 或者 application.yaml 来作为你的配置时,为了能够区分其他应用的配置,这个时候可以开启 spring-cloud-starter-alicloud-acm 提供的基于组级别的配置。即只需在bootstrap.properties配置文件中添加spring.application.group配置来标识应用所属的分组即可。如下所示:
|
||||
在没有明确指定 `{spring.cloud.nacos.config.group}` 配置的情况下, 默认使用的是 DEFAULT_GROUP 。如果需要自定义自己的 Group,可以通过以下配置来实现:
|
||||
|
||||
[source,properties]
|
||||
----
|
||||
spring.application.group=com.infrastructure.alibaba
|
||||
spring.cloud.nacos.config.group=DEVELOP_GROUP
|
||||
----
|
||||
|
||||
如下所示:
|
||||
NOTE: 该配置必须放在 bootstrap.properties 文件中。并且在添加配置时 Group 的值一定要和 `spring.cloud.nacos.config.group` 的配置值一致。
|
||||
|
||||
[source,subs="normal"]
|
||||
==== 支持共享配置
|
||||
|
||||
ACM 提供了一种多个应用之间共享配置中心的同一个配置的推荐方式,供多个应用共享一些配置时使用,您在使用的时候需要添加在 bootstrap 中添加一个配置项 `spring.application.group`。
|
||||
|
||||
[source,properties]
|
||||
----
|
||||
Group: DEFAULT_GROUP
|
||||
|
||||
DataId: com.infrastructure.alibaba:application.yaml
|
||||
|
||||
Content: owner.group: infrastructure
|
||||
spring.application.group=company.department.team
|
||||
----
|
||||
|
||||
NOTE: 这个时候注意在轻量版配置中心填写的dataid的格式为:`${spring.application.group}:application.${file-extension}` 或者
|
||||
`${spring.application.group}:${spring.application.name}.${file-extension}` 。如果有 `spring.profiles.active` 的配置,dataid的格式还支持
|
||||
`${spring.application.group}:${spring.application.name}-${spring.profiles.active}.${file-extension}`。 Group 的值目前只支持 `DEFAULT_GROUP`,因此在使用过程中请额外注意该值配置的正确性,不要和 `spring.application.group` 这个配置搞混了。
|
||||
这时你的应用在获取之前提到的自身所独有的配置之前,会先依次从这些 DataId 去获取,分别是 company:application.properties, company.department:application.properties, company.department.team:application.properties。
|
||||
然后,还会从 {spring.application.group}:{spring.application.name}.{file-extension} 中获取
|
||||
越往后优先级越高,最高的仍然是应用自身所独有的配置。
|
||||
|
||||
启动 Spring Boot 应用测试的代码如下:
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@SpringBootApplication
|
||||
public class ProviderApp {
|
||||
NOTE: 共享配置中 DataId 默认后缀为 properties,可以通过 spring.cloud.nacos.config.file-extension 配置. `{spring.application.group}:{spring.application.name}.{file-extension}` 。
|
||||
|
||||
public static void main(String[] args) throws Exception{
|
||||
ConfigurableApplicationContext applicationContext = SpringApplication.run(ProviderApp.class, args);
|
||||
|
||||
while (true) {
|
||||
String userName = applicationContext.getEnvironment().getProperty("user.name");
|
||||
String userAge = applicationContext.getEnvironment().getProperty("user.age");
|
||||
String deployEnv = applicationContext.getEnvironment().getProperty("deploy.env");
|
||||
//获取当前应用所属的组
|
||||
String ownerGroup = applicationContext.getEnvironment().getProperty("owner.group");
|
||||
System.err.println("Deploy Env:"+deployEnv+"; in group :"+ownerGroup+"\n \tuser name :" + userName + "; age: " + userAge);
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
测试输出的结果如下:
|
||||
|
||||
[source,subs="normal"]
|
||||
----
|
||||
2018-11-05 14:34:28.059 INFO 1902 --- [main] com.alibaba.demo.normal.ProviderApp : Started ProviderApp in 15.431 seconds (JVM running for 16.008)
|
||||
Deploy Env:product; in group :Infrastructure
|
||||
user name :yaml-alibaba-update; age: 1020
|
||||
2018-11-05 14:34:28.109 INFO 1902 --- [gPullingdefault] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@4846b0aa: startup date [Mon Nov 05 14:34:28 CST 2018]; root of context hierarchy
|
||||
----
|
||||
NOTE: 如果设置了 `spring.profiles.active` ,DataId 的格式还支持 `{spring.application.group}:{spring.application.name}-{spring.profiles.active}.{file-extension}`。优先级高于 `{spring.application.group}:{spring.application.name}.{file-extension}`
|
||||
|
@ -1,10 +1,10 @@
|
||||
== Spring Cloud AliCloud ANS
|
||||
== Spring Cloud Alibaba Cloud ANS
|
||||
|
||||
ANS(Application Naming Service) 是隶属于阿里云EDAS产品的组件, Spring Cloud AliCloud ANS 提供了Spring Cloud规范下商业版的服务注册与发现,可以让用户方便的在本地开发,同时也可以运行在云环境里。
|
||||
ANS(Application Naming Service) 是隶属于阿里云 EDAS 产品的组件, Spring Cloud AliCloud ANS 提供了 Spring Cloud 规范下商业版的服务注册与发现,可以让用户方便的在本地开发,同时也可以运行在云环境里。
|
||||
|
||||
=== 如何引入 Spring Cloud AliCloud ANS
|
||||
|
||||
Spring Cloud Alibaba 已经发布了0.2.0版本,需要首先导入依赖管理POM。
|
||||
Spring Cloud Alibaba 已经发布了 0.2.0.RELEASE 版本,需要首先导入依赖管理 POM。
|
||||
|
||||
[source,xml]
|
||||
----
|
||||
@ -56,23 +56,23 @@ public class ProviderApplication {
|
||||
}
|
||||
----
|
||||
|
||||
既然服务会被注册到注册中心,那么肯定需要配置注册中心的地址,在application.properties中,还需要配置上以下地址。
|
||||
既然服务会被注册到注册中心,那么肯定需要配置注册中心的地址,在 application.properties 中,还需要配置上以下地址。
|
||||
|
||||
[source,properties]
|
||||
----
|
||||
# 应用名会被作为服务名称使用,因此会必选
|
||||
spring.application.name=ans-provider
|
||||
server.port=18081
|
||||
# 以下就是注册中心的IP和端口配置,因为默认就是127.0.0.1和8080,因此以下两行配置也可以省略
|
||||
spring.cloud.alicloud.ans.server.list=127.0.0.1
|
||||
spring.cloud.alicloud.ans.server.port=8080
|
||||
# 以下就是注册中心的IP和端口配置
|
||||
spring.cloud.alicloud.ans.server-list=127.0.0.1
|
||||
spring.cloud.alicloud.ans.server-port=8080
|
||||
----
|
||||
|
||||
NOTE: 此时没有启动注册中心,启动应用会报错,因此在应用启动之前,应当首先启动注册中心。
|
||||
|
||||
=== 启动注册中心
|
||||
|
||||
ANS使用的注册中心有两种,一种是完全免费的轻量版配置中心,主要用于开发和本地调试,一种是云上注册中心,ANS依托于阿里云EDAS产品提供服务注册的功能。通常情况下,可以使用轻量版配置中心作为开发和测试环境,使用云上的EDAS作为灰度和生产环境。
|
||||
ANS 使用的注册中心有两种,一种是完全免费的轻量版配置中心,主要用于开发和本地调试,一种是云上注册中心,ANS 依托于阿里云 EDAS 产品提供服务注册的功能。通常情况下,可以使用轻量版配置中心作为开发和测试环境,使用云上的 EDAS 作为灰度和生产环境。
|
||||
|
||||
==== 启动轻量版配置中心
|
||||
|
||||
@ -103,9 +103,9 @@ spring.cloud.alicloud.edas.namespace=cn-xxxxx
|
||||
|
||||
server-mode 的默认值为 LOCAL ,如果要使用云上注册中心,则需要更改为 EDAS 。
|
||||
|
||||
access-key 和 secret-key 则是阿里云账号的AK/SK,需要首先注册阿里云账号,然后登陆 https://usercenter.console.aliyun.com/#/manage/ak[阿里云AK/SK管理页面] ,即可看到 AccessKey ID 和 Access Key Secret ,如果没有的话,需要点击"创建AccessKey"按钮创建。
|
||||
access-key 和 secret-key 则是阿里云账号的 AK/SK,需要首先注册阿里云账号,然后登陆 https://usercenter.console.aliyun.com/#/manage/ak[阿里云AK/SK管理页面] ,即可看到 AccessKey ID 和 Access Key Secret ,如果没有的话,需要点击"创建 AccessKey"按钮创建。
|
||||
|
||||
namespace 是阿里云EDAS产品的概念,用于隔离不同的环境,比如测试环境和生产环境。要获取 namespace 需要 https://common-buy.aliyun.com/?spm=5176.11451019.0.0.6f5965c0Uq5tue&commodityCode=edaspostpay#/buy[开通EDAS服务],按量计费模式下开通是免费的,开通以后进入 https://edas.console.aliyun.com/#/namespaces?regionNo=cn-hangzhou[EDAS控制台],即可看到对应的namespace,比如cn-hangzhou。
|
||||
namespace 是阿里云 EDAS 产品的概念,用于隔离不同的环境,比如测试环境和生产环境。要获取 namespace 需要 https://common-buy.aliyun.com/?spm=5176.11451019.0.0.6f5965c0Uq5tue&commodityCode=edaspostpay#/buy[开通 EDAS 服务],按量计费模式下开通是免费的,开通以后进入 https://edas.console.aliyun.com/#/namespaces?regionNo=cn-hangzhou[EDAS控制台],即可看到对应的 namespace,比如 cn-hangzhou。
|
||||
|
||||
NOTE: EDAS提供应用托管服务,如果你将应用托管到EDAS,那么EDAS将会自动为你填充所有配置。
|
||||
NOTE: EDAS 提供应用托管服务,如果你将应用托管到 EDAS,那么 EDAS 将会自动为你填充所有配置。
|
||||
|
||||
|
@ -1,14 +1,12 @@
|
||||
= Spring Cloud Alibaba Nacos Config
|
||||
== Spring Cloud Alibaba Nacos Config
|
||||
|
||||
Nacos 提供用于存储配置和其他元数据的 key/value 存储,为分布式系统中的外部化配置提供服务器端和客户端支持。使用 Spring Cloud Alibaba Nacos Config,您可以在 Nacos Server 集中管理你 Spring Cloud 应用的外部属性配置。
|
||||
|
||||
Spring Cloud Alibaba Nacos Config 是 Config Server 和 Client 的替代方案,客户端和服务器上的概念与 Spring Environment 和 PropertySource 有着一致的抽象,在特殊的 bootstrap 阶段,配置被加载到 Spring 环境中。当应用程序通过部署管道从开发到测试再到生产时,您可以管理这些环境之间的配置,并确保应用程序具有迁移时需要运行的所有内容。
|
||||
|
||||
== 快速开始
|
||||
=== 快速开始
|
||||
|
||||
=== 基于 dataid 为 properties 的文件扩展名配置方式
|
||||
|
||||
==== Nacos 服务端初始化
|
||||
===== Nacos 服务端初始化
|
||||
|
||||
1、启动Nacos Server。启动方式可见 https://nacos.io/zh-cn/docs/quick-start.html[Nacos 官网]
|
||||
|
||||
@ -28,7 +26,7 @@ Group : DEFAULT_GROUP
|
||||
|
||||
NOTE: 注意dataid是以 properties(默认的文件扩展名方式)为扩展名。
|
||||
|
||||
==== 客户端使用方式
|
||||
===== 客户端使用方式
|
||||
|
||||
为了能够在应用程序中使用 Nacos 来实现应用的外部化配置,在构建应用的同时添加一个Spring Boot Starter org.springframework.cloud:spring-cloud-starter-alibaba-nacos-config。以下是一个基本的 maven 依赖配置:
|
||||
|
||||
@ -301,3 +299,64 @@ spring.cloud.nacos.config.group=DEVELOP_GROUP
|
||||
----
|
||||
|
||||
NOTE: 该配置必须放在 bootstrap.properties 文件中。并且在添加配置时 Group 的值一定要和 `spring.cloud.nacos.config.group` 的配置值一致。
|
||||
|
||||
=== 支持自定义扩展的 Data Id 配置
|
||||
|
||||
Spring Cloud Alibaba Nacos Config 从 0.2.1 版本后,可支持自定义 Data Id 的配置。关于这部分详细的设计可参考 https://github.com/spring-cloud-incubator/spring-cloud-alibaba/issues/141[这里]。
|
||||
一个完整的配置案例如下所示:
|
||||
|
||||
[source,properties]
|
||||
----
|
||||
spring.application.name=opensource-service-provider
|
||||
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
|
||||
|
||||
# config external configuration
|
||||
# 1、Data Id 在默认的组 DEFAULT_GROUP,不支持配置的动态刷新
|
||||
spring.cloud.nacos.config.ext-config[0].data-id=ext-config-common01.properties
|
||||
|
||||
# 2、Data Id 不在默认的组,不支持动态刷新
|
||||
spring.cloud.nacos.config.ext-config[1].data-id=ext-config-common02.properties
|
||||
spring.cloud.nacos.config.ext-config[1].group=GLOBALE_GROUP
|
||||
|
||||
# 3、Data Id 既不在默认的组,也支持动态刷新
|
||||
spring.cloud.nacos.config.ext-config[2].data-id=ext-config-common03.properties
|
||||
spring.cloud.nacos.config.ext-config[2].group=REFRESH_GROUP
|
||||
spring.cloud.nacos.config.ext-config[2].refresh=true
|
||||
----
|
||||
|
||||
可以看到:
|
||||
|
||||
* 通过 `spring.cloud.nacos.config.ext-config[n].data-id` 的配置方式来支持多个 Data Id 的配置。
|
||||
* 通过 `spring.cloud.nacos.config.ext-config[n].group` 的配置方式自定义 Data Id 所在的组,不明确配置的话,默认是 DEFAULT_GROUP。
|
||||
* 通过 `spring.cloud.nacos.config.ext-config[n].refresh` 的配置方式来控制该 Data Id 在配置变更时,是否支持应用中可动态刷新,
|
||||
感知到最新的配置值。默认是不支持的。
|
||||
|
||||
|
||||
NOTE: 多个 Data Id 同时配置时,他的优先级关系是 `spring.cloud.nacos.config.ext-config[n].data-id` 其中 n 的值越大,优先级越高。
|
||||
|
||||
NOTE: `spring.cloud.nacos.config.ext-config[n].data-id` 的值必须带文件扩展名,文件扩展名既可支持 properties,又可以支持 yaml/yml。
|
||||
此时 `spring.cloud.nacos.config.file-extension` 的配置对自定义扩展配置的 Data Id 文件扩展名没有影响。
|
||||
|
||||
通过自定义扩展的 Data Id 配置,既可以解决多个应用间配置共享的问题,又可以支持一个应用有多个配置文件。
|
||||
|
||||
为了更加清晰的在多个应用间配置共享的 Data Id ,你可以通过以下的方式来配置:
|
||||
|
||||
[source,properties]
|
||||
----
|
||||
spring.cloud.nacos.config.shared-dataids=bootstrap-common.properties,all-common.properties
|
||||
spring.cloud.nacos.config.refreshable-dataids=bootstrap-common.properties
|
||||
----
|
||||
|
||||
可以看到:
|
||||
|
||||
* 通过 `spring.cloud.nacos.config.shared-dataids` 来支持多个共享 Data Id 的配置,多个之间用逗号隔开。
|
||||
* 通过 `spring.cloud.nacos.config.refreshable-dataids` 来支持哪些共享配置的 Data Id 在配置变化时,应用中是否可动态刷新,
|
||||
感知到最新的配置值,多个 Data Id 之间用逗号隔开。如果没有明确配置,默认情况下所有共享配置的 Data Id 都不支持动态刷新。
|
||||
|
||||
NOTE: 通过 `spring.cloud.nacos.config.shared-dataids` 来支持多个共享配置的 Data Id 时,
|
||||
多个共享配置间的一个优先级的关系我们约定:按照配置出现的先后顺序,即后面的优先级要高于前面。
|
||||
|
||||
NOTE: 通过 `spring.cloud.nacos.config.shared-dataids` 来配置时,Data Id 必须带文件扩展名,文件扩展名既可支持 properties,也可以支持 yaml/yml。
|
||||
此时 `spring.cloud.nacos.config.file-extension` 的配置对自定义扩展配置的 Data Id 文件扩展名没有影响。
|
||||
|
||||
NOTE: `spring.cloud.nacos.config.refreshable-dataids` 给出哪些需要支持动态刷新时,Data Id 的值也必须明确给出文件扩展名。
|
@ -1,15 +1,15 @@
|
||||
= Spring Cloud Alibaba Nacos Discovery
|
||||
== Spring Cloud Alibaba Nacos Discovery
|
||||
|
||||
该项目通过自动配置以及其他 Spring 编程模型的习惯用法为 Spring Boot 应用程序在服务注册与发现方面提供和 Nacos 的无缝集成。
|
||||
通过一些简单的注解,您可以快速来注册一个服务,并使用经过双十一考验的 Nacos 组件来作为大规模分布式系统的服务注册中心。
|
||||
|
||||
== 1. 服务注册发现: Nacos Discovery Starter
|
||||
=== 服务注册发现: Nacos Discovery Starter
|
||||
|
||||
服务发现是微服务架构体系中最关键的组件之一。如果尝试着用手动的方式来给每一个客户端来配置所有服务提供者的服务列表是一件非常困难的事,而且也不利于
|
||||
服务的动态扩缩容。Nacos Discovery Starter 可以帮助您将服务自动注册到 Nacos 服务端并且能够动态感知和刷新某个服务实例的服务列表。除此之外,Nacos
|
||||
Discovery Starter 也将服务实例自身的一些元数据信息-例如 host,port,健康检查URL,主页等-注册到 Nacos 。Nacos 的获取和启动方式可以参考 https://nacos.io/zh-cn/docs/quick-start.html[Nacos 官网]。
|
||||
|
||||
=== 如何引入 Nacos Discovery Starter
|
||||
==== 如何引入 Nacos Discovery Starter
|
||||
|
||||
为了能够在你的工程下引入 Nacos Discovey Starter,使用group ID 为 `org.springframework.cloud` 和 artifact ID 为 `spring-cloud-starter-alibaba-nacos-discovery`。
|
||||
pom.xml 示例如下所示:
|
||||
@ -38,7 +38,7 @@ pom.xml 示例如下所示:
|
||||
</dependencies>
|
||||
----
|
||||
|
||||
=== 启动一个 Provider 应用
|
||||
==== 启动一个 Provider 应用
|
||||
|
||||
如果您使用的 Spring Cloud 版本是 Finchley.SR1 版本,那么这个时候您的Spring Boot版本的选择可需要额外的小心了,因为版本的不匹对,可能会导致许多意外的效果。
|
||||
Spring Cloud 的 Finchley.SR1 版本最佳实践的 Spring Boot 版本是 2.0.6.RELEASE。在启动您的一个 Provider 应用时请检查依赖的 Spring Boot 版本是否是
|
||||
@ -292,7 +292,7 @@ NOTE: 在启动 Consumer 应用之前请先将 Nacos 服务启动好。具体启
|
||||
访问地址:http://127.0.0.1:8082/echo/app-name
|
||||
访问结果:Hello Nacos Discovery nacos-consumer
|
||||
|
||||
== 2. 关于 Nacos Starter 更多的配置项信息
|
||||
=== 关于 Nacos Starter 更多的配置项信息
|
||||
|
||||
更多关于 spring-cloud-starter-alibaba-nacos-discovery 的 starter 配置项如下所示:
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
== Spring Cloud AliCloud OSS
|
||||
== Spring Cloud Alibaba Cloud OSS
|
||||
|
||||
OSS(Object Storage Service)是阿里云的一款对象存储服务产品, Spring Cloud AliCloud OSS 提供了Spring Cloud规范下商业版的对象存储服务,提供简单易用的API,并且支持与 Spring 框架中 Resource 的整合。
|
||||
|
||||
|
131
spring-cloud-alibaba-docs/src/main/asciidoc-zh/schedulerx.adoc
Normal file
131
spring-cloud-alibaba-docs/src/main/asciidoc-zh/schedulerx.adoc
Normal file
@ -0,0 +1,131 @@
|
||||
== Spring Cloud Alibaba Cloud SchedulerX
|
||||
|
||||
SchedulerX(分布式任务调度) 是隶属于阿里云EDAS产品的组件, Spring Cloud AliCloud SchedulerX 提供了在Spring Cloud的配置规范下,分布式任务调度的功能支持。SchedulerX可提供秒级、精准、高可靠、高可用的定时任务调度服务,并支持多种类型的任务调度,如简单单机任务、简单多机任务、脚本任务以及网格任务。
|
||||
|
||||
=== 如何引入 Spring Cloud AliCloud SchedulerX
|
||||
|
||||
Spring Cloud Alibaba 已经发布了0.2.1版本,需要首先导入依赖管理POM。
|
||||
|
||||
[source,xml]
|
||||
----
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
<version>0.2.1.RELEASE</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
----
|
||||
|
||||
接下来引入 Spring Cloud AliCloud SchedulerX Starter 即可。
|
||||
|
||||
[source,xml]
|
||||
----
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alicloud-schedulerX</artifactId>
|
||||
</dependency>
|
||||
----
|
||||
|
||||
=== 启动SchedulerX任务调度
|
||||
|
||||
当客户端引入了 Spring Cloud AliCloud SchedulerX Starter 以后,只需要进行一些简单的配置,就可以自动初始化SchedulerX的任务调度服务。
|
||||
|
||||
以下是一个简单的应用示例。
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@SpringBootApplication
|
||||
public class ScxApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ScxApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
在application.properties中,需要加上以下配置。
|
||||
|
||||
[source,properties]
|
||||
----
|
||||
server.port=18033
|
||||
# 其中cn-test是SchedulerX的测试区域
|
||||
spring.cloud.alicloud.scx.group-id=***
|
||||
spring.cloud.alicloud.edas.namespace=cn-test
|
||||
----
|
||||
|
||||
在获取group-id之前,需要首先 https://account.aliyun.com/register/register.htm?spm=5176.8142029.388261.26.e9396d3eEIv28g&oauth_callback=https%3A%2F%2Fwww.aliyun.com%2F[注册阿里云账号] ,然后 https://common-buy.aliyun.com/?spm=5176.11451019.0.0.6f5965c0Uq5tue&commodityCode=edaspostpay#/buy[开通EDAS服务] ,并 https://edas.console.aliyun.com/#/edasTools[开通分布式任务管理组件] 。
|
||||
|
||||
其中group-id的获取,请参考 https://help.aliyun.com/document_detail/98784.html?spm=a2c4g.11186623.2.17.23c87da9P2F3tG[这里]。
|
||||
|
||||
NOTE: 在创建group的时候,要选择"测试"区域。
|
||||
|
||||
=== 编写一个简单任务
|
||||
|
||||
简单任务是最常用的任务类型,只需要实现 ScxSimpleJobProcessor 接口即可。
|
||||
|
||||
以下是一个简单的单机类型任务示例。
|
||||
|
||||
[source,java]
|
||||
----
|
||||
public class SimpleTask implements ScxSimpleJobProcessor {
|
||||
|
||||
@Override
|
||||
public ProcessResult process(ScxSimpleJobContext context) {
|
||||
System.out.println("-----------Hello world---------------");
|
||||
ProcessResult processResult = new ProcessResult(true);
|
||||
return processResult;
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
=== 对任务进行调度
|
||||
|
||||
进入 https://edas.console.aliyun.com/#/edasSchedulerXJob?regionNo=cn-test[SchedulerX任务列表] 页面,选择上方"测试"区域,点击右上角"新建Job",创建一个Job,即如下所示。
|
||||
|
||||
[source,text]
|
||||
----
|
||||
Job分组:测试——***-*-*-****
|
||||
Job处理接口:org.springframework.cloud.alibaba.cloud.examples.SimpleTask
|
||||
类型:简单Job单机版
|
||||
定时表达式:默认选项——0 * * * * ?
|
||||
Job描述:无
|
||||
自定义参数:无
|
||||
----
|
||||
|
||||
以上任务类型选择了"简单Job单机版",并且制定了Cron表达式为"0 * * * * ?",这意味着,每过一分钟,任务将会被执行且只执行一次。
|
||||
|
||||
更多任务类型,请参考 https://help.aliyun.com/document_detail/43136.html[SchedulerX官方文档]。
|
||||
|
||||
=== 生产环境使用
|
||||
|
||||
以上使用的都是SchedulerX的"测试"区域,主要用于本地调试和测试。
|
||||
|
||||
在生产级别,除了上面的group-id和namespace以外,还需要一些额外的配置,如下所示。
|
||||
|
||||
[source,properties]
|
||||
----
|
||||
server.port=18033
|
||||
# 其中cn-test是SchedulerX的测试区域
|
||||
spring.cloud.alicloud.scx.group-id=***
|
||||
spring.cloud.alicloud.edas.namespace=***
|
||||
# 当应用运行在EDAS上时,以下配置不需要手动配置。
|
||||
spring.cloud.alicloud.access-key=***
|
||||
spring.cloud.alicloud.secret-key=***
|
||||
# 以下配置不是必须的,请参考SchedulerX文档
|
||||
spring.cloud.alicloud.scx.domain-name=***
|
||||
----
|
||||
|
||||
其中group-id与之前的获取方式一样,namespace则是从EDAS控制台左侧"命名空间"列表中获取命名空间ID。
|
||||
|
||||
NOTE: group-id必须创建在namespace当中。
|
||||
|
||||
access-key以及secret-key为阿里云账号的AK/SK信息,如果应用在EDAS上部署,则不需要填写这两项信息,否则请前往 https://usercenter.console.aliyun.com/#/manage/ak[安全信息管理]获取。
|
||||
|
||||
domain-name并不是必须的,具体请参考 https://help.aliyun.com/document_detail/35359.html[SchedulerX官方文档]。
|
@ -1,6 +1,6 @@
|
||||
[[spring-cloud-alibaba-reference]]
|
||||
= Spring Cloud Alibaba 参考文档
|
||||
xiaojing; xiaolongzuo; jim fang; bingting peng
|
||||
xiaojing; xiaolongzuo; jim fang; bingting peng; wangyuxin
|
||||
:doctype: book
|
||||
:toc:
|
||||
:toclevels: 4
|
||||
@ -29,3 +29,6 @@ include::acm.adoc[]
|
||||
|
||||
include::oss.adoc[]
|
||||
|
||||
include::schedulerx.adoc[]
|
||||
|
||||
|
||||
|
@ -1 +1 @@
|
||||
== Spring Cloud AliCloud ACM
|
||||
== Spring Cloud Alibaba Cloud ACM
|
||||
|
@ -1 +1 @@
|
||||
== Spring Cloud AliCloud ANS
|
||||
== Spring Cloud Alibaba Cloud ANS
|
||||
|
@ -1 +1 @@
|
||||
== Spring Cloud AliCloud OSS
|
||||
== Spring Cloud Alibaba Cloud OSS
|
||||
|
@ -20,9 +20,14 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -25,4 +25,13 @@
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -30,6 +30,7 @@
|
||||
<module>acm-example/acm-local-example</module>
|
||||
<module>rocketmq-example</module>
|
||||
<module>spring-cloud-bus-rocketmq-example</module>
|
||||
<module>schedulerx-example/schedulerx-simple-task-example</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
|
@ -0,0 +1,37 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<artifactId>spring-cloud-alibaba-examples</artifactId>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<version>0.2.1.BUILD-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>schedulerx-simple-task-example</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alicloud-schedulerx</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1,47 @@
|
||||
# SchedulerX Simple Task Example
|
||||
|
||||
## 项目说明
|
||||
|
||||
本项目展示了,在Spring Cloud体系中,如何快如接入SchedulerX,使用任务调度服务。
|
||||
|
||||
SchedulerX 是阿里中间件团队开发的一款分布式任务调度产品。它为您提供秒级、精准、高可靠、高可用的定时(基于 Cron 表达式)任务调度服务。同时提供分布式的任务执行模型,如网格任务。网格任务支持海量子任务均匀分配到所有 Worker(schedulerx-client)上执行。
|
||||
|
||||
## 示例
|
||||
|
||||
### 准备工作
|
||||
|
||||
1. 请先[注册阿里云账号](https://account.aliyun.com/register/register.htm?spm=5176.8142029.388261.26.e9396d3eEIv28g&oauth_callback=https%3A%2F%2Fwww.aliyun.com%2F)
|
||||
|
||||
2. SchedulerX集成到了EDAS组件中心,因此需要[开通EDAS服务](https://common-buy.aliyun.com/?spm=5176.11451019.0.0.6f5965c0Uq5tue&commodityCode=edaspostpay#/buy)
|
||||
|
||||
3. 到[EDAS组件中心](https://edas.console.aliyun.com/#/edasTools)开通SchedulerX组件,即分布式任务管理。
|
||||
|
||||
4. 进入[SchedulerX分组管理](https://edas.console.aliyun.com/#/schedulerXGroup?regionNo=cn-test)页面,选择上方"测试"区域,点击右上角"新建分组",创建一个分组。
|
||||
|
||||
5. 将"分组ID"的值填写到`application.properties`文件中`key`为`spring.cloud.alicloud.scx.group-id`对应的value值,即如下所示。
|
||||
|
||||
spring.cloud.alicloud.scx.group-id=111-1-1-1111
|
||||
|
||||
6. 进入[SchedulerX任务列表](https://edas.console.aliyun.com/#/edasSchedulerXJob?regionNo=cn-test)页面,选择上方"测试"区域,点击右上角"新建Job",创建一个Job,即如下所示。
|
||||
|
||||
Job分组:测试——111-1-1-1111
|
||||
Job处理接口:org.springframework.cloud.alibaba.cloud.examples.SimpleTask
|
||||
类型:简单Job单机版
|
||||
定时表达式:默认选项——0 * * * * ?
|
||||
Job描述:无
|
||||
自定义参数:无
|
||||
|
||||
### 启动应用
|
||||
|
||||
直接运行main class,即`ScxApplication`。
|
||||
|
||||
### 查看效果
|
||||
|
||||
观察应用的控制台日志输出,可以看到每一分钟会打印一次如下日志。
|
||||
|
||||
```
|
||||
-----------Hello world---------------
|
||||
```
|
||||
|
||||
如果您对 Spring Cloud SchedulerX Starter 有任何建议或想法,欢迎提交 issue 中或者通过其他社区渠道向我们反馈。
|
||||
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.alibaba.cloud.examples;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class ScxApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ScxApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.alibaba.cloud.examples;
|
||||
|
||||
import com.alibaba.edas.schedulerx.ProcessResult;
|
||||
import com.alibaba.edas.schedulerx.ScxSimpleJobContext;
|
||||
import com.alibaba.edas.schedulerx.ScxSimpleJobProcessor;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
public class SimpleTask implements ScxSimpleJobProcessor {
|
||||
|
||||
@Override
|
||||
public ProcessResult process(ScxSimpleJobContext context) {
|
||||
System.out.println("-----------Hello world---------------");
|
||||
ProcessResult processResult = new ProcessResult(true);
|
||||
return processResult;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
server.port=18033
|
||||
spring.cloud.alicloud.scx.group-id=***
|
||||
spring.cloud.alicloud.edas.namespace=cn-test
|
@ -44,6 +44,7 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
@ -18,11 +18,9 @@ package org.springframework.cloud.alicloud.acm;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.cloud.alicloud.acm.endpoint.AcmHealthIndicator;
|
||||
import org.springframework.cloud.alicloud.acm.refresh.AcmContextRefresher;
|
||||
import org.springframework.cloud.alicloud.acm.refresh.AcmRefreshHistory;
|
||||
import org.springframework.cloud.alicloud.context.acm.AcmIntegrationProperties;
|
||||
import org.springframework.cloud.alicloud.context.acm.AcmProperties;
|
||||
import org.springframework.cloud.context.refresh.ContextRefresher;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
@ -47,12 +45,6 @@ public class AcmAutoConfiguration implements ApplicationContextAware {
|
||||
return new AcmPropertySourceRepository(applicationContext);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AcmHealthIndicator acmHealthIndicator(AcmProperties acmProperties,
|
||||
AcmPropertySourceRepository acmPropertySourceRepository) {
|
||||
return new AcmHealthIndicator(acmProperties, acmPropertySourceRepository);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AcmRefreshHistory acmRefreshHistory() {
|
||||
return new AcmRefreshHistory();
|
||||
|
@ -33,20 +33,26 @@ import org.springframework.context.annotation.Bean;
|
||||
@ConditionalOnClass(name = "org.springframework.boot.actuate.autoconfigure.web.ManagementContextConfiguration")
|
||||
public class AcmEndpointAutoConfiguration {
|
||||
|
||||
@Autowired
|
||||
private AcmProperties acmProperties;
|
||||
@Autowired
|
||||
private AcmProperties acmProperties;
|
||||
|
||||
@Autowired
|
||||
private AcmRefreshHistory acmRefreshHistory;
|
||||
@Autowired
|
||||
private AcmRefreshHistory acmRefreshHistory;
|
||||
|
||||
@Autowired
|
||||
private AcmPropertySourceRepository acmPropertySourceRepository;
|
||||
@Autowired
|
||||
private AcmPropertySourceRepository acmPropertySourceRepository;
|
||||
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnEnabledEndpoint
|
||||
@Bean
|
||||
public AcmEndpoint acmEndpoint() {
|
||||
return new AcmEndpoint(acmProperties, acmRefreshHistory,
|
||||
acmPropertySourceRepository);
|
||||
}
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnEnabledEndpoint
|
||||
@Bean
|
||||
public AcmEndpoint acmEndpoint() {
|
||||
return new AcmEndpoint(acmProperties, acmRefreshHistory,
|
||||
acmPropertySourceRepository);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AcmHealthIndicator acmHealthIndicator(AcmProperties acmProperties,
|
||||
AcmPropertySourceRepository acmPropertySourceRepository) {
|
||||
return new AcmHealthIndicator(acmProperties, acmPropertySourceRepository);
|
||||
}
|
||||
}
|
||||
|
@ -44,9 +44,20 @@
|
||||
<artifactId>spring-cloud-commons</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -38,6 +38,12 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.edas</groupId>
|
||||
<artifactId>schedulerX-client</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.ans</groupId>
|
||||
<artifactId>ans-sdk</artifactId>
|
||||
|
@ -16,14 +16,24 @@
|
||||
|
||||
package org.springframework.cloud.alicloud.context;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.commons.util.InetUtils;
|
||||
import org.springframework.cloud.commons.util.InetUtilsProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(AliCloudProperties.class)
|
||||
@EnableConfigurationProperties({ AliCloudProperties.class, InetUtilsProperties.class })
|
||||
public class AliCloudContextAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public InetUtils inetUtils(InetUtilsProperties inetUtilsProperties) {
|
||||
return new InetUtils(inetUtilsProperties);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,12 +18,8 @@ package org.springframework.cloud.alicloud.context.ans;
|
||||
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.alicloud.context.edas.EdasContextAutoConfiguration;
|
||||
import org.springframework.cloud.commons.util.InetUtils;
|
||||
import org.springframework.cloud.commons.util.InetUtilsProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
@ -31,14 +27,8 @@ import org.springframework.context.annotation.Configuration;
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(name = "org.springframework.cloud.alicloud.ans.AnsAutoConfiguration")
|
||||
@EnableConfigurationProperties({ AnsProperties.class, InetUtilsProperties.class })
|
||||
@EnableConfigurationProperties(AnsProperties.class)
|
||||
@ImportAutoConfiguration(EdasContextAutoConfiguration.class)
|
||||
public class AnsContextAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public InetUtils inetUtils(InetUtilsProperties inetUtilsProperties) {
|
||||
return new InetUtils(inetUtilsProperties);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
package org.springframework.cloud.alicloud.context.nacos;
|
||||
|
||||
import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration;
|
||||
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
|
||||
import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration;
|
||||
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
|
||||
|
||||
public class NacosParameterInitListener
|
||||
implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {
|
||||
private static final Logger log = LoggerFactory
|
||||
@ -20,7 +21,7 @@ public class NacosParameterInitListener
|
||||
|
||||
private void preparedNacosConfiguration() {
|
||||
EdasChangeOrderConfiguration edasChangeOrderConfiguration = EdasChangeOrderConfigurationFactory
|
||||
.buildEdasChangeOrderConfiguration();
|
||||
.getEdasChangeOrderConfiguration();
|
||||
log.info("Initialize Nacos Parameter from edas change order,is edas managed {}.",
|
||||
edasChangeOrderConfiguration.isEdasManaged());
|
||||
if (!edasChangeOrderConfiguration.isEdasManaged()) {
|
||||
|
@ -51,9 +51,9 @@ public class OssContextAutoConfiguration {
|
||||
Assert.isTrue(!StringUtils.isEmpty(ossProperties.getEndpoint()),
|
||||
"Oss endpoint can't be empty.");
|
||||
Assert.isTrue(!StringUtils.isEmpty(aliCloudProperties.getAccessKey()),
|
||||
"Access key can't be empty.");
|
||||
"${spring.cloud.alicloud.access-key} can't be empty.");
|
||||
Assert.isTrue(!StringUtils.isEmpty(aliCloudProperties.getSecretKey()),
|
||||
"Secret key can't be empty.");
|
||||
"${spring.cloud.alicloud.secret-key} can't be empty.");
|
||||
return new OSSClientBuilder().build(ossProperties.getEndpoint(),
|
||||
aliCloudProperties.getAccessKey(), aliCloudProperties.getSecretKey(),
|
||||
ossProperties.getConfig());
|
||||
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.alicloud.context.scx;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.alicloud.context.AliCloudProperties;
|
||||
import org.springframework.cloud.alicloud.context.edas.EdasContextAutoConfiguration;
|
||||
import org.springframework.cloud.alicloud.context.edas.EdasProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.alibaba.cloud.context.edas.AliCloudEdasSdk;
|
||||
import com.alibaba.cloud.context.scx.AliCloudScxInitializer;
|
||||
import com.alibaba.dts.common.exception.InitException;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(name = "org.springframework.cloud.alicloud.scx.ScxAutoConfiguration")
|
||||
@EnableConfigurationProperties(ScxProperties.class)
|
||||
@ImportAutoConfiguration(EdasContextAutoConfiguration.class)
|
||||
public class ScxContextAutoConfiguration {
|
||||
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(ScxContextAutoConfiguration.class);
|
||||
|
||||
@Autowired
|
||||
private AliCloudProperties aliCloudProperties;
|
||||
|
||||
@Autowired
|
||||
private EdasProperties edasProperties;
|
||||
|
||||
@Autowired
|
||||
private ScxProperties scxProperties;
|
||||
|
||||
@Autowired
|
||||
private AliCloudEdasSdk aliCloudEdasSdk;
|
||||
|
||||
@PostConstruct
|
||||
public void initAcmProperties() {
|
||||
try {
|
||||
AliCloudScxInitializer.initialize(aliCloudProperties, edasProperties,
|
||||
scxProperties, aliCloudEdasSdk);
|
||||
}
|
||||
catch (InitException e) {
|
||||
log.error("Init SchedulerX failed.", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.alicloud.context.scx;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import com.alibaba.cloud.context.scx.ScxConfiguration;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
@ConfigurationProperties("spring.cloud.alicloud.scx")
|
||||
public class ScxProperties implements ScxConfiguration {
|
||||
|
||||
private String groupId;
|
||||
|
||||
private String domainName;
|
||||
|
||||
@Override
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(String groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDomainName() {
|
||||
return domainName;
|
||||
}
|
||||
|
||||
public void setDomainName(String domainName) {
|
||||
this.domainName = domainName;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.alicloud.context.statistics;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.cloud.alicloud.context.acm.AcmContextBootstrapConfiguration;
|
||||
import org.springframework.cloud.alicloud.context.acm.AcmProperties;
|
||||
import org.springframework.cloud.alicloud.context.ans.AnsContextAutoConfiguration;
|
||||
import org.springframework.cloud.alicloud.context.ans.AnsProperties;
|
||||
import org.springframework.cloud.alicloud.context.edas.EdasProperties;
|
||||
import org.springframework.cloud.alicloud.context.oss.OssContextAutoConfiguration;
|
||||
import org.springframework.cloud.alicloud.context.oss.OssProperties;
|
||||
import org.springframework.cloud.alicloud.context.scx.ScxContextAutoConfiguration;
|
||||
import org.springframework.cloud.alicloud.context.scx.ScxProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.alibaba.cloud.context.AliCloudServerMode;
|
||||
import com.alibaba.cloud.context.edas.AliCloudEdasSdk;
|
||||
import com.alibaba.cloud.context.statistics.StatisticsTask;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
@Configuration
|
||||
@AutoConfigureAfter({ ScxContextAutoConfiguration.class,
|
||||
OssContextAutoConfiguration.class, AnsContextAutoConfiguration.class,
|
||||
AcmContextBootstrapConfiguration.class })
|
||||
public class StatisticsTaskStarter implements InitializingBean {
|
||||
|
||||
@Autowired(required = false)
|
||||
private AliCloudEdasSdk aliCloudEdasSdk;
|
||||
|
||||
@Autowired(required = false)
|
||||
private EdasProperties edasProperties;
|
||||
|
||||
@Autowired(required = false)
|
||||
private ScxProperties scxProperties;
|
||||
|
||||
@Autowired(required = false)
|
||||
private OssProperties ossProperties;
|
||||
|
||||
@Autowired(required = false)
|
||||
private AnsProperties ansProperties;
|
||||
|
||||
@Autowired(required = false)
|
||||
private AcmProperties acmProperties;
|
||||
|
||||
@Autowired(required = false)
|
||||
private ScxContextAutoConfiguration scxContextAutoConfiguration;
|
||||
|
||||
@Autowired(required = false)
|
||||
private OssContextAutoConfiguration ossContextAutoConfiguration;
|
||||
|
||||
@Autowired(required = false)
|
||||
private AnsContextAutoConfiguration ansContextAutoConfiguration;
|
||||
|
||||
@Autowired(required = false)
|
||||
private AcmContextBootstrapConfiguration acmContextBootstrapConfiguration;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
StatisticsTask statisticsTask = new StatisticsTask(aliCloudEdasSdk,
|
||||
edasProperties, getComponents());
|
||||
statisticsTask.start();
|
||||
}
|
||||
|
||||
private List<String> getComponents() {
|
||||
List<String> components = new ArrayList<>();
|
||||
if (scxContextAutoConfiguration != null && scxProperties != null) {
|
||||
components.add("SC-SCX");
|
||||
}
|
||||
if (ossContextAutoConfiguration != null && ossProperties != null) {
|
||||
components.add("SC-OSS");
|
||||
}
|
||||
boolean edasEnabled = edasProperties != null && edasProperties.isEnabled();
|
||||
boolean ansEnableEdas = edasEnabled || (ansProperties != null
|
||||
&& ansProperties.getServerMode() == AliCloudServerMode.EDAS);
|
||||
if (ansContextAutoConfiguration != null && ansEnableEdas) {
|
||||
components.add("SC-ANS");
|
||||
}
|
||||
boolean acmEnableEdas = edasEnabled || (acmProperties != null
|
||||
&& acmProperties.getServerMode() == AliCloudServerMode.EDAS);
|
||||
if (acmContextBootstrapConfiguration != null && acmEnableEdas) {
|
||||
components.add("SC-ACM");
|
||||
}
|
||||
return components;
|
||||
}
|
||||
|
||||
}
|
@ -4,7 +4,8 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.alicloud.context.AliCloudContextAutoConfiguration,\
|
||||
org.springframework.cloud.alicloud.context.edas.EdasContextAutoConfiguration,\
|
||||
org.springframework.cloud.alicloud.context.ans.AnsContextAutoConfiguration,\
|
||||
org.springframework.cloud.alicloud.context.oss.OssContextAutoConfiguration
|
||||
org.springframework.cloud.alicloud.context.oss.OssContextAutoConfiguration,\
|
||||
org.springframework.cloud.alicloud.context.scx.ScxContextAutoConfiguration,\
|
||||
org.springframework.cloud.alicloud.context.statistics.StatisticsTaskStarter
|
||||
org.springframework.context.ApplicationListener=\
|
||||
org.springframework.cloud.alicloud.context.ans.AnsContextApplicationListener,\
|
||||
org.springframework.cloud.alicloud.context.nacos.NacosParameterInitListener
|
||||
org.springframework.cloud.alicloud.context.ans.AnsContextApplicationListener
|
@ -33,7 +33,9 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
"spring.application.name=myapp",
|
||||
"spring.cloud.alicloud.edas.application.name=myapp",
|
||||
"spring.cloud.alicloud.access-key=ak", "spring.cloud.alicloud.secret-key=sk",
|
||||
"spring.cloud.alicloud.oss.endpoint=test" }, webEnvironment = RANDOM_PORT)
|
||||
"spring.cloud.alicloud.oss.endpoint=test",
|
||||
"spring.cloud.alicloud.scx.group-id=1-2-3-4",
|
||||
"spring.cloud.alicloud.edas.namespace=cn-test" }, webEnvironment = RANDOM_PORT)
|
||||
@DirtiesContext
|
||||
public class AliCloudSpringApplicationTests {
|
||||
|
||||
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.alicloud.context.scx;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.cloud.alicloud.context.edas.EdasProperties;
|
||||
import org.springframework.cloud.alicloud.context.oss.OssProperties;
|
||||
|
||||
import com.aliyun.oss.OSS;
|
||||
|
||||
/**
|
||||
* {@link OSS} {@link OssProperties} Test
|
||||
*
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
*/
|
||||
public class ScxAutoConfigurationTests {
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(ScxContextAutoConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.alicloud.scx.group-id=1-2-3-4")
|
||||
.withPropertyValues("spring.cloud.alicloud.edas.namespace=cn-test");
|
||||
|
||||
@Test
|
||||
public void testSxcProperties() {
|
||||
this.contextRunner.run(context -> {
|
||||
assertThat(context.getBeansOfType(ScxProperties.class).size() == 1).isTrue();
|
||||
EdasProperties edasProperties = context.getBean(EdasProperties.class);
|
||||
ScxProperties scxProperties = context.getBean(ScxProperties.class);
|
||||
assertThat(scxProperties.getGroupId()).isEqualTo("1-2-3-4");
|
||||
assertThat(edasProperties.getNamespace()).isEqualTo("cn-test");
|
||||
assertThat(scxProperties.getDomainName()).isNull();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.alicloud.scx;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
public class ScxAutoConfiguration {
|
||||
}
|
48
spring-cloud-alicloud-schedulerx/pom.xml
Normal file
48
spring-cloud-alicloud-schedulerx/pom.xml
Normal file
@ -0,0 +1,48 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<artifactId>spring-cloud-alibaba</artifactId>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<version>0.2.1.BUILD-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>spring-cloud-alicloud-schedulerx</artifactId>
|
||||
<name>Spring Cloud Alibaba Cloud SchedulerX</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-alicloud-context</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.edas</groupId>
|
||||
<artifactId>schedulerX-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>aliyun-java-sdk-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>aliyun-java-sdk-edas</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-actuator</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.alicloud.scx;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* placeholder configuration
|
||||
*
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
@Configuration
|
||||
public class ScxAutoConfiguration {
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.alicloud.scx.endpoint;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
|
||||
import org.springframework.cloud.alicloud.context.edas.EdasProperties;
|
||||
import org.springframework.cloud.alicloud.context.scx.ScxProperties;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
@Endpoint(id = "scx")
|
||||
public class ScxEndpoint {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ScxEndpoint.class);
|
||||
|
||||
private ScxProperties scxProperties;
|
||||
|
||||
private EdasProperties edasProperties;
|
||||
|
||||
public ScxEndpoint(EdasProperties edasProperties, ScxProperties scxProperties) {
|
||||
this.edasProperties = edasProperties;
|
||||
this.scxProperties = scxProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return scx endpoint
|
||||
*/
|
||||
@ReadOperation
|
||||
public Map<String, Object> invoke() {
|
||||
Map<String, Object> scxEndpoint = new HashMap<>();
|
||||
LOGGER.info("SCX endpoint invoke, scxProperties is {}", scxProperties);
|
||||
scxEndpoint.put("namespace", edasProperties == null ? "" : edasProperties.getNamespace());
|
||||
scxEndpoint.put("scxProperties", scxProperties);
|
||||
return scxEndpoint;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.alicloud.scx.endpoint;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.cloud.alicloud.context.edas.EdasProperties;
|
||||
import org.springframework.cloud.alicloud.context.scx.ScxProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
@ConditionalOnWebApplication
|
||||
@ConditionalOnClass(Endpoint.class)
|
||||
public class ScxEndpointAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public ScxEndpoint scxEndpoint(EdasProperties edasProperties, ScxProperties scxProperties) {
|
||||
return new ScxEndpoint(edasProperties, scxProperties);
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.alicloud.scx.endpoint.ScxEndpointAutoConfiguration,\
|
||||
org.springframework.cloud.alicloud.scx.ScxAutoConfiguration
|
@ -13,6 +13,7 @@
|
||||
<description>Spring Cloud Alibaba Starters</description>
|
||||
<modules>
|
||||
<module>spring-cloud-starter-alibaba-nacos-config</module>
|
||||
<module>spring-cloud-starter-alibaba-nacos-config-server</module>
|
||||
<module>spring-cloud-starter-alibaba-nacos-discovery</module>
|
||||
<module>spring-cloud-starter-alibaba-sentinel</module>
|
||||
<module>spring-cloud-starter-stream-rocketmq</module>
|
||||
|
@ -0,0 +1,20 @@
|
||||
<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-starter-alibaba</artifactId>
|
||||
<version>0.2.1.BUILD-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config-server</artifactId>
|
||||
<name>Spring Cloud Starter Alibaba Nacos Config Server</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -14,5 +14,6 @@
|
||||
<module>spring-cloud-starter-alicloud-oss</module>
|
||||
<module>spring-cloud-starter-alicloud-acm</module>
|
||||
<module>spring-cloud-starter-alicloud-ans</module>
|
||||
<module>spring-cloud-starter-alicloud-schedulerx</module>
|
||||
</modules>
|
||||
</project>
|
@ -0,0 +1,20 @@
|
||||
<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-starter-alicloud</artifactId>
|
||||
<version>0.2.1.BUILD-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-starter-alicloud-schedulerx</artifactId>
|
||||
<name>Spring Cloud Starter Alibaba Cloud SchedulerX</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-alicloud-schedulerx</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
Loading…
x
Reference in New Issue
Block a user