init
This commit is contained in:
		
							
								
								
									
										3
									
								
								sl-express-xxl-job/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								sl-express-xxl-job/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
.idea
 | 
			
		||||
target/
 | 
			
		||||
*.iml
 | 
			
		||||
							
								
								
									
										33
									
								
								sl-express-xxl-job/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								sl-express-xxl-job/pom.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,33 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
 | 
			
		||||
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 | 
			
		||||
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 | 
			
		||||
    <modelVersion>4.0.0</modelVersion>
 | 
			
		||||
 | 
			
		||||
    <parent>
 | 
			
		||||
        <groupId>com.sl-express</groupId>
 | 
			
		||||
        <artifactId>sl-express-parent</artifactId>
 | 
			
		||||
        <version>1.3</version>
 | 
			
		||||
    </parent>
 | 
			
		||||
 | 
			
		||||
    <groupId>com.sl-express.xxl-job</groupId>
 | 
			
		||||
    <artifactId>sl-express-xxl-job</artifactId>
 | 
			
		||||
    <version>1.0-SNAPSHOT</version>
 | 
			
		||||
 | 
			
		||||
    <properties>
 | 
			
		||||
        <maven.compiler.source>11</maven.compiler.source>
 | 
			
		||||
        <maven.compiler.target>11</maven.compiler.target>
 | 
			
		||||
    </properties>
 | 
			
		||||
 | 
			
		||||
    <dependencies>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.springframework.boot</groupId>
 | 
			
		||||
            <artifactId>spring-boot-starter-web</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.xuxueli</groupId>
 | 
			
		||||
            <artifactId>xxl-job-core</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
    </dependencies>
 | 
			
		||||
 | 
			
		||||
</project>
 | 
			
		||||
@@ -0,0 +1,13 @@
 | 
			
		||||
package com.sl;
 | 
			
		||||
 | 
			
		||||
import org.springframework.boot.SpringApplication;
 | 
			
		||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
 | 
			
		||||
 | 
			
		||||
@SpringBootApplication
 | 
			
		||||
public class XxlJobApplication {
 | 
			
		||||
 | 
			
		||||
    public static void main(String[] args) {
 | 
			
		||||
        SpringApplication.run(XxlJobApplication.class, args);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,58 @@
 | 
			
		||||
package com.sl.xxljob.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 config
 | 
			
		||||
 */
 | 
			
		||||
@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:0}")
 | 
			
		||||
    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 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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,54 @@
 | 
			
		||||
package com.sl.xxljob.job;
 | 
			
		||||
 | 
			
		||||
import cn.hutool.core.util.NumberUtil;
 | 
			
		||||
import cn.hutool.core.util.RandomUtil;
 | 
			
		||||
import com.xxl.job.core.context.XxlJobHelper;
 | 
			
		||||
import com.xxl.job.core.handler.annotation.XxlJob;
 | 
			
		||||
import org.springframework.stereotype.Component;
 | 
			
		||||
 | 
			
		||||
import java.time.LocalDateTime;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 任务处理器
 | 
			
		||||
 */
 | 
			
		||||
@Component
 | 
			
		||||
public class JobHandler {
 | 
			
		||||
 | 
			
		||||
    private List<Integer> dataList = Arrays.asList(1, 2, 3, 4, 5);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 普通任务
 | 
			
		||||
     */
 | 
			
		||||
    @XxlJob("firstJob")
 | 
			
		||||
    public void firstJob() throws Exception {
 | 
			
		||||
        System.out.println("firstJob执行了.... " + LocalDateTime.now());
 | 
			
		||||
        for (Integer data : dataList) {
 | 
			
		||||
            XxlJobHelper.log("data= {}", data);
 | 
			
		||||
            Thread.sleep(RandomUtil.randomInt(100, 500));
 | 
			
		||||
        }
 | 
			
		||||
        System.out.println("firstJob执行结束了.... " + LocalDateTime.now());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 分片式任务
 | 
			
		||||
     */
 | 
			
		||||
    @XxlJob("shardingJob")
 | 
			
		||||
    public void shardingJob() throws Exception {
 | 
			
		||||
        // 分片参数
 | 
			
		||||
        // 分片节点总数
 | 
			
		||||
        int shardTotal = XxlJobHelper.getShardTotal();
 | 
			
		||||
        // 当前节点下标,从0开始
 | 
			
		||||
        int shardIndex = XxlJobHelper.getShardIndex();
 | 
			
		||||
 | 
			
		||||
        System.out.println("shardingJob执行了.... " + LocalDateTime.now());
 | 
			
		||||
        for (Integer data : dataList) {
 | 
			
		||||
            if (data % shardTotal == shardIndex) {
 | 
			
		||||
                XxlJobHelper.log("data= {}", data);
 | 
			
		||||
                Thread.sleep(RandomUtil.randomInt(100, 500));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        System.out.println("shardingJob执行结束了.... " + LocalDateTime.now());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										18
									
								
								sl-express-xxl-job/src/main/resources/bootstrap.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								sl-express-xxl-job/src/main/resources/bootstrap.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
application:
 | 
			
		||||
  version: v1.0
 | 
			
		||||
spring:
 | 
			
		||||
  application:
 | 
			
		||||
    name: sl-express-xxl-job
 | 
			
		||||
server:
 | 
			
		||||
  port: 9901
 | 
			
		||||
xxl:
 | 
			
		||||
  job:
 | 
			
		||||
    admin:
 | 
			
		||||
      addresses: http://192.168.150.101:28080/xxl-job-admin
 | 
			
		||||
    executor:
 | 
			
		||||
      ip: 192.168.150.1
 | 
			
		||||
      appname: ${spring.application.name}
 | 
			
		||||
      #执行器运行日志文件存储磁盘路径
 | 
			
		||||
      logpath: /data/applogs/xxl-job/jobhandler
 | 
			
		||||
      #执行器日志文件保存天数
 | 
			
		||||
      logretentiondays: 30
 | 
			
		||||
		Reference in New Issue
	
	Block a user