XXL-JOB 快速入门指南
XXL-JOB 快速入门指南
https://blog.csdn.net/weixin_44798288/article/details/111772876
https://www.cnblogs.com/just-coder/p/10981618.html
https://blog.51cto.com/u_7117633/2920410
https://www.cnblogs.com/linjiqin/p/10785105.html
https://www.cnblogs.com/gcdd1993/p/12292411.html
首先是环境配置,提前安装好以下三个软件
- Maven3+
- Jdk1.8+
- Mysql5.7+
http://localhost:8080/xxl-job-admin (该地址执行器将会使用到,作为回调地址)
默认登录账号 “admin/123456”, 登录后运行界面如下图所示。
此默认账号密码可在/xxl-job/xxl-job-admin/src/main/resources/application.properties文件中填写
显式的加上登录调度中心的账号密码
xxl.job.login.username=admin
xxl.job.login.password=123456
至此“调度中心”项目已经部署成功。
2.4 配置部署“执行器项目”
“执行器”项目:xxl-job-executor-sample-springboot (提供多种版本执行器供选择,现以 springboot 版本为例,可直接使用,也可以参考其并将现有项目改造成执行器)
作用:负责接收“调度中心”的调度并执行;可直接部署执行器,也可以将执行器集成到现有业务项目中。
步骤一:maven依赖
版本号根据调度中心的版本号一致
<dependency> <groupId>com.xuxueligroupId> <artifactId>xxl-job-coreartifactId> <version>2.2.0version> dependency>
步骤二:执行器配置
执行器配置,配置文件地址:
/xxl-job/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/resources/application.properties
执行器配置,配置内容说明:
### 调度中心部署跟地址 [选填]:如调度中心集群部署存在多个地址则用逗号分隔。执行器将会使用该地址进行"执行器心跳注册"和"任务结果回调";为空则关闭自动注册;
xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin
### 执行器通讯TOKEN [选填]:非空时启用;
xxl.job.accessToken=
### 执行器AppName [选填]:执行器心跳注册分组依据;为空则关闭自动注册
xxl.job.executor.appname=xxl-job-executor-sample
### 执行器注册 [选填]:优先使用该配置作为注册地址,为空时使用内嵌服务 ”IP:PORT“ 作为注册地址。从而更灵活的支持容器类型执行器动态IP和动态映射端口问题。
xxl.job.executor.address=
### 执行器IP [选填]:默认为空表示自动获取IP,多网卡时可手动设置指定IP,该IP不会绑定Host仅作为通讯实用;地址信息用于 "执行器注册" 和 "调度中心请求并触发任务";
xxl.job.executor.ip=
### 执行器端口号 [选填]:小于等于0则自动获取;默认端口为9999,单机部署多个执行器时,注意要配置不同执行器端口;
xxl.job.executor.port=9999
### 执行器运行日志文件存储磁盘路径 [选填] :需要对该路径拥有读写权限;为空则使用默认路径;
xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler
### 执行器日志文件保存天数 [选填] : 过期日志自动清理, 限制值大于等于3时生效; 否则, 如-1, 关闭自动清理功能;
xxl.job.executor.logretentiondays=30
步骤三:执行器组件配置
执行器组件,配置文件地址:
/xxl-job/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/java/com/xxl/job/executor/core/config/XxlJobConfig.java
执行器组件,配置内容说明:
@Bean
public XxlJobSpringExecutor xxlJobExecutor() {
logger.info(">>>>>>>>>>> xxl-job config init.");
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
xxlJobSpringExecutor.setAppname(appname);
xxlJobSpringExecutor.setIp(ip);
xxlJobSpringExecutor.setPort(port);
xxlJobSpringExecutor.setAccessToken(accessToken);
xxlJobSpringExecutor.setLogPath(logPath);
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
return xxlJobSpringExecutor;
}
步骤四:部署执行器项目:
如果已经正确进行上述配置,可将执行器项目编译打部署,系统提供多种执行器Sample示例项目,选择其中一个即可,各自的部署方式如下。
xxl-job-executor-sample-springboot:项目编译打包成springboot类型的可执行JAR包,命令启动即可;
xxl-job-executor-sample-frameless:项目编译打包成JAR包,命令启动即可;
至此“执行器”项目已经部署结束。
java -jar xxl-job-executor-sample-springboot-2.2.0.jar
运行执行器jar包时,会根据/xxl-job/xxl-job-executor-samples/xxl-job-executor-sample-springboot/src/main/resources/application.properties配置文件自动注册到调度数据库中的xxl_job_registry表
至此,调度中心、执行器都已启动,接下来就是新增具体要执行的任务了,在任务管理菜单中新增任务
java -jar xxl-job-executor-sample-springboot-2.2.0.jar --server.port=8082 --xxl.job.executor.port=8802
,执行上述命令后,执行器中会有显示
其他的慢慢摸索吧!!!!