From c0c64a487712e3b41e7e4b8a5a135991f126d69d Mon Sep 17 00:00:00 2001 From: jiangyuan <469391363@qq.com> Date: Fri, 12 Jul 2024 05:53:54 +0800 Subject: [PATCH] setup cluster for ServiceDiscoveryDemo (#2812) setup cluster for ServiceDiscoveryDemo --- .../helix/servicediscovery/ServiceDiscoveryDemo.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/recipes/service-discovery/src/main/java/org/apache/helix/servicediscovery/ServiceDiscoveryDemo.java b/recipes/service-discovery/src/main/java/org/apache/helix/servicediscovery/ServiceDiscoveryDemo.java index ddf3936580..c34ead9da4 100644 --- a/recipes/service-discovery/src/main/java/org/apache/helix/servicediscovery/ServiceDiscoveryDemo.java +++ b/recipes/service-discovery/src/main/java/org/apache/helix/servicediscovery/ServiceDiscoveryDemo.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.List; +import org.apache.helix.manager.zk.ZKHelixAdmin; import org.apache.helix.servicediscovery.ServiceDiscovery.Mode; public class ServiceDiscoveryDemo { @@ -34,6 +35,11 @@ public static void main(String[] args) throws Exception { String serviceName = "myServiceName"; int numServices = 5; + ZKHelixAdmin admin = new ZKHelixAdmin(zkAddress); + // create cluster + System.out.println("Creating cluster: " + clusterName); + admin.addCluster(clusterName, true); + // registration + zk watch demo(clusterName, zkAddress, serviceName, numServices, Mode.WATCH); // registration + periodic poll @@ -41,6 +47,7 @@ public static void main(String[] args) throws Exception { // only registration + ondemand demo(clusterName, zkAddress, serviceName, numServices, Mode.NONE); + admin.close(); } private static void demo(String clusterName, String zkAddress, String serviceName,