Java Code Examples for com.alibaba.nacos.api.naming.NamingService#deregisterInstance()
The following examples show how to use
com.alibaba.nacos.api.naming.NamingService#deregisterInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NacosSyncToNacosServiceImpl.java From nacos-sync with Apache License 2.0 | 6 votes |
@Override public boolean delete(TaskDO taskDO) { try { NamingService sourceNamingService = nacosServerHolder.get(taskDO.getSourceClusterId(), taskDO.getGroupName()); NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), taskDO.getGroupName()); sourceNamingService.unsubscribe(taskDO.getServiceName(), nacosListenerMap.get(taskDO.getTaskId())); // 删除目标集群中同步的实例列表 List<Instance> instances = destNamingService.getAllInstances(taskDO.getServiceName()); for (Instance instance : instances) { if (needDelete(instance.getMetadata(), taskDO)) { destNamingService.deregisterInstance(taskDO.getServiceName(), instance.getIp(), instance.getPort()); } } } catch (Exception e) { log.error("delete task from nacos to nacos was failed, taskId:{}", taskDO.getTaskId(), e); metricsManager.recordError(MetricsStatisticsType.DELETE_ERROR); return false; } return true; }
Example 2
Source File: ConsulSyncToNacosServiceImpl.java From nacos-sync with Apache License 2.0 | 6 votes |
@Override public boolean delete(TaskDO taskDO) { try { specialSyncEventBus.unsubscribe(taskDO); NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), null); List<Instance> allInstances = destNamingService.getAllInstances(taskDO.getServiceName()); for (Instance instance : allInstances) { if (needDelete(instance.getMetadata(), taskDO)) { destNamingService.deregisterInstance(taskDO.getServiceName(), instance.getIp(), instance.getPort()); } } } catch (Exception e) { log.error("delete task from consul to nacos was failed, taskId:{}", taskDO.getTaskId(), e); metricsManager.recordError(MetricsStatisticsType.DELETE_ERROR); return false; } return true; }
Example 3
Source File: ZookeeperSyncToNacosServiceImpl.java From nacos-sync with Apache License 2.0 | 6 votes |
private void processEvent(TaskDO taskDO, NamingService destNamingService, PathChildrenCacheEvent event, String path, Map<String, String> queryParam) throws NacosException { Map<String, String> ipAndPortParam = parseIpAndPortString(path); Instance instance = buildSyncInstance(queryParam, ipAndPortParam, taskDO); switch (event.getType()) { case CHILD_ADDED: case CHILD_UPDATED: destNamingService.registerInstance( getServiceNameFromCache(taskDO.getTaskId(), queryParam), instance); break; case CHILD_REMOVED: destNamingService.deregisterInstance( getServiceNameFromCache(taskDO.getTaskId(), queryParam), ipAndPortParam.get(INSTANCE_IP_KEY), Integer.parseInt(ipAndPortParam.get(INSTANCE_PORT_KEY))); nacosServiceNameMap.remove(taskDO.getTaskId()); break; default: break; } }
Example 4
Source File: ZookeeperSyncToNacosServiceImpl.java From nacos-sync with Apache License 2.0 | 6 votes |
@Override public boolean delete(TaskDO taskDO) { try { CloseableUtils.closeQuietly(pathChildrenCacheMap.get(taskDO.getTaskId())); NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), null); if (nacosServiceNameMap.containsKey(taskDO.getTaskId())) { List<Instance> allInstances = destNamingService.getAllInstances(nacosServiceNameMap.get(taskDO.getTaskId())); for (Instance instance : allInstances) { if (needDelete(instance.getMetadata(), taskDO)) { destNamingService.deregisterInstance(instance.getServiceName(), instance.getIp(), instance.getPort()); } nacosServiceNameMap.remove(taskDO.getTaskId()); } } } catch (Exception e) { log.error("delete task from zookeeper to nacos was failed, taskId:{}", taskDO.getTaskId(), e); metricsManager.recordError(MetricsStatisticsType.DELETE_ERROR); return false; } return true; }
Example 5
Source File: NacosServiceRegistry.java From spring-cloud-alibaba with Apache License 2.0 | 6 votes |
@Override public void deregister(Registration registration) { log.info("De-registering from Nacos Server now..."); if (StringUtils.isEmpty(registration.getServiceId())) { log.warn("No dom to de-register for nacos client..."); return; } NamingService namingService = namingService(); String serviceId = registration.getServiceId(); String group = nacosDiscoveryProperties.getGroup(); try { namingService.deregisterInstance(serviceId, group, registration.getHost(), registration.getPort(), nacosDiscoveryProperties.getClusterName()); } catch (Exception e) { log.error("ERR_NACOS_DEREGISTER, de-register failed...{},", registration.toString(), e); } log.info("De-registration finished."); }
Example 6
Source File: EurekaSyncToNacosServiceImpl.java From nacos-sync with Apache License 2.0 | 5 votes |
private void removeInvalidInstance(TaskDO taskDO, NamingService destNamingService, List<InstanceInfo> eurekaInstances, List<Instance> nacosInstances) throws NacosException { for (Instance instance : nacosInstances) { if (!isExistInEurekaInstance(eurekaInstances, instance) && needDelete(instance.getMetadata(), taskDO)) { log.info("Remove invalid service instance from Nacos, serviceName={}, Ip={}, port={}", instance.getServiceName(), instance.getIp(), instance.getPort()); destNamingService.deregisterInstance(taskDO.getServiceName(), instance.getIp(), instance.getPort()); } } }
Example 7
Source File: EurekaSyncToNacosServiceImpl.java From nacos-sync with Apache License 2.0 | 5 votes |
private void deleteAllInstance(TaskDO taskDO, NamingService destNamingService, List<Instance> allInstances) throws NacosException { for (Instance instance : allInstances) { if (needDelete(instance.getMetadata(), taskDO)) { destNamingService.deregisterInstance(taskDO.getServiceName(), instance); } } }
Example 8
Source File: ConsulSyncToNacosServiceImpl.java From nacos-sync with Apache License 2.0 | 5 votes |
private void cleanAllOldInstance(TaskDO taskDO, NamingService destNamingService, Set<String> instanceKeys) throws NacosException { List<Instance> allInstances = destNamingService.getAllInstances(taskDO.getServiceName()); for (Instance instance : allInstances) { if (needDelete(instance.getMetadata(), taskDO) && !instanceKeys.contains(composeInstanceKey(instance.getIp(), instance.getPort()))) { destNamingService.deregisterInstance(taskDO.getServiceName(), instance.getIp(), instance.getPort()); } } }