概述
docker官网搜索镜像地址:https://hub.docker.com/r/xuxueli/xxl-job-admin
-
下载镜像
docker pull xuxueli/xxl-job-admin:2.2.0
-
使用该镜像启动容器
docker run -e PARAMS="--spring.datasource.url=jdbc:mysql://10.64.160.59:3306/xxl_job?useUnicode=true&characterEncoding=UTF-8 --spring.datasource.password=123456" -p 8181:8080 -v /usr/local/xxl-job/log:/data/applogs --name xxl-job-admin -d xuxueli/xxl-job-admin:2.2.0
注意一些参数如邮箱可以省略
docker run -e PARAMS="--spring.datasource.url=jdbc:mysql://数据库地址:3306/xxl-job?Unicode=true&characterEncoding=UTF-8 --spring.datasource.password=数据库密码 --spring.mail.host=smtp.163.com --spring.mail.username=邮箱名 --spring.mail.password=邮箱密码 --xxl.job.login.password=登录密码" -p 8080:8080 -v /tmp:/data/applogs --name xxl-job-admin --privileged=true -d xuxueli/xxl-job-admin:2.2.0
-
进入xxl-job-admin
http://10.64.160.59:8181/xxl-job-admin 初始用户名admin 密码123456
-
Spingboot实现定时器调度
1、application.properties文件增加以下
### xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
xxl.job.admin.addresses = http://10.64.160.59:8181/xxl-job-admin
### xxl-job, access token
xxl.job.accessToken =
### xxl-job executor appname
xxl.job.executor.appname = integrated-job-executor
### xxl-job executor registry-address: default use address to registry , otherwise use ip:port if address is null
xxl.job.executor.address =
### xxl-job executor server-info
xxl.job.executor.ip = 10.64.9.43
#xxl.job.executor.ip = 172.17.0.1
xxl.job.executor.port = 9999
### xxl-job executor log-pathf
xxl.job.executor.logpath = /usr/local/xxl-job/jobhandler
### xxl-job executor log-retention-days
xxl.job.executor.logretentiondays = 30
2、增加xxl-job配置类
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 ligansi
* @since 2020-09-22
*/
@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;
}
/**
* 针对多网卡、容器内部署等情况,可借助 "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();
*/
}
3、增加任务调度类
import com.mywind.integrated.servicemy.config.XxlJobConfig;
import com.mywind.integrated.servicemy.controller.*;
import com.mywind.integrated.servicemy.utils.LogsUtils;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
*
* SF文件同步任务调度
*
* @author ligansi
* @since 2020-11-12
*/
@Component
public class SyncSfJobHandler {
private Logger logger = LoggerFactory.getLogger(XxlJobConfig.class);
/**
* 测试定时器环境
* @param s
* @return
* @throws Exception
*/
@XxlJob("mywindTestJobHandler")
public ReturnT<String> mywindTestJobHandler(String s) throws Exception {
logger.info(">>>>>>>>>>> xxl-job test.");
return new ReturnT(ReturnT.SUCCESS_CODE,"测试成功");
}
}
4、进入xxl-job admin增加执行器与任务
最后就是测试调用了,有问题请联系QQ:121214756
最后
以上就是可爱台灯为你收集整理的Docker部署xxl-job-admin以及Spingboot实现定时器调度的全部内容,希望文章能够帮你解决Docker部署xxl-job-admin以及Spingboot实现定时器调度所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复