zoukankan      html  css  js  c++  java
  • xxl-job 执行器调度

    源码:https://github.com/xuxueli/xxl-job

    按文档启动xxl-job-admin后,可以自己写执行器

    执行器:

    新建springboot服务 选中spring web、Mysql Driver、JDBC API、Mybatis Framework等依赖

    pom.xml添加

    <dependency>
        <groupId>com.xuxueli</groupId>
        <artifactId>xxl-job-core</artifactId>
        <version>2.1.0</version>
    </dependency>

    application.properties

    spring.datasource.url=jdbc:mysql://localhost:3306/xxl_job?Unicode=true&characterEncoding=UTF-8
    spring.datasource.username=root
    spring.datasource.password=7546857
    spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
    server.port=8082
    
    ### xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
    xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin
    ### xxl-job executor address
    xxl.job.executor.appname=xxl-test
    xxl.job.executor.ip=
    xxl.job.executor.port=30020
    ### xxl-job, access token
    xxl.job.accessToken=
    ### xxl-job log path
    xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler
    ### xxl-job log retention days
    xxl.job.executor.logretentiondays=-1

    接下来创建一个XxlJobConfig类,进行扫描JobHandler的位置。

    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 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.executor.appname}")
        private String appName;
    
        @Value("${xxl.job.executor.ip}")
        private String ip;
    
        @Value("${xxl.job.executor.port}")
        private int port;
    
        @Value("${xxl.job.accessToken}")
        private String accessToken;
    
        @Value("${xxl.job.executor.logpath}")
        private String logPath;
    
        @Value("${xxl.job.executor.logretentiondays}")
        private int logRetentionDays;
    
    
        @Bean(initMethod = "start", destroyMethod = "destroy")
        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;
        }
    }

    最后创建继承了IJobHandler的类,也就是JobHandler,例子如下:

    import com.xxl.job.core.biz.model.ReturnT;
    import com.xxl.job.core.handler.IJobHandler;
    import com.xxl.job.core.handler.annotation.JobHandler;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.stereotype.Component;
    
    
    @Component
    @JobHandler("test")
    public class TestJobHander extends IJobHandler {
        private Logger logger= LoggerFactory.getLogger(TestJobHander.class);
        @Override
        public ReturnT<String> execute(String s) throws Exception {
            System.out.println("11111111111111111111");
            logger.info("lalalala");
            return ReturnT.SUCCESS;
        }
    }

     

  • 相关阅读:
    SQL语句导入导出大全
    数据库连接大全
    数据库关键字过滤问题
    HttpHandler
    asp代码的一个do。。。wile循环代码
    vs .net 2005 的Global.asax 在哪添加
    asp.net项目ckeditor+ckfinder实现图片上传
    CKEditor+CKFinder的图片上传配置
    asp实现统计访问量的代码
    asp.net绘统计图
  • 原文地址:https://www.cnblogs.com/mytzq/p/14760193.html
Copyright © 2011-2022 走看看