当前位置:网站首页>xxl-job使用指南
xxl-job使用指南
2022-07-01 02:51:00 【纸素画笺】
xxl-job使用指南
官网:https://www.xuxueli.com/xxl-job
一、安装依赖
1.1 基础依赖
说明解释
本文只讲解已部署好的xxl-job如何使用
依赖地址
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<version>2.3.0</version>
</dependency>
二、配置xxl-job
2.1 目录结构

2.2 配置文件代码
XxlJobConfig
package xx.xx.crawler.supplier.configuration;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Data
@ConfigurationProperties(prefix = "xxl.job")
@Configuration
public class XxlJobConfig {
/** * 执行器AppName [选填]:执行器心跳注册分组依据;为空则关闭自动注册 */
private String appname;
/** * 服务注册地址,优先使用该配置作为注册地址 为空时使用内嵌服务 ”IP:PORT“ 作为注册地址 从而更灵活的支持容器类型执行器动态IP和动态映射端口问题 */
private String address;
/** * 执行器IP [选填]:默认为空表示自动获取IP,多网卡时可手动设置指定IP ,该IP不会绑定Host仅作为通讯实用;地址信息用于 "执行器注册" 和 * "调度中心请求并触发任务" */
private String ip;
/** * 执行器端口号 [选填]:小于等于0则自动获取;默认端口为9999,单机部署多个执行器时,注意要配置不同执行器端口; */
private Integer port = 8900;
/** * 执行器通讯TOKEN [选填]:非空时启用; */
private String accessToken;
/** * 执行器运行日志文件存储磁盘路径 [选填] :需要对该路径拥有读写权限;为空则使用默认路径; */
private String logPath = "logs/applogs/xxl-job/jobhandler";
/** * 执行器日志保存天数 [选填] :值大于3时生效,启用执行器Log文件定期清理功能,否则不生效; */
private Integer logRetentionDays = 30;
@Bean
public XxlJobSpringExecutor xxlJobExecutor() {
XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
xxlJobSpringExecutor.setAdminAddresses("部署地址");
xxlJobSpringExecutor.setAppname("supplier");
//xxlJobSpringExecutor.setIp(ip);
xxlJobSpringExecutor.setPort(port);
//xxlJobSpringExecutor.setAccessToken(accessToken);
xxlJobSpringExecutor.setLogPath(logPath);
xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
return xxlJobSpringExecutor;
}
}
可以留意到@ConfigurationProperties(prefix = "xxl.job")这段注解,通过配置类来实现不同环境下的xxl-job地址以及端口号的设置
2.3 注意点
2.3.1.port=8900

本地测试:端口号需要与内网穿透地址的端口号一致,下图红框处要写8900,下图中我写的不对

(本地测试连接需要内网穿透)
内网穿透工具地址:https://natapp.cn/
2.3.2 setAdminAddresses
xxlJobSpringExecutor.setAdminAddresses设置对应的xxl-job地址(注册到对应地址上的xxl-job)
具体使用地址看自己部署的地址
2.3.3 setAppname
要保证该命名和三、在xxl-job中注册服务中注册的执行器名称相同
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-UpLbDwib-1656002860119)(xxl-job使用指南.assets/1651722324714.png)]](/img/85/34ef55ec0fa08aa1e2f4d46fe5be61.png)
三、在xxl-job中注册服务
3.1 登录xxl-job服务中心
地址:找运维要,自己部署的自己知道~
账户密码:找运维要,自己部署的自己知道~
3.2 注册执行器
3.2.1 点击新增
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Yhr46N65-1656002860119)(xxl-job使用指南.assets/1651722415769.png)]](/img/96/6bfd578dcb2cbd6c84292c07f758bf.png)
3.2.2 新增执行器
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Q2YpYqgX-1656002860120)(xxl-job使用指南.assets/1651722448958.png)]](/img/fc/c944814931a83e057d17174e6907af.png)
注意点:线上部署使用自动注册,本地调用使用手动录入,录入地址为内网穿透提供的地址(笔记本可用自动注册,宽带用户只能手动录入)【初学,如有大佬知道原因请指正】
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-D8rlnkb4-1656002860120)(xxl-job使用指南.assets/1651722553218.png)]](/img/c2/2228315a779c73a75c521ae09f58a2.png)
确保这里的端口号和二、配置文件代码中相同(这里不同仅做展示)
3.2.3 注册完毕
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-UGkjo3vF-1656002860120)(xxl-job使用指南.assets/1651722625261.png)]](/img/d3/c127f54957bd843c22ee1279546202.png)
可以在执行器管理中心查看
3.3 创建调度任务
3.3.1 点击新增

当然我这边是已经有创建好的任务
3.3.2 创建任务

JobHandler在代码中配置,配置方法如下
@XxlJob() //使用该注解
实例
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-5avsuovr-1656002860121)(xxl-job使用指南.assets/1651722934959.png)]](/img/53/b53ccf51616b393575bc6201b6685f.png)
增加该注解,取消原本的定时服务,将其注册到xxl-job中。" "中的自定义命名即为JobHandler中的命名
四、执行测试,日志查看
4.1 执行
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-yb7GKClE-1656002860122)(xxl-job使用指南.assets/1651723130521.png)]](/img/2b/f054dec3b31c8a0d1295e94ba1df9f.png)
4.2 调度日志
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tBDF2Off-1656002860122)(xxl-job使用指南.assets/1651723169177.png)]](/img/b9/d68b9089fc096cafbbe88e54618104.png)
查看日志,没问题就收工~
边栏推荐
- [multi source BFS] 934 Shortest Bridge
- Restcloud ETL实践之数据行列转换
- Mouse over effect III
- Here comes the share creators budding talent training program!
- Pulsar 主题压缩
- How to use Jieba participle in unity
- Mouse over effect V
- Densenet network paper learning notes
- js防抖和节流
- I want to know how to open a stock account? Is it safe to open an account online?
猜你喜欢

Restcloud ETl数据通过时间戳实现增量数据同步

【小程序项目开发 -- 京东商城】uni-app 商品分类页面(下)

Pulsar Geo Replication/灾备/地域复制

php批量excel转word

Pulsar geo replication/ disaster recovery / regional replication

Restcloud ETL WebService data synchronization to local

Share Creators萌芽人才培养计划来了!

Restcloud ETL实践之数据行列转换

RestCloud ETL实践之无标识位实现增量数据同步

Nacos configuration center tutorial
随机推荐
【小程序项目开发--京东商城】uni-app之自定义搜索组件(上)
Zero foundation self-study SQL course | window function
Restcloud ETL实践之数据行列转换
UE4渲染管线学习笔记
详解数据治理知识体系
通信协议——分类及其特征介绍
Viewing JVM parameters
Pychart software deployment gray unable to point
Is it safe to open a stock account? Shanghai stock account opening procedures.
SAP ALV summary is inconsistent with exported excel summary data
Prototype and prototype chain in JS
MnasNet学习笔记
How to buy Hong Kong shares in China? What platform is safer?
C language a little bit (may increase in the future)
Small program cloud development -- wechat official account article collection
Pychar open remote directory remote host
Mouse over effect 7
Gartner研究:在中国,混合云的采用已成为主流趋势
SSH configuration password free login error: /usr/bin/ssh copy ID: error: no identities found solution
基于Pytorch完整的训练一个神经网络并进行验证