gpt4 book ai didi

java - 如何使用 Curator.x.discovery 注册服务 ZooKeeper

转载 作者:行者123 更新时间:2023-12-02 11:47:41 30 4
gpt4 key购买 nike

我正在尝试在 int port 上注册一个简单的 REST 服务,到 ZooKeeper 服务器,地址为 localhost:2181。我也使用zooClient检查了路径ls/。有任何想法吗?

private static void registerInZookeeper(int port) throws Exception {
CuratorFramework curatorFramework = CuratorFrameworkFactory
.newClient("localhost:2181", new RetryForever(5));

curatorFramework.start();

ServiceInstance<Object> serviceInstance = ServiceInstance.builder()
.address("localhost")
.port(port)
.name("worker")
.uriSpec(new UriSpec("{scheme}://{address}:{port}"))
.build();

ServiceDiscoveryBuilder.builder(Object.class)
.basePath("myNode")
.client(curatorFramework)
.thisInstance(serviceInstance)
.build()
.start();

Optional.ofNullable(curatorFramework.checkExists().forPath("/zookeeper")).ifPresent(System.out::println);
Optional.ofNullable(curatorFramework.checkExists().forPath("/myNode")).ifPresent(System.out::println);
}

最佳答案

我一直从 Zoo 服务器接收在未知类型 15 的服务器上接收到的数据包,因为 compatibility issues

关于java - 如何使用 Curator.x.discovery 注册服务 ZooKeeper,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48091875/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com