美文网首页
springboot3.x 整合 elasticjob

springboot3.x 整合 elasticjob

作者: wuyuan0127 | 来源:发表于2023-06-30 08:48 被阅读0次

1. 请先看如何安装 lite ui 地址: https://www.jianshu.com/p/a4b278661813

2. 引入最新版本 pom 坐标:

<!-- https://mvnrepository.com/artifact/org.apache.shardingsphere.elasticjob/elasticjob-lite-spring-boot-starter -->

<dependency>

    <groupId>org.apache.shardingsphere.elasticjob</groupId>

    <artifactId>elasticjob-lite-spring-boot-starter</artifactId>

    <version>3.0.3</version>

</dependency>

3.  安装 zookeeper  单机版本, 下载链接: https://zookeeper.apache.org/releases.html

我下班的 3.6.x版本:  https://www.apache.org/dyn/closer.lua/zookeeper/zookeeper-3.6.4/apache-zookeeper-3.6.4-bin.tar.gz

安装copy zoo.cfg  配置一个dataDir 就行。 点击 bin/zkServer.cmd 启动就行。

4.  编写一个 simpleJob

@Component

@Slf4j

public class SpringBootSimpleJobimplements SimpleJob {

    @Override

    public void execute(final ShardingContext shardingContext) {

            log.info("Item: {} | Time: {} | Thread: {} | {}",

                shardingContext.getShardingItem(), LocalDateTime.now(), Thread.currentThread().getId(), "SIMPLE");

    }

}

5. config application.yml

elasticjob:

    regCenter:

        serverLists: localhost:2181

        namespace: elasticjob-lite-springboot

    jobs:

        simpleJob:

        elasticJobClass:  org.example.liteflow.job.SpringBootSimpleJob

        cron: 0/5 * * * * ?

        shardingTotalCount: 3

        shardingItemParameters: 0=Beijing,1=Shanghai,2=Guangzhou

        override: true

6. 目前 elasticjob 不支持 springboot3.0 自动配置, 破坑配置

在 自己项目的 repsource 目录下 新建 :  META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports      文件

把自动配置类 copy进去这个文件

org.apache.shardingsphere.elasticjob.lite.spring.boot.job.ElasticJobLiteAutoConfiguration

like under : 

没有这个 文件夹,只support springboot2.x

7. start application

 进来 job

8. 运维管理平台操作

添加注册中心:

在作业操作就可以看到作业了:

完结撒花!!!!!!!!!

小技巧:让 gpt 生成 cron 表达式

相关文章

  • 【ElasticJob源码解析】任务调度器

    作业需要执行,必然需要一个调度器,去统筹作业执行的逻辑,这也是ElasticJob的核心内容;ElasticJob...

  • SpringBoot2 整合ElasticJob框架,定制化管理

    本文源码:GitHub·点这里 || GitEE·点这里 一、ElasticJob简介 1、定时任务 在前面的文...

  • elasticjob架构

    基于zookeeper、quzrtz的分布式任务调度(作业)框架实现的主要功能: 重写quartz基于数据库的分布...

  • ElasticJob源码学习

    1. spring命名空间 NamespaceHandlerSupport 2. ZookeeperRegistr...

  • ElasticJob Lite调研

    因现有系统的调度系统对作业的生命周期,执行轨迹与状态监控和报警,无统一的管理和资源规划;导致运维维护困难、调度与执...

  • ElasticJob选举实现

    1、为什么需要选举?ElasticJob中,所有的节点服务器都是对等的,他们在整个集群当中的地位都是相同的。为了避...

  • ElasticJob分片机制

    ElasticJob是一个弹性的分布式任务调度框架,这里的分布式就是采用分片的来进行任务调度和业务执行的解耦,分片...

  • SpringBoot-ElasticJob

    elasticjob的官方资料 概念 & 功能 依赖 作业开发 作业开发API:简单作业、数据流作业、脚本作业、H...

  • ElasticJob简单使用

    ElasticJob单点使用 任务类 主要的任务就是将未归档的数据整理到归档的表中,表结构一样执行类 这种情况下,...

  • elastic job源码分析 - 作业触发监听管理器

    作业触发监听管理器io.elasticjob.lite.internal.instance.TriggerList...

网友评论

      本文标题:springboot3.x 整合 elasticjob

      本文链接:https://www.haomeiwen.com/subject/rmkzydtx.html