快速入门
引入maven依赖
<!-- 引入elastic-job-cloud执行器模块 -->
<dependency>
<groupId>io.elasticjob</groupId>
<artifactId>elastic-job-cloud-executor</artifactId>
<version>${latest.release.version}</version>
</dependency>
作业开发
public class MyElasticJob implements SimpleJob {
@Override
public void execute(ShardingContext context) {
switch (context.getShardingItem()) {
case 0:
// do something by sharding item 0
break;
case 1:
// do something by sharding item 1
break;
case 2:
// do something by sharding item 2
break;
// case n: ...
}
}
}
Java启动方式
需定义Main
方法并调用JobBootstrap.execute()
,例子如下:
public class JobDemo {
public static void main(final String[] args) {
JobBootstrap.execute();
}
}
打包作业
tar-cvf yourJobs.tar.gz yourJobs
发布APP
curl -l -H "Content-type: application/json" -X POST -d '{"appName":"foo_app","appURL":"http://app_host:8080/yourJobs.tar.gz","cpuCount":0.1,"memoryMB":64.0,"bootstrapScript":"bin/start.sh","appCacheEnable":true,"eventTraceSamplingCount":0}' http://elastic_job_cloud_host:8899/api/app
发布作业
curl -l -H "Content-type: application/json" -X POST -d '{"jobName":"foo_job","appName":"foo_app","jobClass":"yourJobClass","jobType":"SIMPLE","jobExecutionType":"TRANSIENT","cron":"0/5 * * * * ?","shardingTotalCount":3,"cpuCount":0.1,"memoryMB":64.0}' http://elastic_job_cloud_host:8899/api/job/register
详细的开发方式请参考开发指南
版权声明:「DDKK.COM 弟弟快看,程序员编程资料站」本站文章,版权归原作者所有
来源:Elastic-Job 当当前内容版权归 ElasticJob 或其关联方所有