ElasticJob supports multiple types of registry centers for coordinating the scheduling and execution of distributed jobs.
This section describes how to configure different types of registry centers.
| Registry Center Type | Description |
|---|---|
| ZooKeeper | Apache ZooKeeper, distributed coordination service |
| etcd | etcd3, distributed key-value store |
ElasticJob provides the following methods to configure registry centers:
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
public class ZookeeperExample {
public static void main(String[] args) {
// ZooKeeper
ZookeeperConfiguration zkConfig = new ZookeeperConfiguration("host1:2181,host2:2181", "elasticjob");
CoordinatorRegistryCenter registryCenter = new ZookeeperRegistryCenter(zkConfig);
registryCenter.init();
}
}
import org.apache.shardingsphere.elasticjob.reg.etcd.EtcdConfiguration;
import org.apache.shardingsphere.elasticjob.reg.etcd.EtcdRegistryCenter;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
public class EtcdExample {
public static void main(String[] args) {
// etcd
EtcdConfiguration etcdConfig = new EtcdConfiguration("http://host1:2379,http://host2:2379", "elasticjob");
CoordinatorRegistryCenter registryCenter = new EtcdRegistryCenter(etcdConfig);
registryCenter.init();
}
}
elasticjob:
reg-center:
type: zookeeper # or etcd
server-lists: host1:2181,host2:2181 # or http://host1:2379,http://host2:2379
namespace: elasticjob
<!-- ZooKeeper -->
<elasticjob:zookeeper id="regCenter" server-lists="host1:2181,host2:2181" namespace="elasticjob" />
<!-- etcd -->
<elasticjob:etcd id="regCenter" server-lists="http://host1:2379,http://host2:2379" namespace="elasticjob" />