diff --git a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/boot/RuntimeInstance.java b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/boot/RuntimeInstance.java index 5e3c3060f2..dc37db1da2 100644 --- a/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/boot/RuntimeInstance.java +++ b/eventmesh-runtime-v2/src/main/java/org/apache/eventmesh/runtime/boot/RuntimeInstance.java @@ -1,7 +1,9 @@ package org.apache.eventmesh.runtime.boot; import lombok.extern.slf4j.Slf4j; + import org.apache.commons.lang3.StringUtils; + import org.apache.eventmesh.registry.QueryInstances; import org.apache.eventmesh.registry.RegisterServerInfo; import org.apache.eventmesh.registry.RegistryFactory; @@ -26,7 +28,7 @@ public class RuntimeInstance { private Map adminServerInfoMap = new HashMap<>(); -// private final RegistryService registryService; + private final RegistryService registryService; private Runtime runtime; @@ -38,20 +40,20 @@ public class RuntimeInstance { public RuntimeInstance(RuntimeInstanceConfig runtimeInstanceConfig) { this.runtimeInstanceConfig = runtimeInstanceConfig; -// this.registryService = RegistryFactory.getInstance(runtimeInstanceConfig.getRegistryPluginType()); + this.registryService = RegistryFactory.getInstance(runtimeInstanceConfig.getRegistryPluginType()); } public void init() throws Exception { -// registryService.init(); + registryService.init(); QueryInstances queryInstances = new QueryInstances(); queryInstances.setServiceName(runtimeInstanceConfig.getAdminServiceName()); queryInstances.setHealth(true); -// List adminServerRegisterInfoList = registryService.selectInstances(queryInstances); -// if (!adminServerRegisterInfoList.isEmpty()) { -// adminServerAddr = getRandomAdminServerAddr(adminServerRegisterInfoList); -// } else { -// throw new RuntimeException("admin server address is empty, please check"); -// } + List adminServerRegisterInfoList = registryService.selectInstances(queryInstances); + if (!adminServerRegisterInfoList.isEmpty()) { + adminServerAddr = getRandomAdminServerAddr(adminServerRegisterInfoList); + } else { + throw new RuntimeException("admin server address is empty, please check"); + } runtimeInstanceConfig.setAdminServerAddr(adminServerAddr); runtimeFactory = initRuntimeFactory(runtimeInstanceConfig); runtime = runtimeFactory.createRuntime(runtimeInstanceConfig); @@ -61,19 +63,19 @@ public void init() throws Exception { public void start() throws Exception { if (!StringUtils.isBlank(adminServerAddr)) { -// registryService.subscribe((event) -> { -// log.info("runtime receive registry event: {}", event); -// List registerServerInfoList = event.getInstances(); -// Map registerServerInfoMap = new HashMap<>(); -// for (RegisterServerInfo registerServerInfo : registerServerInfoList) { -// registerServerInfoMap.put(registerServerInfo.getAddress(), registerServerInfo); -// } -// if (!registerServerInfoMap.isEmpty()) { -// adminServerInfoMap = registerServerInfoMap; -// updateAdminServerAddr(); -// } -// -// }, runtimeInstanceConfig.getAdminServiceName()); + registryService.subscribe((event) -> { + log.info("runtime receive registry event: {}", event); + List registerServerInfoList = event.getInstances(); + Map registerServerInfoMap = new HashMap<>(); + for (RegisterServerInfo registerServerInfo : registerServerInfoList) { + registerServerInfoMap.put(registerServerInfo.getAddress(), registerServerInfo); + } + if (!registerServerInfoMap.isEmpty()) { + adminServerInfoMap = registerServerInfoMap; + updateAdminServerAddr(); + } + + }, runtimeInstanceConfig.getAdminServiceName()); runtime.start(); isStarted = true; } else {