xxl-job任务调度中心部署整合SpringBoot
创始人
2025-05-28 15:05:15
0次

使用Docker部署调度中心

1、拉取镜像

docker pull xuxueli/xxl-job-admin:2.3.1

2、从gitee下载sql文件
https://gitee.com/xuxueli0323/xxl-job/tree/master/doc/db
在这里插入图片描述在数据库中运行sql文件
在这里插入图片描述
3、运行xxl-job镜像

docker run -e PARAMS="--spring.datasource.url=jdbc:mysql://182.40.202.xxx:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=UTC --spring.datasource.username=root --spring.datasource.password=123456" -p 8090:8080 -p 9999:9999  -v /root/sifan/xxl-job:/data/applogs --name=xxl-job-admin -d xuxueli/xxl-job-admin:2.3.1

注意:数据库ip、用户名、密码配置成自己的;需要开放两个端口一个供调度器使用,一个供执行器使用;端口值自己可以定义。我这里使用了8090端口和9999端口。
4、访问控制面板
http://182.40.202.xxx:8090/xxl-job-admin/jobinfo
默认用户名:admin 密码:123456
注意:有设置防火墙和安全组的需要开放端口。
在这里插入图片描述

SpringBoot整合xxl-job

pom依赖

        com.xuxuelixxl-job-core2.3.1

yml配置

# 任务调度中心
api:initListen:###开启配置xxl: true
xxl:job:admin:addresses: http://182.40.202.xxx:8090/xxl-job-admin/userName: adminpassword: 123456accessToken: default_tokenexecutor:appname: core### xxl-job executor registry-address: default use address to registry , otherwise use ip:port if address is nulladdress:### xxl-job executor server-infoip:### 执行器端口号 [选填]:小于等于0则自动获取;默认端口为9999,单机部署多个执行器时,注意要配置不同执行器端口;port: 9999### 执行器运行日志文件存储磁盘路径 [选填] :需要对该路径拥有读写权限;为空则使用默认路径logpath: logs/xxl-job/jobhandler### xxl-job executor log-retention-dayslogretentiondays: 7

在yml中配置了一个执行器appname为core
配置类

@Configuration
@ConditionalOnProperty(prefix = "api", name = "initListen.xxl")
@Slf4j
public class XXLJobConfig {@Value("${xxl.job.admin.addresses}")private String adminAddresses;@Value("${xxl.job.accessToken}")private String accessToken;@Value("${xxl.job.executor.appname}")private String appname;@Value("${xxl.job.executor.address}")private String address;@Value("${xxl.job.executor.ip}")private String ip;@Value("${xxl.job.executor.port}")private int port;@Value("${xxl.job.executor.logpath}")private String logPath;@Value("${xxl.job.executor.logretentiondays}")private int logRetentionDays;@Beanpublic XxlJobSpringExecutor xxlJobExecutor() {log.info(">>>>>>>>>>> xxl-job config init.");XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();xxlJobSpringExecutor.setAdminAddresses(adminAddresses);xxlJobSpringExecutor.setAppname(appname);xxlJobSpringExecutor.setAddress(address);xxlJobSpringExecutor.setIp(ip);xxlJobSpringExecutor.setPort(port);xxlJobSpringExecutor.setAccessToken(accessToken);xxlJobSpringExecutor.setLogPath(logPath);xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);return xxlJobSpringExecutor;}}

SpringBoot连接任务调度中心

上面在yml配置了一个执行器
接下来去调度中心配置,点击新增
在这里插入图片描述这里appname写yml定义的appname的值。我这里是core
在这里插入图片描述
启动SpringBoot,成功注册
在这里插入图片描述任务调度中心也出现注册的信息
在这里插入图片描述

SpringBoot创建定时任务

在SpringBoot中创建一个Job用于测试,处理器的名字为helloWordHandler

@Component
@Slf4j
public class XxlJob {@com.xxl.job.core.handler.annotation.XxlJob("helloWordHandler")public void demoJobHandler() throws Exception {XxlJobHelper.log("XXL-JOB, Hello World.");log.info("XXL-JOB, Hello World.");for (int i = 0; i < 5; i++) {System.out.println("Hello World");XxlJobHelper.log("beat at:" + i);TimeUnit.SECONDS.sleep(1);}}
}

在调度中心创建定时任务
指定创建的执行器
在这里插入图片描述在这里插入图片描述写上cron和处理器,处理器是自己在代码中@XxlJob注解中的值
在这里插入图片描述
启动任务
在这里插入图片描述
把应用部署之后可以看到定时任务运行了

在这里插入图片描述调度日志也ok
停掉任务后台也不再打印

相关内容

热门资讯

实测发现!微信小程序微乐辅助器... 您好,微信小程序微乐辅助器这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很...
一分钟揭秘!微乐游戏小程序脚本... 一分钟揭秘!微乐游戏小程序脚本(透视器),微乐西安麻将好像是有透视挂工具一、微乐游戏小程序脚本游戏安...
实测必看!微信微乐游戏有辅助吗... 实测必看!微信微乐游戏有辅助吗(外挂),微乐宁夏捉老麻子好像是有透视挂方法1、该软件可以轻松地帮助玩...
一起来探讨!微乐小程序晃晃脚本... 一起来探讨!微乐小程序晃晃脚本(作弊器),微乐西安麻将一直真的是有透视挂技巧1、微乐小程序晃晃脚本公...
玩家必备教程!微乐自建房辅助软... 玩家必备教程!微乐自建房辅助软件功能(透视挂),微乐贵阳捉鸡果然是真的有透视挂工具1、玩家必备教程!...
科普常识!微信卡五星小程序辅助... 科普常识!微信卡五星小程序辅助(辅助),微乐山东麻将真是存在有透视挂技巧1、微信卡五星小程序辅助辅助...
一秒答解!微乐家乡官方app(... 一秒答解!微乐家乡官方app(辅助器),微信微乐卡五星确实真的有透视挂脚本1、很好的工具软件,可以解...
最新技巧!微信小程序微乐辅助器... 最新技巧!微信小程序微乐辅助器免费版v2.0(辅助),微信微乐卡五星切实真的是有透视挂方法1)微信小...
一分钟了解!微乐小程序辅助免费... 一分钟了解!微乐小程序辅助免费(透视器),微乐长沙跑胡子确实存在有透视挂插件;1、点击下载安装,微乐...
揭秘几款!微信小程序微乐辅助器... 揭秘几款!微信小程序微乐辅助器教程(透视挂),微乐宁夏麻将切实真的有透视挂app1、打开软件启动之后...