分布式任务调度框架Elastic-Job的简单实用

2021-12-28 12:43:41 浏览数 (1)

Elastic-Job

代码语言:javascript复制
        <dependency>
            <groupId>com.dangdang</groupId>
            <artifactId>elastic-job-lite-core</artifactId>
            <version>2.1.5</version>
        </dependency>
代码语言:javascript复制
public class MessagePushJob implements SimpleJob {
    @Override
    public void execute(ShardingContext shardingContext) {
        System.out.println(shardingContext);
    }
}
代码语言:javascript复制
public class Startup {
    public static void main(String[] args) {
        new JobScheduler(createRegistryCenter(), createJobConfiguration()).init();
    }

    private static CoordinatorRegistryCenter createRegistryCenter() {
        CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(new ZookeeperConfiguration("localhost:2181", "elastic-job"));
        regCenter.init();
        return regCenter;
    }

    private static LiteJobConfiguration createJobConfiguration() {
        // 定义作业核心配置
        JobCoreConfiguration simpleCoreConfig = JobCoreConfiguration.newBuilder("messagePushJob", "5 * * * * ?", 3).build();
        // 定义SIMPLE类型配置
        SimpleJobConfiguration simpleJobConfig = new SimpleJobConfiguration(simpleCoreConfig, MessagePushJob.class.getCanonicalName());
        // 定义Lite作业根配置
        LiteJobConfiguration simpleJobRootConfig = LiteJobConfiguration.newBuilder(simpleJobConfig).build();
        return simpleJobRootConfig;
    }
}

elastic-job-lite-console(控制台)

代码语言:javascript复制
地址:https://github.com/elasticjob/elastic-job-lite/tree/dev/elastic-job-lite-console
代码语言:javascript复制
启动类:com.dangdang.ddframe.job.lite.console.ConsoleBootstrap

登录账号密码:

代码语言:javascript复制
root/root 、 guest/guest

其他:

zookeeper

v : 3.5.5

JDK:

v:1.8

0 人点赞