Python 官方文档:入门教程 => 点击学习
目录部署xxl-jobSpringBoot配置Maven 配置application.yaml配置 XxlJobConfigXxlJobspringExecutor新建执行任务配置x
k8s 部署 xxl-job 参考文档:https://www.jb51.net/article/252770.htm
pom 文件添加依赖
<!--xxl-job依赖-->
<dependency>
<groupId>com.xuxueli</groupId>
<artifactId>xxl-job-core</artifactId>
<version>2.3.0</version>
</dependency>
添加参数
xxl:
job:
admin:
addresses: Http://192.168.140.1:8080/xxl-job-admin
executor:
appname: demo-feng-executor
ip:
port: 9997
logpath: /home/applogs/xxl-job/jobhandler
logretentiondays: -1
accessToken:
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;
@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
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;
}
}
这里聊一下 XxlJobSpringExecutor,不想多了解的可以跳过
afterSingletonsInstantiated 函数
public void afterSingletonsInstantiated() {
this.initJobHandlerMethodRepository(applicationContext);
GlueFactory.refreshInstance(1);
try {
super.start();
} catch (Exception var2) {
throw new RuntimeException(var2);
}
}
start函数
public void start() throws Exception {
XxlJobFileAppender.initLogPath(this.logPath);
this.initAdminBizList(this.adminAddresses, this.accessToken);
JobLogFileCleanThread.getInstance().start((long)this.logRetentionDays);
TriggerCallbackThread.getInstance().start();
this.initEmbedServer(this.address, this.ip, this.port, this.appname, this.accessToken);
}
@Slf4j
@Component
public class MyTask {
@XxlJob("fengDemoTask")
private void task() {
log.info("成功调用demo任务");
}
}
点击 “新增”
选择刚刚执行器,点击 “新增”
编辑任务状态
到此这篇关于SpringBoot部署xxl-job方法详细讲解的文章就介绍到这了,更多相关SpringBoot部署xxl-job内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: SpringBoot部署xxl-job方法详细讲解
本文链接: https://lsjlt.com/news/177172.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0