Elastic-Job is a distributed scheduled job solution. Elastic-Job is composited from 2 independent sub projects: Elastic-Job-Lite and Elastic-Job-Cloud.
Elastic-Job-Lite is a centre-less solution, use lightweight jar to coordinate distributed jobs.
Elastic-Job-Lite and Elastic-Job-Cloud provide unified API. Developers only need code one time, then decide to deploy Lite or Cloud as you want.
- Distributed schedule job coordinate
- Elastic scale in and scale out supported
- Failover
- Misfired jobs refire
- Sharding consistently, same sharding item for a job only one running instance
- Self diagnose and recover when distribute environment unstable
- Parallel scheduling supported
- Job lifecycle operation
- Lavish job types
- Spring integrated and namespace supported
- Web console
<!-- import elastic-job lite core -->
<dependency>
<groupId>org.apache.shardingsphere.elasticjob</groupId>
<artifactId>elastic-job-lite-core</artifactId>
<version>${lasted.release.version}</version>
</dependency>
<!-- import other module if need -->
<dependency>
<groupId>org.apache.shardingsphere.elasticjob</groupId>
<artifactId>elastic-job-lite-spring</artifactId>
<version>${lasted.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: ...
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:reg="http://elasticjob.shardingsphere.apache.org/schema/reg"
xmlns:job="http://elasticjob.shardingsphere.apache.org/schema/job"
xmlns:monitor="http://elasticjob.shardingsphere.apache.org/schema/monitor"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://elasticjob.shardingsphere.apache.org/schema/reg
http://elasticjob.shardingsphere.apache.org/schema/reg/reg.xsd
http://elasticjob.shardingsphere.apache.org/schema/job
http://elasticjob.shardingsphere.apache.org/schema/job/job.xsd
http://elasticjob.shardingsphere.apache.org/schema/monitor
http://elasticjob.shardingsphere.apache.org/schema/monitor/monitor.xsd
">
<!--configure registry center -->
<reg:zookeeper id="regCenter" server-lists="yourhost:2181" namespace="elastic-job" base-sleep-time-milliseconds="1000" max-sleep-time-milliseconds="3000" max-retries="3" />
<!--configure monitor -->
<monitor:embed id="monitor1" registry-center-ref="regCenter" monitor-port="9999"/>
<!--configure job class -->
<bean id="simpleJob" class="xxx.MyElasticJob" />
<!--configure job -->
<job:simple id="oneOffElasticJob" job-ref="simpleJob" registry-center-ref="regCenter" cron="0/10 * * * * ?" sharding-total-count="3" sharding-item-parameters="0=A,1=B,2=C" />
</beans>