ElasticJob 支持多种注册中心类型,用于协调分布式作业的调度和执行。
本章节介绍如何配置不同类型的注册中心。
| 注册中心类型 | 说明 |
|---|---|
| ZooKeeper | Apache ZooKeeper,分布式协调服务 |
| etcd | etcd3,分布式键值存储 |
ElasticJob 提供了以下配置注册中心的方式:
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 # 或 etcd
server-lists: host1:2181,host2:2181 # 或 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" />