elastic-job配置类
生活随笔
收集整理的這篇文章主要介紹了
elastic-job配置类
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
@Configuration
public class ElasticJobConfig {@AutowiredMyJob myJob;@AutowiredZookeeperRegistryCenter registryCenter;@Value("${myjob.count}")private int shardingCount;@Value("${myjob.cron}")private String cron;/*** 配置任務詳細信息* @param jobClass 任務執行類* @param cron 執行策略* @param shardingTotalCount 分片數量* @return*/private LiteJobConfiguration createJobConfiguration(final Class<? extends SimpleJob> jobClass,final String cron,final int shardingTotalCount){//創建JobCoreConfigurationBuilderJobCoreConfiguration.Builder JobCoreConfigurationBuilder = JobCoreConfiguration.newBuilder(jobClass.getName(), cron, shardingTotalCount);JobCoreConfiguration jobCoreConfiguration = JobCoreConfigurationBuilder.build();//創建SimpleJobConfigurationSimpleJobConfiguration simpleJobConfiguration = new SimpleJobConfiguration(jobCoreConfiguration, jobClass.getCanonicalName());//創建LiteJobConfigurationLiteJobConfiguration liteJobConfiguration = LiteJobConfiguration.newBuilder(simpleJobConfiguration) .jobShardingStrategyClass("com.dangdang.ddframe.job.lite.api.strategy.impl.AverageAllocationJobShardingStrategy").overwrite(true).build();return liteJobConfiguration;}@Bean(initMethod = "init")public SpringJobScheduler initSimpleElasticJob() {//創建SpringJobSchedulerSpringJobScheduler springJobScheduler = new SpringJobScheduler(myJob, registryCenter,createJobConfiguration(myJob.getClass(), cron, shardingCount));return springJobScheduler;}
}
總結
以上是生活随笔為你收集整理的elastic-job配置类的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: zookeeper注册中心
- 下一篇: Saas详解