From 20e305b75848ae4ab8f263e0a06bee68a6c8f763 Mon Sep 17 00:00:00 2001 From: yaohui Date: Tue, 18 Oct 2022 18:04:05 +0800 Subject: [PATCH 1/4] update aliyun-schedulerx-spring-boot-sample --- .../pom.xml | 11 ++++ .../schedulerx/SchedulerxApplication.java | 3 +- .../schedulerx/domain/AccountInfo.java | 4 +- .../schedulerx/job/annotation/SpringJob.java | 57 ++++++++++++++++++ .../job/{ => processor}/BroadcastJob.java | 2 +- .../job/{ => processor}/KillJob.java | 2 +- .../job/{ => processor}/MapReduceJob.java | 6 +- .../job/{ => processor}/ParallelJob.java | 2 +- .../{ => processor}/ScanShardingTableJob.java | 12 ++-- .../{ => processor}/ScanSingleTableJob.java | 12 ++-- .../job/{ => processor}/ShardingJob.java | 2 +- .../job/{ => processor}/SimpleJob.java | 2 +- .../job/{ => processor}/SleepJob.java | 2 +- .../job/{ => processor}/TradeOrderJob.java | 2 +- .../main/resources/application-processor.yml | 48 +++++++++++++++ .../src/main/resources/application.yml | 59 ++++++------------- .../src/main/resources/log4j2.xml | 1 + .../pom.xml | 2 +- 18 files changed, 162 insertions(+), 67 deletions(-) create mode 100644 aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/annotation/SpringJob.java rename aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/{ => processor}/BroadcastJob.java (97%) rename aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/{ => processor}/KillJob.java (96%) rename aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/{ => processor}/MapReduceJob.java (93%) rename aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/{ => processor}/ParallelJob.java (98%) rename aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/{ => processor}/ScanShardingTableJob.java (91%) rename aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/{ => processor}/ScanSingleTableJob.java (91%) rename aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/{ => processor}/ShardingJob.java (95%) rename aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/{ => processor}/SimpleJob.java (96%) rename aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/{ => processor}/SleepJob.java (96%) rename aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/{ => processor}/TradeOrderJob.java (98%) create mode 100644 aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application-processor.yml diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/pom.xml b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/pom.xml index 5955b0d..4e05fd9 100644 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/pom.xml +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/pom.xml @@ -51,6 +51,17 @@ aliyun-schedulerx-spring-boot-starter + + + org.springframework.boot + spring-boot-starter-log4j2 + + + + org.yaml + snakeyaml + 1.26 + diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/SchedulerxApplication.java b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/SchedulerxApplication.java index 80c430c..49c1dff 100644 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/SchedulerxApplication.java +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/SchedulerxApplication.java @@ -19,6 +19,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; +import org.springframework.scheduling.annotation.EnableScheduling; /** * SchedulerxApplication. @@ -26,7 +27,7 @@ * @author xiaomeng.hxm */ @SpringBootApplication -@ComponentScan(value="com.alibaba.schedulerx.*") +@EnableScheduling public class SchedulerxApplication { public static void main(String[] args) { diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/domain/AccountInfo.java b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/domain/AccountInfo.java index 6b8b206..c3a1bff 100644 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/domain/AccountInfo.java +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/domain/AccountInfo.java @@ -16,10 +16,10 @@ package com.alibaba.cloud.examples.schedulerx.domain; +import java.util.HashMap; import java.util.Map; import com.alibaba.schedulerx.worker.processor.BizSubTask; -import com.google.common.collect.Maps; /** * AccountInfo. @@ -44,7 +44,7 @@ public AccountInfo(long id, String name, String accountId) { */ @Override public Map labelMap() { - Map labelMap = Maps.newHashMap(); + Map labelMap = new HashMap<>(); labelMap.put("user", name); return labelMap; } diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/annotation/SpringJob.java b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/annotation/SpringJob.java new file mode 100644 index 0000000..134f8c6 --- /dev/null +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/annotation/SpringJob.java @@ -0,0 +1,57 @@ +/* + * Copyright 2013-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 + * + * https://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 com.alibaba.cloud.examples.schedulerx.job.annotation; + +import com.alibaba.schedulerx.common.domain.ExecuteMode; +import com.alibaba.schedulerx.worker.processor.SchedulerX; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +/** + * Spring scheduled job + * @author yaohui + * @create 2022/10/17 下午2:51 + **/ +@Component +public class SpringJob { + + /** + * log4j2/logback配置schedulerxLogAppender,可以进行日志采集 + */ + private static final Logger logger = LoggerFactory.getLogger("schedulerx"); + + /** + * An spring scheduled job + */ + @Scheduled(cron = "0/5 * * * * ?") + public void simpleJob() { + logger.info("hello schedulerx! this's an spring simple job."); + } + + /** + * An spring scheduled job + * Can use @SchedulerX annotation set job config when open sync(true) + */ + @Scheduled(cron = "0/5 * * * * ?") + @SchedulerX(name = "simpleJobWithAnnotation", model = ExecuteMode.STANDALONE) + public void simpleJobWithAnnotation() { + logger.info("hello schedulerx! this's an spring simple job with SchedulerX annotation."); + } + +} diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/BroadcastJob.java b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/BroadcastJob.java similarity index 97% rename from aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/BroadcastJob.java rename to aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/BroadcastJob.java index cd0e43b..a9b4bc3 100644 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/BroadcastJob.java +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/BroadcastJob.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.examples.schedulerx.job; +package com.alibaba.cloud.examples.schedulerx.job.processor; import java.util.Map; import java.util.Map.Entry; diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/KillJob.java b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/KillJob.java similarity index 96% rename from aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/KillJob.java rename to aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/KillJob.java index 67d0615..2716da5 100644 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/KillJob.java +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/KillJob.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.examples.schedulerx.job; +package com.alibaba.cloud.examples.schedulerx.job.processor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/MapReduceJob.java b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/MapReduceJob.java similarity index 93% rename from aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/MapReduceJob.java rename to aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/MapReduceJob.java index 79e8582..a0a0cda 100644 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/MapReduceJob.java +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/MapReduceJob.java @@ -14,8 +14,9 @@ * limitations under the License. */ -package com.alibaba.cloud.examples.schedulerx.job; +package com.alibaba.cloud.examples.schedulerx.job.processor; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -24,7 +25,6 @@ import com.alibaba.schedulerx.worker.domain.JobContext; import com.alibaba.schedulerx.worker.processor.MapReduceJobProcessor; import com.alibaba.schedulerx.worker.processor.ProcessResult; -import com.google.common.collect.Lists; /** * MapReduce任务Demo:分发50条消息,分布式并行处理 @@ -43,7 +43,7 @@ public ProcessResult process(JobContext context) throws Exception { } if (isRootTask(context)) { System.out.println("start root task"); - List msgList = Lists.newArrayList(); + List msgList = new ArrayList<>(); for (int i = 0; i <= dispatchNum; i++) { msgList.add("msg_" + i); } diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/ParallelJob.java b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/ParallelJob.java similarity index 98% rename from aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/ParallelJob.java rename to aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/ParallelJob.java index e83a7eb..56c3187 100644 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/ParallelJob.java +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/ParallelJob.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.examples.schedulerx.job; +package com.alibaba.cloud.examples.schedulerx.job.processor; import java.util.LinkedList; import java.util.List; diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/ScanShardingTableJob.java b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/ScanShardingTableJob.java similarity index 91% rename from aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/ScanShardingTableJob.java rename to aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/ScanShardingTableJob.java index aaf89b9..f7c74ff 100644 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/ScanShardingTableJob.java +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/ScanShardingTableJob.java @@ -14,8 +14,9 @@ * limitations under the License. */ -package com.alibaba.cloud.examples.schedulerx.job; +package com.alibaba.cloud.examples.schedulerx.job.processor; +import java.util.ArrayList; import java.util.List; import org.springframework.stereotype.Component; @@ -26,7 +27,6 @@ import com.alibaba.schedulerx.worker.domain.JobContext; import com.alibaba.schedulerx.worker.processor.MapJobProcessor; import com.alibaba.schedulerx.worker.processor.ProcessResult; -import com.google.common.collect.Lists; /** * 通过Map模型扫描分库分表 @@ -57,7 +57,7 @@ public ProcessResult process(JobContext context) throws Exception { Pair idPair = queryMinAndMaxId(tableName); long minId = idPair.getFirst(); long maxId = idPair.getSecond(); - List tasks = Lists.newArrayList(); + List tasks = new ArrayList<>(); int step = (int) ((maxId - minId) / PAGE_SIZE); //计算分页数量 for (long i = minId; i < maxId; i+=PAGE_SIZE) { long startId = i; @@ -79,13 +79,13 @@ public ProcessResult process(JobContext context) throws Exception { } private List getDbList() { - List dbList = Lists.newArrayList(); + List dbList = new ArrayList<>(); //TODO 返回分库列表 return dbList; } private List getTableList(String dbName) { - List tableList = Lists.newArrayList(); + List tableList = new ArrayList<>(); //TODO 返回分表列表 return tableList; } @@ -96,7 +96,7 @@ private Pair queryMinAndMaxId(String tableName) { } private List queryRecord(String tableName, long startId, long endId) { - List records = Lists.newArrayList(); + List records = new ArrayList<>(); //TODO select * from [tableName] where id>=[startId] and id<[endId] return records; } diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/ScanSingleTableJob.java b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/ScanSingleTableJob.java similarity index 91% rename from aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/ScanSingleTableJob.java rename to aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/ScanSingleTableJob.java index 5fdfe25..207e02d 100644 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/ScanSingleTableJob.java +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/ScanSingleTableJob.java @@ -14,8 +14,9 @@ * limitations under the License. */ -package com.alibaba.cloud.examples.schedulerx.job; +package com.alibaba.cloud.examples.schedulerx.job.processor; +import java.util.ArrayList; import java.util.List; import org.springframework.stereotype.Component; @@ -26,7 +27,6 @@ import com.alibaba.schedulerx.worker.domain.JobContext; import com.alibaba.schedulerx.worker.processor.MapJobProcessor; import com.alibaba.schedulerx.worker.processor.ProcessResult; -import com.google.common.collect.Lists; /** * 通过Map模型扫描一个大表 @@ -46,7 +46,7 @@ public ProcessResult process(JobContext context) throws Exception { Pair idPair = queryMinAndMaxId(tableName); long minId = idPair.getFirst(); long maxId = idPair.getSecond(); - List tasks = Lists.newArrayList(); + List tasks = new ArrayList<>(); int step = (int) ((maxId - minId) / PAGE_SIZE); //计算分页数量 for (long i = minId; i < maxId; i+=PAGE_SIZE) { long startId = i; @@ -67,13 +67,13 @@ public ProcessResult process(JobContext context) throws Exception { } private List getDbList() { - List dbList = Lists.newArrayList(); + List dbList = new ArrayList<>(); //TODO 返回分库列表 return dbList; } private List getTableList(String dbName) { - List tableList = Lists.newArrayList(); + List tableList = new ArrayList<>(); //TODO 返回分表列表 return tableList; } @@ -84,7 +84,7 @@ private Pair queryMinAndMaxId(String tableName) { } private List queryRecord(String tableName, long startId, long endId) { - List records = Lists.newArrayList(); + List records = new ArrayList<>(); //TODO select * from [tableName] where id>=[startId] and id<[endId] return records; } diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/ShardingJob.java b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/ShardingJob.java similarity index 95% rename from aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/ShardingJob.java rename to aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/ShardingJob.java index af7c7e2..f1f1c7e 100644 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/ShardingJob.java +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/ShardingJob.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.examples.schedulerx.job; +package com.alibaba.cloud.examples.schedulerx.job.processor; import org.springframework.stereotype.Component; diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/SimpleJob.java b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/SimpleJob.java similarity index 96% rename from aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/SimpleJob.java rename to aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/SimpleJob.java index 5600d74..7c779ee 100644 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/SimpleJob.java +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/SimpleJob.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.examples.schedulerx.job; +package com.alibaba.cloud.examples.schedulerx.job.processor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/SleepJob.java b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/SleepJob.java similarity index 96% rename from aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/SleepJob.java rename to aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/SleepJob.java index 331ddbe..9cad933 100644 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/SleepJob.java +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/SleepJob.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.examples.schedulerx.job; +package com.alibaba.cloud.examples.schedulerx.job.processor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/TradeOrderJob.java b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/TradeOrderJob.java similarity index 98% rename from aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/TradeOrderJob.java rename to aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/TradeOrderJob.java index 287f5ed..46dcadc 100644 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/TradeOrderJob.java +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/processor/TradeOrderJob.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.alibaba.cloud.examples.schedulerx.job; +package com.alibaba.cloud.examples.schedulerx.job.processor; import java.util.ArrayList; import java.util.List; diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application-processor.yml b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application-processor.yml new file mode 100644 index 0000000..1eb1575 --- /dev/null +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application-processor.yml @@ -0,0 +1,48 @@ +## 采用配置文件模式定义任务配置信息 (可选模式) +## Step1. 请先在任务调度控制台创建命名空间和应用分组 +spring: + schedulerx2: + endpoint: acm.aliyun.com #请填写不同region的endpoint + namespace: 433d8b23-xxx-xxx-xxx-90d4d1b9a4af #region内全局唯一,建议使用UUID生成 + namespaceName: 测试环境 + namespaceSource: schedulerx + appName: myTest #应用名称 + groupId: myTest.group #应用的id标识,一个命名空间下需要唯一 + appKey: myTest123@alibaba #应用的key,不要太简单,注意保管好 + regionId: public #请填写不同的regionId + aliyunAccessKey: xxxxxxxxx + aliyunSecretKey: xxxxxxxxx + alarmChannel: sms,ding #报警通道:短信和钉钉 + jobs: + simpleJob: + jobModel: standalone + className: com.alibaba.cloud.examples.schedulerx.job.processor.SimpleJob + cron: 0/30 * * * * ? # cron表达式 + jobParameter: hello + overwrite: true + shardingJob: + jobModel: sharding + className: com.alibaba.cloud.examples.schedulerx.job.processor.ShardingJob + oneTime: 2022-06-02 12:00:00 # 一次性任务表达式 + jobParameter: 0=Beijing,1=Shanghai,2=Guangzhou + overwrite: true + broadcastJob: # 不填写cron和oneTime,表示api任务 + jobModel: broadcast + className: com.alibaba.cloud.examples.schedulerx.job.processor.BroadcastJob + jobParameter: hello + overwrite: true + mapReduceJob: + jobModel: mapreduce + className: com.alibaba.cloud.examples.schedulerx.job.processor.MapReduceJob + cron: 0 * * * * ? + jobParameter: 100 + overwrite: true + alarmUsers: + user1: + userName: 张三 + userPhone: 12345678900 + user2: + userName: 李四 + ding: https://oapi.dingtalk.com/robot/send?access_token=xxxxx +logging: + config: classpath:log4j2.xml \ No newline at end of file diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application.yml b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application.yml index 7951291..2afaf27 100644 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application.yml +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application.yml @@ -1,43 +1,20 @@ +## 控制台定义任务配置信息,或通过注解定义任务 (推荐模式) +## Step1. 请先在任务调度控制台创建命名空间和应用分组 spring: schedulerx2: - endpoint: acm.aliyun.com #请填写不同region的endpoint - namespace: 433d8b23-xxx-xxx-xxx-90d4d1b9a4af #region内全局唯一,建议使用UUID生成 - namespaceName: 测试环境 - appName: myTest #应用名称 - groupId: myTest.group #应用的id标识,一个命名空间下需要唯一 - appKey: myTest123@alibaba #应用的key,不要太简单,注意保管好 - regionId: public #请填写不同的regionId - aliyunAccessKey: xxxxxxxxx - aliyunSecretKey: xxxxxxxxx - alarmChannel: sms,ding #报警通道:短信和钉钉 - jobs: - simpleJob: - jobModel: standalone - className: com.alibaba.cloud.examples.schedulerx.processor.SimpleJob - cron: 0/30 * * * * ? # cron表达式 - jobParameter: hello - overwrite: true - shardingJob: - jobModel: sharding - className: com.alibaba.cloud.examples.schedulerx.processor.ShardingJob - oneTime: 2022-06-02 12:00:00 # 一次性任务表达式 - jobParameter: 0=Beijing,1=Shanghai,2=Guangzhou - overwrite: true - broadcastJob: # 不填写cron和oneTime,表示api任务 - jobModel: broadcast - className: com.alibaba.cloud.examples.schedulerx.processor.BroadcastJob - jobParameter: hello - overwrite: true - mapReduceJob: - jobModel: mapreduce - className: com.alibaba.cloud.examples.schedulerx.processor.MapReduceJob - cron: 0 * * * * ? - jobParameter: 100 - overwrite: true - alarmUsers: - user1: - userName: 张三 - userPhone: 12345678900 - user2: - userName: 李四 - ding: https://oapi.dingtalk.com/robot/send?access_token=xxxxx \ No newline at end of file + endpoint: acm.aliyun.com #请填写不同region的endpoint + namespace: aad167f6-8bee-xxxx-xxxx-xxxxxxxxx #region内全局唯一,控制台上创建命名空间时自动生成 + groupId: qianxi.dev #应用的id标识,从控制台上创建应用分组时自定义填写,一个命名空间下需要唯一 + appKey: xxxxxxxxxxxxxxxxxxxxxxxx #应用的key,从控制台上获取 + task: + scheduling: + scheduler: schedulerx # 接管Spring定时任务 +# 可选,开启自动同步Spring注解任务 +# sync: true +# overwrite: false +# regionId: public +# aliyunAccessKey: XXXXXXXXX +# aliyunSecretKey: XXXXXXXXX + +logging: + config: classpath:log4j2.xml \ No newline at end of file diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/log4j2.xml b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/log4j2.xml index aba50dd..91c9188 100644 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/log4j2.xml +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/log4j2.xml @@ -18,6 +18,7 @@ + \ No newline at end of file diff --git a/aliyun-spring-boot-starters/aliyun-schedulerx-spring-boot-starter/pom.xml b/aliyun-spring-boot-starters/aliyun-schedulerx-spring-boot-starter/pom.xml index 62776b3..07f207a 100644 --- a/aliyun-spring-boot-starters/aliyun-schedulerx-spring-boot-starter/pom.xml +++ b/aliyun-spring-boot-starters/aliyun-schedulerx-spring-boot-starter/pom.xml @@ -49,7 +49,7 @@ com.aliyun.schedulerx schedulerx2-spring-boot-starter - 1.5.0.2 + 1.7.9 From c955d0a6e267fc5310a1599450934da395390823 Mon Sep 17 00:00:00 2001 From: yaohui Date: Tue, 18 Oct 2022 20:18:47 +0800 Subject: [PATCH 2/4] update aliyun-schedulerx-spring-boot-sample --- .../readme-zh.md | 97 +++++++++++++------ .../main/resources/application-processor.yml | 22 ++--- .../src/main/resources/application.properties | 17 ++++ .../src/main/resources/application.yml | 20 ---- 4 files changed, 93 insertions(+), 63 deletions(-) create mode 100644 aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application.properties delete mode 100644 aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application.yml diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/readme-zh.md b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/readme-zh.md index e9600c5..2dd8944 100644 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/readme-zh.md +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/readme-zh.md @@ -10,8 +10,10 @@ ### 如何接入 1. 登录阿里云分布式任务调度[Schedulerx控制台](https://schedulerx2.console.aliyun.com),点击开通服务 - -2. pom增加依赖aliyun-schedulerx-spring-boot-starter + +2. 进入任务调度控制台->应用管理,点击"创建应用",配置应用分组信息保存 + +3. pom增加依赖aliyun-schedulerx-spring-boot-starter ```xml com.alibaba.cloud @@ -19,54 +21,63 @@ ``` -3. 配置application.yml +4. 应用配置application.properties,可在控制台->应用管理->XXX应用(接入配置)点击获取 +```properties +spring.schedulerx2.endpoint=acm.aliyun.com #请填写不同region的endpoint +spring.schedulerx2.namespace=aad167f6-8bee-xxxx-xxxx-xxxxxxxxx #region内全局唯一,控制台上创建命名空间时自动生成 +spring.schedulerx2.groupId=qianxi.dev #应用的id标识,从控制台上创建应用分组时自定义填写,一个命名空间下需要唯一 +spring.schedulerx2.appKey=xxxxxxxxxxxxxxxxxxxxxxxx #应用的key,从控制台上获取 +spring.schedulerx2.task.scheduling.scheduler=schedulerx #接管Spring定时任务 + +# 可选,开启自动同步Spring注解任务 +#spring.schedulerx2.task.scheduling.sync=true +#spring.schedulerx2.task.scheduling.overwrite=false +#spring.schedulerx2.regionId=public +#spring.schedulerx2.aliyunAccessKey=XXXXXXXXX +#spring.schedulerx2.aliyunSecretKey=XXXXXXXXX +``` + +通过配置文件定义任务并自动同步创建,配置application.yml (可选模式) ```yaml spring: schedulerx2: - endpoint: acm.aliyun.com #请填写不同regin的endpoint - namespace: 433d8b23-06e9-xxxx-xxxx-90d4d1b9a4af #region内全局唯一,建议使用UUID生成 - namespaceName: 学仁测试 - appName: myTest - groupId: myTest.group #同一个命名空间下需要唯一 - appKey: myTest123@alibaba #应用的key,不要太简单,注意保管好 - regionId: public #填写对应的regionId - aliyunAccessKey: xxxxxxx #阿里云账号的ak - aliyunSecretKey: xxxxxxx #阿里云账号的sk - alarmChannel: sms,ding #报警通道:短信和钉钉 - jobs: + endpoint: acm.aliyun.com #请填写不同region的endpoint + namespace: 433d8b23-xxx-xxx-xxx-90d4d1b9a4af #region内全局唯一,推荐控制台手动创建,如控制台region下不存在且存在任务配置时会自动创建(建议使用UUID生成) + namespaceName: 测试环境 + namespaceSource: schedulerx + appName: myTest #应用名称,如控制台手动创建应用分组则直接复制过来配置即可 + groupId: myTest.group #应用的id标识,一个命名空间下需要唯一,推荐控制台手动创建,如控制台region下不存在且存在任务配置时会自动创建 + appKey: myTest123@alibaba #应用的key,不要太简单,注意保管好,如控制台手动创建应用分组则直接复制过来配置即可 + regionId: public #请填写不同的regionId,用于自动同步下方的任务信息至指定的region + aliyunAccessKey: xxxxxxxxx + aliyunSecretKey: xxxxxxxxx + jobs: simpleJob: jobModel: standalone - className: com.aliyun.schedulerx.example.processor.SimpleJob + className: com.alibaba.cloud.examples.schedulerx.job.processor.SimpleJob cron: 0/30 * * * * ? # cron表达式 jobParameter: hello overwrite: true shardingJob: jobModel: sharding - className: ccom.aliyun.schedulerx.example.processor.ShardingJob + className: com.alibaba.cloud.examples.schedulerx.job.processor.ShardingJob oneTime: 2022-06-02 12:00:00 # 一次性任务表达式 jobParameter: 0=Beijing,1=Shanghai,2=Guangzhou overwrite: true broadcastJob: # 不填写cron和oneTime,表示api任务 jobModel: broadcast - className: com.aliyun.schedulerx.example.processor.BroadcastJob + className: com.alibaba.cloud.examples.schedulerx.job.processor.BroadcastJob jobParameter: hello overwrite: true mapReduceJob: jobModel: mapreduce - className: com.aliyun.schedulerx.example.processor.MapReduceJob + className: com.alibaba.cloud.examples.schedulerx.job.processor.MapReduceJob cron: 0 * * * * ? jobParameter: 100 overwrite: true - alarmUsers: #报警联系人 - user1: - userName: 张三 - userPhone: 12345678900 - user2: - userName: 李四 - ding: https://oapi.dingtalk.com/robot/send?access_token=xxxxx ``` -4. 实现任务接口,以单机任务为例,更多任务模型请看examples +5. 实现任务接口,以单机任务为例,更多任务模型请看examples ```java package com.alibaba.cloud.examples.schedulerx.job; @@ -95,9 +106,39 @@ public class SimpleJob extends JavaProcessor { public void kill(JobContext context) { } } -``` +``` +支持Spring原生定时任务调度 +```java +@Component +public class SpringJob { + + /** + * log4j2/logback配置schedulerxLogAppender,可以进行日志采集 + */ + private static final Logger logger = LoggerFactory.getLogger("schedulerx"); + + /** + * An spring scheduled job + */ + @Scheduled(cron = "0/5 * * * * ?") + public void simpleJob() { + logger.info("hello schedulerx! this's an spring simple job."); + } + + /** + * An spring scheduled job + * Can use @SchedulerX annotation set job config when open sync(true) + */ + @Scheduled(cron = "0/5 * * * * ?") + @SchedulerX(name = "simpleJobWithAnnotation", model = ExecuteMode.STANDALONE) + public void simpleJobWithAnnotation() { + logger.info("hello schedulerx! this's an spring simple job with SchedulerX annotation."); + } + +} +``` -5. 启动你的springboot启动类,大概1分钟左右,你的定时任务就可以正常调度起来了 +6. 启动你的springboot启动类,大概1分钟左右,你的定时任务就可以正常调度起来了 ``` hello schedulerx! hello schedulerx! diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application-processor.yml b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application-processor.yml index 1eb1575..446e38b 100644 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application-processor.yml +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application-processor.yml @@ -2,18 +2,17 @@ ## Step1. 请先在任务调度控制台创建命名空间和应用分组 spring: schedulerx2: - endpoint: acm.aliyun.com #请填写不同region的endpoint - namespace: 433d8b23-xxx-xxx-xxx-90d4d1b9a4af #region内全局唯一,建议使用UUID生成 + endpoint: acm.aliyun.com #请填写不同region的endpoint + namespace: 433d8b23-xxx-xxx-xxx-90d4d1b9a4af #region内全局唯一,推荐控制台手动创建,如控制台region下不存在且存在任务配置时会自动创建(建议使用UUID生成) namespaceName: 测试环境 namespaceSource: schedulerx - appName: myTest #应用名称 - groupId: myTest.group #应用的id标识,一个命名空间下需要唯一 - appKey: myTest123@alibaba #应用的key,不要太简单,注意保管好 - regionId: public #请填写不同的regionId + appName: myTest #应用名称,如控制台手动创建应用分组则直接复制过来配置即可 + groupId: myTest.group #应用的id标识,一个命名空间下需要唯一,推荐控制台手动创建,如控制台region下不存在且存在任务配置时会自动创建 + appKey: myTest123@alibaba #应用的key,不要太简单,注意保管好,如控制台手动创建应用分组则直接复制过来配置即可 + regionId: public #请填写不同的regionId,用于自动同步下方的任务信息至指定的region aliyunAccessKey: xxxxxxxxx aliyunSecretKey: xxxxxxxxx - alarmChannel: sms,ding #报警通道:短信和钉钉 - jobs: + jobs: simpleJob: jobModel: standalone className: com.alibaba.cloud.examples.schedulerx.job.processor.SimpleJob @@ -37,12 +36,5 @@ spring: cron: 0 * * * * ? jobParameter: 100 overwrite: true - alarmUsers: - user1: - userName: 张三 - userPhone: 12345678900 - user2: - userName: 李四 - ding: https://oapi.dingtalk.com/robot/send?access_token=xxxxx logging: config: classpath:log4j2.xml \ No newline at end of file diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application.properties b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application.properties new file mode 100644 index 0000000..a48f682 --- /dev/null +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application.properties @@ -0,0 +1,17 @@ +## 控制台定义任务配置信息,或通过注解定义任务 (推荐模式) +## Step1. 请先在任务调度控制台创建命名空间和应用分组 +spring.schedulerx2.endpoint=acm.aliyun.com #请填写不同region的endpoint +spring.schedulerx2.namespace=aad167f6-8bee-xxxx-xxxx-xxxxxxxxx #region内全局唯一,控制台上创建命名空间时自动生成 +spring.schedulerx2.groupId=qianxi.dev #应用的id标识,从控制台上创建应用分组时自定义填写,一个命名空间下需要唯一 +spring.schedulerx2.appKey=xxxxxxxxxxxxxxxxxxxxxxxx #应用的key,从控制台上获取 +spring.schedulerx2.task.scheduling.scheduler=schedulerx #接管Spring定时任务 + +# 可选,开启自动同步Spring注解任务 +#spring.schedulerx2.task.scheduling.sync=true +#spring.schedulerx2.task.scheduling.overwrite=false +#spring.schedulerx2.regionId=public +#spring.schedulerx2.aliyunAccessKey=XXXXXXXXX +#spring.schedulerx2.aliyunSecretKey=XXXXXXXXX + +## 日志配置 +logging.config=classpath:log4j2.xml \ No newline at end of file diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application.yml b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application.yml deleted file mode 100644 index 2afaf27..0000000 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application.yml +++ /dev/null @@ -1,20 +0,0 @@ -## 控制台定义任务配置信息,或通过注解定义任务 (推荐模式) -## Step1. 请先在任务调度控制台创建命名空间和应用分组 -spring: - schedulerx2: - endpoint: acm.aliyun.com #请填写不同region的endpoint - namespace: aad167f6-8bee-xxxx-xxxx-xxxxxxxxx #region内全局唯一,控制台上创建命名空间时自动生成 - groupId: qianxi.dev #应用的id标识,从控制台上创建应用分组时自定义填写,一个命名空间下需要唯一 - appKey: xxxxxxxxxxxxxxxxxxxxxxxx #应用的key,从控制台上获取 - task: - scheduling: - scheduler: schedulerx # 接管Spring定时任务 -# 可选,开启自动同步Spring注解任务 -# sync: true -# overwrite: false -# regionId: public -# aliyunAccessKey: XXXXXXXXX -# aliyunSecretKey: XXXXXXXXX - -logging: - config: classpath:log4j2.xml \ No newline at end of file From 902de32c8ef8bcd46f85ec18ef677f9291d3c463 Mon Sep 17 00:00:00 2001 From: yaohui Date: Wed, 19 Oct 2022 14:47:02 +0800 Subject: [PATCH 3/4] update aliyun-schedulerx-spring-boot-sample --- .../readme-zh.md | 15 ++++++++++----- .../src/main/resources/application.properties | 16 +++++++++++----- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/readme-zh.md b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/readme-zh.md index 2dd8944..b3a8f4b 100644 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/readme-zh.md +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/readme-zh.md @@ -23,11 +23,16 @@ 4. 应用配置application.properties,可在控制台->应用管理->XXX应用(接入配置)点击获取 ```properties -spring.schedulerx2.endpoint=acm.aliyun.com #请填写不同region的endpoint -spring.schedulerx2.namespace=aad167f6-8bee-xxxx-xxxx-xxxxxxxxx #region内全局唯一,控制台上创建命名空间时自动生成 -spring.schedulerx2.groupId=qianxi.dev #应用的id标识,从控制台上创建应用分组时自定义填写,一个命名空间下需要唯一 -spring.schedulerx2.appKey=xxxxxxxxxxxxxxxxxxxxxxxx #应用的key,从控制台上获取 -spring.schedulerx2.task.scheduling.scheduler=schedulerx #接管Spring定时任务 +## 请填写不同region的endpoint +spring.schedulerx2.endpoint=acm.aliyun.com +## region内全局唯一,控制台上创建命名空间时自动生成 +spring.schedulerx2.namespace=aad167f6-8bee-xxxx-xxxx-xxxxxxxxx +## 应用的id标识,从控制台上创建应用分组时自定义填写,一个命名空间下需要唯一 +spring.schedulerx2.groupId=qianxi.dev +## 应用的key,从控制台上获取 +spring.schedulerx2.appKey=xxxxxxxxxxxxxxxxxxxxxxxx +## 接管Spring定时任务 +spring.schedulerx2.task.scheduling.scheduler=schedulerx # 可选,开启自动同步Spring注解任务 #spring.schedulerx2.task.scheduling.sync=true diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application.properties b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application.properties index a48f682..ebedf94 100644 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application.properties +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/resources/application.properties @@ -1,10 +1,16 @@ ## 控制台定义任务配置信息,或通过注解定义任务 (推荐模式) ## Step1. 请先在任务调度控制台创建命名空间和应用分组 -spring.schedulerx2.endpoint=acm.aliyun.com #请填写不同region的endpoint -spring.schedulerx2.namespace=aad167f6-8bee-xxxx-xxxx-xxxxxxxxx #region内全局唯一,控制台上创建命名空间时自动生成 -spring.schedulerx2.groupId=qianxi.dev #应用的id标识,从控制台上创建应用分组时自定义填写,一个命名空间下需要唯一 -spring.schedulerx2.appKey=xxxxxxxxxxxxxxxxxxxxxxxx #应用的key,从控制台上获取 -spring.schedulerx2.task.scheduling.scheduler=schedulerx #接管Spring定时任务 + +## 请填写不同region的endpoint +spring.schedulerx2.endpoint=acm.aliyun.com +## region内全局唯一,控制台上创建命名空间时自动生成 +spring.schedulerx2.namespace=aad167f6-8bee-xxxx-xxxx-xxxxxxxxx +## 应用的id标识,从控制台上创建应用分组时自定义填写,一个命名空间下需要唯一 +spring.schedulerx2.groupId=qianxi.dev +## 应用的key,从控制台上获取 +spring.schedulerx2.appKey=xxxxxxxxxxxxxxxxxxxxxxxx +## 接管Spring定时任务 +spring.schedulerx2.task.scheduling.scheduler=schedulerx # 可选,开启自动同步Spring注解任务 #spring.schedulerx2.task.scheduling.sync=true From 8d22ba6574a11b32a1c44dfbf924829499e7d1d1 Mon Sep 17 00:00:00 2001 From: yaohui Date: Mon, 24 Oct 2022 11:11:04 +0800 Subject: [PATCH 4/4] update aliyun-schedulerx-spring-boot-sample --- .../aliyun-schedulerx-spring-boot-sample/readme-zh.md | 2 +- .../cloud/examples/schedulerx/job/annotation/SpringJob.java | 6 ++---- .../aliyun-schedulerx-spring-boot-starter/pom.xml | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/readme-zh.md b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/readme-zh.md index b3a8f4b..48d5873 100644 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/readme-zh.md +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/readme-zh.md @@ -11,7 +11,7 @@ 1. 登录阿里云分布式任务调度[Schedulerx控制台](https://schedulerx2.console.aliyun.com),点击开通服务 -2. 进入任务调度控制台->应用管理,点击"创建应用",配置应用分组信息保存 +2. 进入任务调度控制台->应用管理,点击"创建应用",配置应用分组信息保存(PS:本地开发测试环境仅支持公网region创建分组对接) 3. pom增加依赖aliyun-schedulerx-spring-boot-starter ```xml diff --git a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/annotation/SpringJob.java b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/annotation/SpringJob.java index 134f8c6..fb07f1a 100644 --- a/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/annotation/SpringJob.java +++ b/aliyun-spring-boot-samples/aliyun-schedulerx-spring-boot-sample/src/main/java/com/alibaba/cloud/examples/schedulerx/job/annotation/SpringJob.java @@ -17,7 +17,7 @@ package com.alibaba.cloud.examples.schedulerx.job.annotation; import com.alibaba.schedulerx.common.domain.ExecuteMode; -import com.alibaba.schedulerx.worker.processor.SchedulerX; +import com.alibaba.schedulerx.scheduling.annotation.SchedulerX; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.scheduling.annotation.Scheduled; @@ -48,10 +48,8 @@ public void simpleJob() { * An spring scheduled job * Can use @SchedulerX annotation set job config when open sync(true) */ - @Scheduled(cron = "0/5 * * * * ?") - @SchedulerX(name = "simpleJobWithAnnotation", model = ExecuteMode.STANDALONE) + @SchedulerX(name = "simpleJobWithAnnotation", cron = "0 0/1 * * * ?", model = ExecuteMode.STANDALONE) public void simpleJobWithAnnotation() { logger.info("hello schedulerx! this's an spring simple job with SchedulerX annotation."); } - } diff --git a/aliyun-spring-boot-starters/aliyun-schedulerx-spring-boot-starter/pom.xml b/aliyun-spring-boot-starters/aliyun-schedulerx-spring-boot-starter/pom.xml index 07f207a..50d13bc 100644 --- a/aliyun-spring-boot-starters/aliyun-schedulerx-spring-boot-starter/pom.xml +++ b/aliyun-spring-boot-starters/aliyun-schedulerx-spring-boot-starter/pom.xml @@ -49,7 +49,7 @@ com.aliyun.schedulerx schedulerx2-spring-boot-starter - 1.7.9 + 1.8.0