diff --git a/config/dev/datasource.yml b/config/dev/datasource.yml
index b16fdc57..56644b81 100644
--- a/config/dev/datasource.yml
+++ b/config/dev/datasource.yml
@@ -9,7 +9,7 @@ datasource:
url: jdbc:mysql://localhost:3306/ry-cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&rewriteBatchedStatements=true
username: root
password: password
- xxl-job-admin:
+ job:
url: jdbc:mysql://localhost:3306/ry-job?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&rewriteBatchedStatements=true
username: root
password: password
diff --git a/config/dev/ruoyi-job.yml b/config/dev/ruoyi-job.yml
new file mode 100644
index 00000000..40e04cdb
--- /dev/null
+++ b/config/dev/ruoyi-job.yml
@@ -0,0 +1,41 @@
+# dubbo 订阅配置
+dubbo:
+ cloud:
+ # 需要远程调用的服务 多个用逗号分割
+ subscribed-services: ruoyi-system
+
+spring:
+ datasource:
+ dynamic:
+ # 设置默认的数据源或者数据源组,默认值即为 master
+ primary: master
+ datasource:
+ # 主库数据源
+ master:
+ driver-class-name: com.mysql.cj.jdbc.Driver
+ url: ${datasource.job.url}
+ username: ${datasource.job.username}
+ password: ${datasource.job.password}
+
+xxl:
+ job:
+ # 执行器开关
+ enabled: true
+ # 调度中心地址:如调度中心集群部署存在多个地址则用逗号分隔。
+ admin-addresses: http://localhost:9900
+ # 执行器通讯TOKEN:非空时启用
+ access-token: xxl-job
+ # 执行器配置
+ executor:
+ # 执行器AppName:执行器心跳注册分组依据;为空则关闭自动注册
+ appname: ${spring.application.name}-executor
+ # 执行器端口号 执行器从19901开始往后写
+ port: 9901
+ # 执行器注册:默认IP:PORT
+ address:
+ # 执行器IP:默认自动获取IP
+ ip:
+ # 执行器运行日志文件存储磁盘路径
+ logpath: ./logs/${spring.application.name}/xxl-job
+ # 执行器日志文件保存天数:大于3生效
+ logretentiondays: 30
diff --git a/config/dev/ruoyi-system.yml b/config/dev/ruoyi-system.yml
index f9ec5657..15e215ed 100644
--- a/config/dev/ruoyi-system.yml
+++ b/config/dev/ruoyi-system.yml
@@ -22,26 +22,3 @@ spring:
# url:
# username:
# password:
-
-xxl:
- job:
- # 执行器开关
- enabled: true
- # 调度中心地址:如调度中心集群部署存在多个地址则用逗号分隔。
- admin-addresses: http://localhost:9900
- # 执行器通讯TOKEN:非空时启用
- access-token: xxl-job
- # 执行器配置
- executor:
- # 执行器AppName:执行器心跳注册分组依据;为空则关闭自动注册
- appname: ${spring.application.name}-executor
- # 执行器端口号 执行器从19901开始往后写
- port: 9901
- # 执行器注册:默认IP:PORT
- address:
- # 执行器IP:默认自动获取IP
- ip:
- # 执行器运行日志文件存储磁盘路径
- logpath: ./logs/${spring.application.name}/xxl-job
- # 执行器日志文件保存天数:大于3生效
- logretentiondays: 30
diff --git a/config/dev/ruoyi-xxl-job-admin.yml b/config/dev/ruoyi-xxl-job-admin.yml
index 9f5f9c22..7b3bacfc 100644
--- a/config/dev/ruoyi-xxl-job-admin.yml
+++ b/config/dev/ruoyi-xxl-job-admin.yml
@@ -3,9 +3,9 @@ spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
- url: ${datasource.xxl-job-admin.url}
- username: ${datasource.xxl-job-admin.username}
- password: ${datasource.xxl-job-admin.password}
+ url: ${datasource.job.url}
+ username: ${datasource.job.username}
+ password: ${datasource.job.password}
hikari:
auto-commit: true
connection-test-query: SELECT 1
diff --git a/config/dev/seata-server.properties b/config/dev/seata-server.properties
index 2acdaab0..af555eb0 100644
--- a/config/dev/seata-server.properties
+++ b/config/dev/seata-server.properties
@@ -2,6 +2,7 @@ service.vgroupMapping.ruoyi-auth-group=default
service.vgroupMapping.ruoyi-system-group=default
service.vgroupMapping.ruoyi-resource-group=default
service.vgroupMapping.ruoyi-gen-group=default
+service.vgroupMapping.ruoyi-job-group=default
service.enableDegrade=false
service.disableGlobalTransaction=false
store.mode=db
diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
index dc0b4de3..fc3faf55 100644
--- a/docker/docker-compose.yml
+++ b/docker/docker-compose.yml
@@ -12,7 +12,7 @@ services:
# 初始化数据库
MYSQL_DATABASE: ry-cloud
ports:
- - 3306:3306
+ - "3306:3306"
volumes:
# 数据挂载
- /docker/mysql/data/:/var/lib/mysql/
@@ -35,9 +35,9 @@ services:
image: nacos/nacos-server:2.0.4
container_name: nacos
ports:
- - 8848:8848
- - 9848:9848
- - 9849:9849
+ - "8848:8848"
+ - "9848:9848"
+ - "9849:9849"
environment:
TZ: Asia/Shanghai
MODE: standalone
@@ -61,7 +61,7 @@ services:
image: redis:6.2.6
container_name: redis
ports:
- - 6379:6379
+ - "6379:6379"
environment:
# 时区上海
TZ: Asia/Shanghai
@@ -82,9 +82,9 @@ services:
container_name: minio
ports:
# api 端口
- - 9000:9000
+ - "9000:9000"
# 控制台端口
- - 9001:9001
+ - "9001:9001"
environment:
# 时区上海
TZ: Asia/Shanghai
@@ -108,7 +108,7 @@ services:
image: seataio/seata-server:1.4.2
container_name: seata-server
ports:
- - 8091:8091
+ - "8091:8091"
environment:
TZ: Asia/Shanghai
# 注意 此处ip如果是外网使用 要改为外网ip
@@ -131,8 +131,8 @@ services:
# 时区上海
TZ: Asia/Shanghai
ports:
- - 80:80
- - 443:443
+ - "80:80"
+ - "443:443"
volumes:
# 证书映射
- /docker/nginx/cert:/etc/nginx/cert
@@ -153,7 +153,7 @@ services:
environment:
TZ: Asia/Shanghai
ports:
- - 8718:8718
+ - "8718:8718"
volumes:
# 配置文件
- /docker/ruoyi-sentinel-dashboard/logs/:/ruoyi/sentinel-dashboard/logs
@@ -169,7 +169,7 @@ services:
# 时区上海
TZ: Asia/Shanghai
ports:
- - 9100:9100
+ - "9100:9100"
volumes:
# 配置文件
- /docker/ruoyi-monitor/logs/:/ruoyi/monitor/logs
@@ -186,7 +186,7 @@ services:
# 时区上海
TZ: Asia/Shanghai
ports:
- - 9900:9900
+ - "9900:9900"
volumes:
# 配置文件
- /docker/ruoyi-xxl-job-admin/logs/:/ruoyi/xxl-job-admin/logs
@@ -203,7 +203,7 @@ services:
# 时区上海
TZ: Asia/Shanghai
ports:
- - 8080:8080
+ - "8080:8080"
volumes:
# 配置文件
- /docker/ruoyi-gateway/logs/:/ruoyi/gateway/logs
@@ -220,7 +220,7 @@ services:
# 时区上海
TZ: Asia/Shanghai
ports:
- - 9200:9200
+ - "9200:9200"
volumes:
# 配置文件
- /docker/ruoyi-auth/logs/:/ruoyi/auth/logs
@@ -237,7 +237,7 @@ services:
# 时区上海
TZ: Asia/Shanghai
ports:
- - 9201:9201
+ - "9201:9201"
volumes:
# 配置文件
- /docker/ruoyi-system/logs/:/ruoyi/system/logs
@@ -246,6 +246,38 @@ services:
networks:
- ruoyi_net
+ ruoyi-gen:
+ image: ruoyi/ruoyi-gen:0.7.0
+ container_name: ruoyi-gen
+ environment:
+ # 时区上海
+ TZ: Asia/Shanghai
+ ports:
+ - "9202:9202"
+ volumes:
+ # 配置文件
+ - /docker/ruoyi-gen/logs/:/ruoyi/gen/logs
+ privileged: true
+ restart: always
+ networks:
+ - ruoyi_net
+
+ ruoyi-job:
+ image: ruoyi/ruoyi-job:0.7.0
+ container_name: ruoyi-job
+ environment:
+ # 时区上海
+ TZ: Asia/Shanghai
+ ports:
+ - "9203:9203"
+ volumes:
+ # 配置文件
+ - /docker/ruoyi-job/logs/:/ruoyi/job/logs
+ privileged: true
+ restart: always
+ networks:
+ - ruoyi_net
+
ruoyi-resource:
image: ruoyi/ruoyi-resource:0.7.0
container_name: ruoyi-resource
@@ -253,7 +285,7 @@ services:
# 时区上海
TZ: Asia/Shanghai
ports:
- - 9300:9300
+ - "9300:9300"
volumes:
# 配置文件
- /docker/ruoyi-resource/logs/:/ruoyi/resource/logs
diff --git a/ruoyi-modules/pom.xml b/ruoyi-modules/pom.xml
index 940f954d..55e612fe 100644
--- a/ruoyi-modules/pom.xml
+++ b/ruoyi-modules/pom.xml
@@ -11,6 +11,7 @@
ruoyi-system
ruoyi-gen
+ ruoyi-job
ruoyi-resource
diff --git a/ruoyi-modules/ruoyi-job/Dockerfile b/ruoyi-modules/ruoyi-job/Dockerfile
new file mode 100644
index 00000000..c29994a1
--- /dev/null
+++ b/ruoyi-modules/ruoyi-job/Dockerfile
@@ -0,0 +1,15 @@
+FROM anapsix/alpine-java:8_server-jre_unlimited
+
+MAINTAINER Lion Li
+
+RUN mkdir -p /ruoyi/job
+RUN mkdir -p /ruoyi/job/logs
+RUN mkdir -p /ruoyi/job/temp
+
+WORKDIR /ruoyi/job
+
+EXPOSE 9203
+
+ADD ./target/ruoyi-job.jar ./app.jar
+
+ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "app.jar"]
diff --git a/ruoyi-modules/ruoyi-job/pom.xml b/ruoyi-modules/ruoyi-job/pom.xml
new file mode 100644
index 00000000..b00900cb
--- /dev/null
+++ b/ruoyi-modules/ruoyi-job/pom.xml
@@ -0,0 +1,116 @@
+
+
+
+ com.ruoyi
+ ruoyi-modules
+ 0.7.0
+
+ 4.0.0
+
+ ruoyi-job
+
+
+ ruoyi-job 任务调度模块
+
+
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-discovery
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-nacos-config
+
+
+
+
+ com.alibaba.cloud
+ spring-cloud-starter-alibaba-sentinel
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
+
+ mysql
+ mysql-connector-java
+
+
+
+
+ com.ruoyi
+ ruoyi-common-log
+
+
+
+ com.ruoyi
+ ruoyi-common-dict
+
+
+
+ com.ruoyi
+ ruoyi-common-web
+
+
+
+ com.ruoyi
+ ruoyi-common-dubbo
+
+
+
+ com.ruoyi
+ ruoyi-common-mybatis
+
+
+
+ com.ruoyi
+ ruoyi-common-seata
+
+
+
+ com.ruoyi
+ ruoyi-common-job
+
+
+
+
+ com.ruoyi
+ ruoyi-api-system
+
+
+
+
+
+ ${project.artifactId}
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+ ${spring-boot.version}
+
+
+
+ repackage
+
+
+
+
+
+ com.spotify
+ docker-maven-plugin
+
+
+
+
+
diff --git a/ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/RuoYiJobApplication.java b/ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/RuoYiJobApplication.java
new file mode 100644
index 00000000..9b365160
--- /dev/null
+++ b/ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/RuoYiJobApplication.java
@@ -0,0 +1,23 @@
+package com.ruoyi.job;
+
+import com.ruoyi.common.security.annotation.EnableCustomConfig;
+import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * 任务调度模块
+ *
+ * @author Lion Li
+ */
+@EnableCustomConfig
+@EnableDubbo
+@SpringBootApplication
+public class RuoYiJobApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(RuoYiJobApplication.class, args);
+ System.out.println("(♥◠‿◠)ノ゙ 任务调度模块启动成功 ლ(´ڡ`ლ)゙ ");
+ }
+
+}
diff --git a/ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/service/MultiService.java b/ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/service/MultiService.java
new file mode 100644
index 00000000..c86f6d4d
--- /dev/null
+++ b/ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/service/MultiService.java
@@ -0,0 +1,39 @@
+package com.ruoyi.job.service;
+
+import com.ruoyi.system.api.RemoteUserService;
+import com.ruoyi.system.api.domain.SysUser;
+import com.ruoyi.system.api.model.LoginUser;
+import com.xxl.job.core.context.XxlJobHelper;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import io.seata.spring.annotation.GlobalTransactional;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.springframework.stereotype.Service;
+
+/**
+ * XxlJob 多服务调用
+ *
+ * @author Lion Li
+ */
+@Slf4j
+@Service
+public class MultiService {
+
+ @DubboReference
+ private RemoteUserService remoteUserService;
+
+ /**
+ * 多服务调用
+ */
+ @GlobalTransactional(rollbackFor = Exception.class)
+ @XxlJob("multiServiceHandler")
+ public void multiServiceHandler() throws Exception {
+ LoginUser admin = remoteUserService.getUserInfo("admin");
+ XxlJobHelper.log("XXL-JOB, multiServiceHandler result: {}", admin.toString());
+ SysUser sysUser = new SysUser();
+ sysUser.setUserName("test");
+ sysUser.setNickName("test");
+ remoteUserService.registerUserInfo(sysUser);
+ }
+
+}
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/job/SampleService.java b/ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/service/SampleService.java
similarity index 99%
rename from ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/job/SampleService.java
rename to ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/service/SampleService.java
index cd270226..20afa2e6 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/job/SampleService.java
+++ b/ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/service/SampleService.java
@@ -1,4 +1,4 @@
-package com.ruoyi.system.job;
+package com.ruoyi.job.service;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
diff --git a/ruoyi-modules/ruoyi-job/src/main/resources/banner.txt b/ruoyi-modules/ruoyi-job/src/main/resources/banner.txt
new file mode 100644
index 00000000..683f20c8
--- /dev/null
+++ b/ruoyi-modules/ruoyi-job/src/main/resources/banner.txt
@@ -0,0 +1,10 @@
+Spring Boot Version: ${spring-boot.version}
+Spring Application Name: ${spring.application.name}
+ _ _ _
+ (_) (_) | |
+ _ __ _ _ ___ _ _ _ ______ _ ___ | |__
+| '__| | | |/ _ \| | | | |______| |/ _ \| '_ \
+| | | |_| | (_) | |_| | | | | (_) | |_) |
+|_| \__,_|\___/ \__, |_| | |\___/|_.__/
+ __/ | _/ |
+ |___/ |__/
diff --git a/ruoyi-modules/ruoyi-job/src/main/resources/bootstrap.yml b/ruoyi-modules/ruoyi-job/src/main/resources/bootstrap.yml
new file mode 100644
index 00000000..d1b24675
--- /dev/null
+++ b/ruoyi-modules/ruoyi-job/src/main/resources/bootstrap.yml
@@ -0,0 +1,38 @@
+# Tomcat
+server:
+ port: 9203
+
+# Spring
+spring:
+ main:
+ # 此配置禁止放入 nacos 优先级不够
+ allow-circular-references: true
+ application:
+ # 应用名称
+ name: ruoyi-job
+ profiles:
+ # 环境配置
+ active: @profiles.active@
+
+--- # nacos 配置
+spring:
+ cloud:
+ nacos:
+ # nacos 服务地址
+ server-addr: @nacos.server@
+ discovery:
+ # 注册组
+ group: @nacos.discovery.group@
+ namespace: ${spring.profiles.active}
+ config:
+ # 配置组
+ group: @nacos.config.group@
+ namespace: ${spring.profiles.active}
+ # 配置文件格式
+ file-extension: yml
+ # 共享配置
+ shared-configs:
+ - data-id: application.${spring.cloud.nacos.config.file-extension}
+ refresh: true
+ - data-id: datasource.${spring.cloud.nacos.config.file-extension}
+ refresh: true
diff --git a/ruoyi-modules/ruoyi-job/src/main/resources/logback.xml b/ruoyi-modules/ruoyi-job/src/main/resources/logback.xml
new file mode 100644
index 00000000..b84440de
--- /dev/null
+++ b/ruoyi-modules/ruoyi-job/src/main/resources/logback.xml
@@ -0,0 +1,97 @@
+
+
+
+
+
+
+
+
+
+
+
+ ${console.log.pattern}
+ utf-8
+
+
+
+
+
+ ${log.path}/console.log
+
+
+ ${log.path}/console.%d{yyyy-MM-dd}.log
+
+ 1
+
+
+ ${log.pattern}
+ utf-8
+
+
+
+ INFO
+
+
+
+
+
+ ${log.path}/info.log
+
+
+
+ ${log.path}/info.%d{yyyy-MM-dd}.log
+
+ 60
+
+
+ ${log.pattern}
+
+
+
+ INFO
+
+ ACCEPT
+
+ DENY
+
+
+
+
+ ${log.path}/error.log
+
+
+
+ ${log.path}/error.%d{yyyy-MM-dd}.log
+
+ 60
+
+
+ ${log.pattern}
+
+
+
+ ERROR
+
+ ACCEPT
+
+ DENY
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ruoyi-modules/ruoyi-system/pom.xml b/ruoyi-modules/ruoyi-system/pom.xml
index 7f6dd127..3f1c490e 100644
--- a/ruoyi-modules/ruoyi-system/pom.xml
+++ b/ruoyi-modules/ruoyi-system/pom.xml
@@ -84,11 +84,6 @@
ruoyi-common-seata
-
- com.ruoyi
- ruoyi-common-job
-
-
com.ruoyi
diff --git a/sql/ry-job.sql b/sql/ry-job.sql
index 61bdfa85..2c133677 100644
--- a/sql/ry-job.sql
+++ b/sql/ry-job.sql
@@ -110,10 +110,26 @@ CREATE TABLE `xxl_job_lock` (
PRIMARY KEY (`lock_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-INSERT INTO `xxl_job_group`(`id`, `app_name`, `title`, `address_type`, `address_list`, `update_time`) VALUES (1, 'ruoyi-system-executor', '示例执行器', 0, NULL, '2018-11-03 22:21:31' );
+INSERT INTO `xxl_job_group`(`id`, `app_name`, `title`, `address_type`, `address_list`, `update_time`) VALUES (1, 'ruoyi-job-executor', '示例执行器', 0, NULL, '2018-11-03 22:21:31' );
INSERT INTO `xxl_job_info`(`id`, `job_group`, `job_desc`, `add_time`, `update_time`, `author`, `alarm_email`, `schedule_type`, `schedule_conf`, `misfire_strategy`, `executor_route_strategy`, `executor_handler`, `executor_param`, `executor_block_strategy`, `executor_timeout`, `executor_fail_retry_count`, `glue_type`, `glue_source`, `glue_remark`, `glue_updatetime`, `child_jobid`) VALUES (1, 1, '测试任务1', '2018-11-03 22:21:31', '2018-11-03 22:21:31', 'XXL', '', 'CRON', '0 0 0 * * ? *', 'DO_NOTHING', 'FIRST', 'demoJobHandler', '', 'SERIAL_EXECUTION', 0, 0, 'BEAN', '', 'GLUE代码初始化', '2018-11-03 22:21:31', '');
+INSERT INTO `xxl_job_info`(`id`, `job_group`, `job_desc`, `add_time`, `update_time`, `author`, `alarm_email`, `schedule_type`, `schedule_conf`, `misfire_strategy`, `executor_route_strategy`, `executor_handler`, `executor_param`, `executor_block_strategy`, `executor_timeout`, `executor_fail_retry_count`, `glue_type`, `glue_source`, `glue_remark`, `glue_updatetime`, `child_jobid`) VALUES (2, 1, '多服务任务', '2022-02-17 12:21:31', '2022-02-17 12:21:31', 'XXL', '', 'CRON', '0 0 0 * * ? *', 'DO_NOTHING', 'FIRST', 'multiServiceHandler', '', 'SERIAL_EXECUTION', 0, 0, 'BEAN', '', 'GLUE代码初始化', '2022-02-17 12:21:31', '');
INSERT INTO `xxl_job_user`(`id`, `username`, `password`, `role`, `permission`) VALUES (1, 'admin', 'e10adc3949ba59abbe56e057f20f883e', 1, NULL);
INSERT INTO `xxl_job_lock` ( `lock_name`) VALUES ( 'schedule_lock');
+-- for AT mode you must to init this sql for you business database. the seata server not need it.
+CREATE TABLE IF NOT EXISTS `undo_log`
+(
+ `branch_id` BIGINT(20) NOT NULL COMMENT 'branch transaction id',
+ `xid` VARCHAR(100) NOT NULL COMMENT 'global transaction id',
+ `context` VARCHAR(128) NOT NULL COMMENT 'undo_log context,such as serialization',
+ `rollback_info` LONGBLOB NOT NULL COMMENT 'rollback info',
+ `log_status` INT(11) NOT NULL COMMENT '0:normal status,1:defense status',
+ `log_created` DATETIME(6) NOT NULL COMMENT 'create datetime',
+ `log_modified` DATETIME(6) NOT NULL COMMENT 'modify datetime',
+ UNIQUE KEY `ux_undo_log` (`xid`, `branch_id`)
+) ENGINE = InnoDB
+ AUTO_INCREMENT = 1
+ DEFAULT CHARSET = utf8mb4 COMMENT ='AT transaction mode undo table';
+
commit;