##主要贡献者
**讨论QQ群:**430066234(不限于Elastic-Job,包括分布式,定时任务相关以及其他互联网技术交流)
elastic-job已经发布到中央仓库,可以在pom.xml文件中直接引入maven坐标。
<!-- 引入elastic-job核心模块 --> <dependency> <groupId>com.dangdang</groupId> <artifactId>elastic-job-core</artifactId> <version>1.0.1</version> </dependency> <!-- 使用springframework自定义命名空间时引入 --> <dependency> <groupId>com.dangdang</groupId> <artifactId>elastic-job-spring</artifactId> <version>1.0.1</version> </dependency>
public class MyElasticJob extends AbstractPerpetualElasticJob<Foo> { @Override protected List<Foo> fetchData(JobExecutionMultipleShardingContext context) { List<Foo> result = // get data from database by sharding items return result; } @Override protected boolean processData(JobExecutionMultipleShardingContext context, Foo data) { // process data return true; } }
<?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://www.dangdang.com/schema/ddframe/reg" xmlns:job="http://www.dangdang.com/schema/ddframe/job" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.dangdang.com/schema/ddframe/reg http://www.dangdang.com/schema/ddframe/reg/reg.xsd http://www.dangdang.com/schema/ddframe/job http://www.dangdang.com/schema/ddframe/job/job.xsd "> <!--配置作业注册中心 --> <reg:zookeeper id="regCenter" serverLists=" yourhost:2181" namespace="dd-job" baseSleepTimeMilliseconds="1000" maxSleepTimeMilliseconds="3000" maxRetries="3" /> <!-- 配置作业--> <job:bean id="oneOffElasticJob" class="xxx.MyElasticJob" regCenter="regCenter" cron="0/10 * * * * ?" shardingTotalCount="3" shardingItemParameters="0=A,1=B,2=C" /> </beans>