一、zk安装参考
zookeeper之二:手把手教你安装zookeeper3.7.0(绝对实用) - 北漂程序员 - 博客园前面分享了zookeeper的基本知识,下面分享有关zookeeper安装的知识。 1、下载 zookeeper的官网是:https://zookeeper.apache.org/ 在官网上找到下载链https://www.cnblogs.com/teach/p/14852801.html二、vertx zookeeper集群
1、添加vertx-zookeeper依赖
<dependency><groupId>io.vertx</groupId><artifactId>vertx-zookeeper</artifactId><version>4.2.4</version>
</dependency>
Vert.x 集群管理器包含以下几个功能:
-
发现并管理集群中的节点
-
管理集群端的主题订阅清单(这样就可以轻松得知集群中的那些节点订阅了那些 EventBus 地址)
-
分布式 Map 支持
-
分布式锁
-
分布式计数器
Vert.x 集群器并不处理节点之间的通信,在 Vert.x 中节点中的通信是直接由 TCP 链接处理的。
2、使用ZookeeperClusterManager
zk配置方式:
a、 通过编程方式指定(代码实例如下)
b、在 classpath
中添加一个 zookeeper.json
文件
c、启动参数增加
-Dvertx.zookeeper.config=./config/my-zookeeper-conf.json
JsonObject zkConfig = new JsonObject();
zkConfig.put("zookeeperHosts", "x.x.x.x");//zk地址
zkConfig.put("rootPath", "io.vertx");
zkConfig.put("retry", new JsonObject().put("initialSleepTime", 3000).put("maxTimes", 3));ClusterManager mgr = new ZookeeperClusterManager(zkConfig);
VertxOptions options = new VertxOptions().setClusterManager(mgr);
Vertx.clusteredVertx(options, res -> {if (res.succeeded()) {Vertx vertx = res.result();EventBus eventBus = vertx.eventBus();System.out.println("We now have a clustered event bus: " + eventBus);} else {System.out.println("Failed: " + res.cause());}
});
参考vertx中文网站
https://vertx-china.github.io/docs/vertx-zookeeper/java/