XXL-JOB入门教学

news/2024/5/18 22:40:45 标签: xxl-job, XXL-JOB, 分布式任务调度

目录

目标

官方文档及项目下载地址

实战

搭建调度中心

创建任务调度(这里演示SpringBoot版本)


目标

掌握XXL-JOB项目基本搭建和使用。


官方文档及项目下载地址

分布式任务调度平台XXL-JOBhttps://www.xuxueli.com/XXL-JOB.html" title=xxl-job>xxl-job/


实战

搭建调度中心

第一步:下载XXL-JOB项目(略)。 


 第二步:执行相关的SQL脚本,此时会创建一个名字为xxl_job的数据库。


第三步:在XXL-JOB.html" title=xxl-job>xxl-job-admin项目中配置application.properties。需要注意基础配置,如:端口、数据库连接配置、访问地址,日志所在目录等。

### web
server.port=8099
server.servlet.context-path=/XXL-JOB.html" title=xxl-job>xxl-job-admin

### actuator
management.server.servlet.context-path=/actuator
management.health.mail.enabled=false

### resources
spring.mvc.servlet.load-on-startup=0
spring.mvc.static-path-pattern=/static/**
spring.resources.static-locations=classpath:/static/

### freemarker
spring.freemarker.templateLoaderPath=classpath:/templates/
spring.freemarker.suffix=.ftl
spring.freemarker.charset=UTF-8
spring.freemarker.request-context-attribute=request
spring.freemarker.settings.number_format=0.##########

### mybatis
mybatis.mapper-locations=classpath:/mybatis-mapper/*Mapper.xml
#mybatis.type-aliases-package=com.xxl.job.admin.core.model

### XXL-JOB.html" title=xxl-job>xxl-job, datasource
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

### datasource-pool
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.minimum-idle=10
spring.datasource.hikari.maximum-pool-size=30
spring.datasource.hikari.auto-commit=true
spring.datasource.hikari.idle-timeout=30000
spring.datasource.hikari.pool-name=HikariCP
spring.datasource.hikari.max-lifetime=900000
spring.datasource.hikari.connection-timeout=10000
spring.datasource.hikari.connection-test-query=SELECT 1
spring.datasource.hikari.validation-timeout=1000

### XXL-JOB.html" title=xxl-job>xxl-job, email
spring.mail.host=smtp.qq.com
spring.mail.port=25
spring.mail.username=xxx@qq.com
spring.mail.from=xxx@qq.com
spring.mail.password=xxx
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory

### XXL-JOB.html" title=xxl-job>xxl-job, access token
xxl.job.accessToken=default_token

### XXL-JOB.html" title=xxl-job>xxl-job, i18n (default is zh_CN, and you can choose "zh_CN", "zh_TC" and "en")
xxl.job.i18n=zh_CN

## XXL-JOB.html" title=xxl-job>xxl-job, triggerpool max size
xxl.job.triggerpool.fast.max=200
xxl.job.triggerpool.slow.max=100

### XXL-JOB.html" title=xxl-job>xxl-job, log retention days
xxl.job.logretentiondays=30

### XXL-JOB.html" title=xxl-job>xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
xxl.job.admin.addresses=http://127.0.0.1:8099/XXL-JOB.html" title=xxl-job>xxl-job-admin

### XXL-JOB.html" title=xxl-job>xxl-job executor appname
xxl.job.executor.appname=XXL-JOB.html" title=xxl-job>xxl-job-executor-sample
### XXL-JOB.html" title=xxl-job>xxl-job executor registry-address: default use address to registry , otherwise use ip:port if address is null
xxl.job.executor.address=
### XXL-JOB.html" title=xxl-job>xxl-job executor server-info
xxl.job.executor.ip=
xxl.job.executor.port=9999
### XXL-JOB.html" title=xxl-job>xxl-job executor log-path
xxl.job.executor.logpath=D:/idea_workflow/XXL-JOB.html" title=xxl-job>xxl-job-master/log
### XXL-JOB.html" title=xxl-job>xxl-job executor log-retention-days
xxl.job.executor.logretentiondays=30

第四步:配置XxlJobSpringExecutor对象。

package com.xxl.job.admin.config;

import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * XXL-JOB.html" title=xxl-job>xxl-job config
 *
 * @author xuxueli 2017-04-28
 */
@Configuration
public class XxlJobConfig {
    private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);

    @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;


    @Bean
    public XxlJobSpringExecutor xxlJobExecutor() {
        logger.info(">>>>>>>>>>> XXL-JOB.html" title=xxl-job>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;
    }

    /**
     * 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP;
     *
     *      1、引入依赖:
     *          <dependency>
     *             <groupId>org.springframework.cloud</groupId>
     *             <artifactId>spring-cloud-commons</artifactId>
     *             <version>${version}</version>
     *         </dependency>
     *
     *      2、配置文件,或者容器启动变量
     *          spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.'
     *
     *      3、获取IP
     *          String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
     */
}

第五步:启动XXL-JOB.html" title=xxl-job>xxl-job-admin项目,并访问后台管理系统(登录的账号/密码保存在xxl_job_user表中,初始账号/密码:admin/123456)。

#访问路径配置在application.properties文件的xxl.job.admin.addresses属性上。
http://127.0.0.1:8099/XXL-JOB.html" title=xxl-job>xxl-job-admin


创建任务调度(这里演示SpringBoot版本)

第一步:在XXL-JOB.html" title=xxl-job>xxl-job-executor-sample-springboot服务配置application.properties配置文件,注意和调度中心的xxl.job.admin.addresses对应起来。

# web port
server.port=8091
# no web
#spring.main.web-environment=false

# log config
logging.config=classpath:logback.xml

### XXL-JOB.html" title=xxl-job>xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
xxl.job.admin.addresses=http://127.0.0.1:8099/XXL-JOB.html" title=xxl-job>xxl-job-admin

### XXL-JOB.html" title=xxl-job>xxl-job, access token
xxl.job.accessToken=default_token

### XXL-JOB.html" title=xxl-job>xxl-job executor appname
xxl.job.executor.appname=XXL-JOB.html" title=xxl-job>xxl-job-executor-sample
### XXL-JOB.html" title=xxl-job>xxl-job executor registry-address: default use address to registry , otherwise use ip:port if address is null
xxl.job.executor.address=
### XXL-JOB.html" title=xxl-job>xxl-job executor server-info
xxl.job.executor.ip=127.0.0.1
xxl.job.executor.port=9990
### XXL-JOB.html" title=xxl-job>xxl-job executor log-path
xxl.job.executor.logpath=D:/idea_workflow/XXL-JOB.html" title=xxl-job>xxl-job-master/log
### XXL-JOB.html" title=xxl-job>xxl-job executor log-retention-days
xxl.job.executor.logretentiondays=30

第二步:登录后台管理系统,将刚才的信息录入到执行器管理。

 第三步:在XXL-JOB.html" title=xxl-job>xxl-job-executor-sample-springboot编写调度任务并启动项目。

    @XxlJob("myJobHandler")
    public void myJobHandler() throws Exception {
        System.out.println("hello world!");
    }

第四步:在后台管理系统设置调度任务的配置。

第五步:启动XXL-JOB.html" title=xxl-job>xxl-job-executor-sample-springboot项目,尝试执行调度任务。


http://www.niftyadmin.cn/n/1571252.html

相关文章

怎么把数据集的输出值转换成只含有0,1的标签向量

举个例子&#xff1a; 某神经网络有5个输出值&#xff0c;分别对应1-5每个数字的输出概率&#xff0c;先有数据集x(i)x^{(i)}x(i)&#xff0c;其输出值为&#xff0c;y[1223444]y\begin{bmatrix}1\\2\\2\\3\\4\\4\\4\\\end{bmatrix}y⎣⎢⎢⎢⎢⎢⎢⎢⎢⎡​1223444​⎦⎥⎥⎥⎥…

JDK8的新特性stream——让数据结构更具艺术性

目录 目标 操作数据 相关依赖 中间方法 distinct filter map flatMap limit skip sorted 终止方法 allMatch anyMatch collect findAny findFirst forEach max/min noneMatch reduce Collectors的方法 averaging collectingAndThen countIng groupin…

微分与可微

一、微分的定义 什么是微分&#xff1f; 先来看一个例子 设有一个半径为r的金属圆片受热后其半径增加了Δr\Delta_rΔr​&#xff0c;求面积A的增量ΔA\Delta AΔA A(r)πr2ΔAπ(rΔr)2−πr2π[2rΔr(Δr)2]2rπΔrπ(Δr)2\begin{aligned}A(r) &\pi r^2 \newline \\ \…

kafka常见命令集锦

目录 目标 相关概念 环境 启动zookeeper和kafka节点 命令集锦 查看kafka节点数量 查看所有消费者组 查看消费者组详情 创建主题 扩容分区 查看主题详情 查看所有主题 删除主题 发送消息 监听&消费消息 目标 熟悉kafka各个组件的功能。 通过命令的方式验证…

kafka生产者和消费者的具体交互以及核心参数详解

目录 目标 实战 生产者发送消息 消费者消费消息 把消费者组对应的主题内未消费完的数据导入到文件中 生产者核心参数 acks retries&&retry.backoff.ms buffer.memory&&batch.size&&linger.ms 消费者核心参数 enable.auto.commit&&a…

根据kafka官方API对线上问题进行优化

目录 目标 环境 kafka官方API kafka消息丢失的问题 分析 消息丢失发生的环节 生产者发送消息丢失的原因和解决思路 消费者消费消息丢失的原因和解决思路 解决生产者发送消息丢失的问题 解决消费者消费消息丢失的问题 kafka消息重复消费的问题 分析 消息重复的环节…

关于反向传播算法中几个公式的推导

** 参考自资料&#xff0c;[戳此处](http://deeplearning.stanford.edu/wiki/index.php/%E5%8F%8D%E5%90%91%E4%BC%A0%E5%AF%BC%E7%AE%97%E6%B3%95)** J(W,b;x,y)12∣∣hW,b(x)−y∣∣2J(W,b;x,y)\frac{1}{2}||h_{W,b}(x)-y||^2J(W,b;x,y)21​∣∣hW,b​(x)−y∣∣2 符号说明&…

图文并茂地带你了解kafka分区Rebalance机制

目录 目标 Consumer API版本 技术支持 分区重平衡及相关概念 什么时候可能发生分区重平衡 分区重平衡的意义 分区重平衡策略 range策略&#xff08;按范围顺序分配&#xff09; round-robin策略&#xff08;按轮询方式分配&#xff09; sticky策略&#xff08;粘性策…