Introduce dependencies
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<version>2.3.0</version>
</dependency>
XxlJobConfig
package com.nbbsqcc.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;
/**
* @Description
* @Author HuangKun
* @Date 2022-12-13 17:13
*/
@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 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;
}
}
xxl-job application.yml configuration file
# xxljob
xxl:
job:
admin:
addresses: http://xxx:8088/xxl-job-admin/ #调度中心地址
accessToken: default_token
executor:
appname: xxljob-NBCC
ip:
port: 8190
address:
logpath: /data/applogs/xxl-job/jobhandler
logretentiondays: 30
Download the code of xxljob task scheduling center, deploy and run it
2022/12/23 Supplement
Docker deployment xxl-job
In different containers, when xxl-job calls the service at this time, it will report: xxl-rpc remoting error(connect timed out), for url
because the interface to which the service is called is not mapped in the docker container. In addition, the mutual access between containers will fail with the automatically registered ip, and the bridge ip of the Docker container should be used: 172.17.0.1.