mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Merge remote-tracking branch 'upstream/1.x' into 1.x
This commit is contained in:
commit
d27c449638
10
pom.xml
10
pom.xml
@ -61,6 +61,7 @@
|
||||
<!-- Dependency Versions -->
|
||||
<spring-cloud-commons.version>1.3.5.RELEASE</spring-cloud-commons.version>
|
||||
<spring-cloud-netflix.version>1.4.6.RELEASE</spring-cloud-netflix.version>
|
||||
<spring-cloud-bus.version>1.3.4.RELEASE</spring-cloud-bus.version>
|
||||
|
||||
<junit.version>4.12</junit.version>
|
||||
<javax-servlet-api>3.0</javax-servlet-api>
|
||||
@ -90,6 +91,7 @@
|
||||
<module>spring-cloud-alicloud-context</module>
|
||||
<module>spring-cloud-alicloud-acm</module>
|
||||
<module>spring-cloud-alicloud-ans</module>
|
||||
<module>spring-cloud-alicloud-schedulerx</module>
|
||||
</modules>
|
||||
|
||||
<dependencyManagement>
|
||||
@ -119,6 +121,14 @@
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-bus-dependencies</artifactId>
|
||||
<version>${spring-cloud-bus.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
@ -22,9 +22,10 @@
|
||||
<acm.version>1.0.8</acm.version>
|
||||
<ans.version>0.1.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>
|
||||
@ -61,6 +62,11 @@
|
||||
<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>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
@ -172,6 +178,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,12 +230,24 @@
|
||||
<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>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bus-rocketmq</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Testing Dependencies -->
|
||||
|
||||
|
||||
|
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.1.1版本,需要首先导入依赖管理POM。
|
||||
|
||||
[source,xml]
|
||||
----
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
<version>0.1.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官方文档]。
|
@ -29,3 +29,4 @@ include::acm.adoc[]
|
||||
|
||||
include::oss.adoc[]
|
||||
|
||||
include::schedulerx.adoc[]
|
@ -29,3 +29,4 @@ include::acm.adoc[]
|
||||
|
||||
include::oss.adoc[]
|
||||
|
||||
include::schedulerx.adoc[]
|
@ -1,4 +1,4 @@
|
||||
server.port=18082
|
||||
spring.application.name=service-provider
|
||||
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
|
||||
management.endpoints.web.exposure.include=*
|
||||
management.security.enabled=false
|
@ -28,6 +28,8 @@
|
||||
<module>ans-example/ans-provider-example</module>
|
||||
<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.1.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
|
@ -0,0 +1,54 @@
|
||||
<?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.1.1.BUILD-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-bus-rocketmq-example</artifactId>
|
||||
<name>Spring Cloud Bus RocketMQ Example</name>
|
||||
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bus-rocketmq</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>
|
||||
<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>
|
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.rocketmq;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.bus.event.AckRemoteApplicationEvent;
|
||||
import org.springframework.cloud.bus.jackson.RemoteApplicationEventScan;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* RocketMQ Bus Spring Application
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @since 0.2.1
|
||||
*/
|
||||
@RestController
|
||||
@EnableAutoConfiguration
|
||||
@RemoteApplicationEventScan(basePackages = "org.springframework.cloud.alibaba.cloud.examples.rocketmq")
|
||||
public class RocketMQBusApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(RocketMQBusApplication.class)
|
||||
.properties("server.port=0") // Random server port
|
||||
.properties("management.security.enabled=false") // exposure includes all
|
||||
.properties("spring.cloud.bus.trace.enabled=true") // Enable trace
|
||||
.run(args);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private ApplicationEventPublisher publisher;
|
||||
|
||||
@Value("${spring.cloud.bus.id}")
|
||||
private String originService;
|
||||
|
||||
@Value("${server.port}")
|
||||
private int localServerPort;
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* Publish the {@link UserRemoteApplicationEvent}
|
||||
*
|
||||
* @param name the user name
|
||||
* @param destination the destination
|
||||
* @return If published
|
||||
*/
|
||||
@GetMapping("/bus/event/publish/user")
|
||||
public boolean publish(@RequestParam String name,
|
||||
@RequestParam(required = false) String destination) {
|
||||
User user = new User();
|
||||
user.setId(System.currentTimeMillis());
|
||||
user.setName(name);
|
||||
publisher.publishEvent(
|
||||
new UserRemoteApplicationEvent(user, originService, destination));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener on the {@link UserRemoteApplicationEvent}
|
||||
*
|
||||
* @param event {@link UserRemoteApplicationEvent}
|
||||
*/
|
||||
@EventListener
|
||||
public void onEvent(UserRemoteApplicationEvent event) {
|
||||
System.out.printf("Server [port : %d] listeners on %s\n", localServerPort,
|
||||
event.getUser());
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void onAckEvent(AckRemoteApplicationEvent event)
|
||||
throws JsonProcessingException {
|
||||
System.out.printf("Server [port : %d] listeners on %s\n", localServerPort,
|
||||
objectMapper.writeValueAsString(event));
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.rocketmq;
|
||||
|
||||
/**
|
||||
* User Domain
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @since 0.2.1
|
||||
*/
|
||||
public class User {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" + "id=" + id + ", name='" + name + '\'' + '}';
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.rocketmq;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import org.springframework.cloud.bus.event.RemoteApplicationEvent;
|
||||
|
||||
/**
|
||||
* {@link User} {@link RemoteApplicationEvent}
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @since 0.2.1
|
||||
*/
|
||||
public class UserRemoteApplicationEvent extends RemoteApplicationEvent {
|
||||
|
||||
public UserRemoteApplicationEvent() {
|
||||
}
|
||||
|
||||
public UserRemoteApplicationEvent(User user, String originService,
|
||||
String destinationService) {
|
||||
super(user, originService, destinationService);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public User getUser() {
|
||||
return (User) getSource();
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
spring.application.name=spring-cloud-bus-rocketmq-example
|
||||
spring.cloud.stream.rocketmq.binder.namesrv-addr=127.0.0.1:9876
|
||||
spring.cloud.bus.id=${spring.application.name}:${server.port}
|
@ -50,6 +50,12 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.edas</groupId>
|
||||
<artifactId>schedulerX-client</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.edas.acm</groupId>
|
||||
<artifactId>acm-sdk</artifactId>
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
* A listener that prepare initialize the nacos configuration for aliyun acm
|
||||
*
|
||||
@ -24,7 +25,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()) {
|
||||
|
@ -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,9 @@ 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
|
@ -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,50 @@
|
||||
/*
|
||||
* 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.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.cloud.alicloud.context.edas.EdasProperties;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = ScxContextAutoConfiguration.class, properties = {
|
||||
"spring.cloud.alicloud.scx.group-id=1-2-3-4",
|
||||
"spring.cloud.alicloud.edas.namespace=cn-test" })
|
||||
public class ScxPropertiesLoadTests {
|
||||
|
||||
@Autowired
|
||||
private EdasProperties edasProperties;
|
||||
|
||||
@Autowired
|
||||
private ScxProperties scxProperties;
|
||||
|
||||
@Test
|
||||
public void testSxcProperties() {
|
||||
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.1.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 java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
|
||||
import org.springframework.cloud.alicloud.context.edas.EdasProperties;
|
||||
import org.springframework.cloud.alicloud.context.scx.ScxProperties;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
public class ScxEndpoint extends AbstractEndpoint<Map<String, Object>> {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ScxEndpoint.class);
|
||||
|
||||
private ScxProperties scxProperties;
|
||||
|
||||
private EdasProperties edasProperties;
|
||||
|
||||
public ScxEndpoint(EdasProperties edasProperties, ScxProperties scxProperties) {
|
||||
super("scx", false);
|
||||
this.edasProperties = edasProperties;
|
||||
this.scxProperties = scxProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return scx endpoint
|
||||
*/
|
||||
@Override
|
||||
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.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(name = "org.springframework.boot.actuate.endpoint.AbstractEndpoint")
|
||||
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
|
@ -18,6 +18,7 @@
|
||||
<module>spring-cloud-starter-alibaba-nacos-discovery</module>
|
||||
<module>spring-cloud-starter-alibaba-sentinel</module>
|
||||
<module>spring-cloud-starter-stream-rocketmq</module>
|
||||
<module>spring-cloud-starter-bus-rocketmq</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
|
@ -0,0 +1,33 @@
|
||||
<?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>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba</artifactId>
|
||||
<version>0.1.1.BUILD-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bus-rocketmq</artifactId>
|
||||
<name>Spring Cloud Alibaba Bus RocketMQ</name>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- Spring Cloud Stream RocketMQ -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-stream-binder-rocketmq</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Cloud Bus -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-bus</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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.bus.rocketmq.env;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.cloud.bus.BusEnvironmentPostProcessor;
|
||||
import org.springframework.cloud.bus.SpringCloudBusClient;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The lowest precedence {@link EnvironmentPostProcessor} configures default RocketMQ Bus
|
||||
* Properties that will be appended into {@link SpringApplication#defaultProperties}
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @see BusEnvironmentPostProcessor
|
||||
* @since 0.2.1
|
||||
*/
|
||||
public class RocketMQBusEnvironmentPostProcessor
|
||||
implements EnvironmentPostProcessor, Ordered {
|
||||
|
||||
/**
|
||||
* The name of {@link PropertySource} of {@link SpringApplication#defaultProperties}
|
||||
*/
|
||||
private static final String PROPERTY_SOURCE_NAME = "defaultProperties";
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment,
|
||||
SpringApplication application) {
|
||||
|
||||
addDefaultPropertySource(environment);
|
||||
|
||||
}
|
||||
|
||||
private void addDefaultPropertySource(ConfigurableEnvironment environment) {
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
|
||||
configureDefaultProperties(map);
|
||||
|
||||
addOrReplace(environment.getPropertySources(), map);
|
||||
}
|
||||
|
||||
private void configureDefaultProperties(Map<String, Object> source) {
|
||||
// Required Properties
|
||||
String groupBindingPropertyName = createBindingPropertyName(
|
||||
SpringCloudBusClient.INPUT, "group");
|
||||
source.put(groupBindingPropertyName, "rocketmq-bus-group");
|
||||
}
|
||||
|
||||
private String createBindingPropertyName(String channel, String propertyName) {
|
||||
return "spring.cloud.stream.bindings." + channel + "." + propertyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy from
|
||||
* {@link BusEnvironmentPostProcessor#addOrReplace(MutablePropertySources, Map)}
|
||||
*
|
||||
* @param propertySources {@link MutablePropertySources}
|
||||
* @param map Default RocketMQ Bus Properties
|
||||
*/
|
||||
private void addOrReplace(MutablePropertySources propertySources,
|
||||
Map<String, Object> map) {
|
||||
MapPropertySource target = null;
|
||||
if (propertySources.contains(PROPERTY_SOURCE_NAME)) {
|
||||
PropertySource<?> source = propertySources.get(PROPERTY_SOURCE_NAME);
|
||||
if (source instanceof MapPropertySource) {
|
||||
target = (MapPropertySource) source;
|
||||
for (String key : map.keySet()) {
|
||||
if (!target.containsProperty(key)) {
|
||||
target.getSource().put(key, map.get(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (target == null) {
|
||||
target = new MapPropertySource(PROPERTY_SOURCE_NAME, map);
|
||||
}
|
||||
if (!propertySources.contains(PROPERTY_SOURCE_NAME)) {
|
||||
propertySources.addLast(target);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return LOWEST_PRECEDENCE;
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
# EnvironmentPostProcessor
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=\
|
||||
org.springframework.cloud.bus.rocketmq.env.RocketMQBusEnvironmentPostProcessor
|
@ -11,11 +11,12 @@
|
||||
<artifactId>spring-cloud-starter-alicloud</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>Spring Cloud Alibaba Cloud Starters</name>
|
||||
<description>Spring Cloud Alibaba Cloud Starters</description>
|
||||
<description>Spring Cloud Alibaba Cloud Starters</description>
|
||||
<modules>
|
||||
<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>
|
||||
|
||||
|
||||
|
@ -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.1.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