我正在尝试在 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/