<!-- 引入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: ...
}
}
}
需定义Main
方法并调用JobBootstrap.execute()
,例子如下:
public class JobDemo {
public static void main(final String[] args) {
JobBootstrap.execute();
}
}
tar -cvf yourJobs.tar.gz yourJobs
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
详细的开发方式请参考开发指南