@Test public void testConsulSyncToNacos() throws Exception { TaskDO taskDO = mock(TaskDO.class); mockSync(taskDO); Assert.assertTrue(consulSyncToNacosService.sync(taskDO)); }
@Override public boolean sync(TaskDO taskDO) { try { ConsulClient consulClient = consulServerHolder.get(taskDO.getSourceClusterId(), null); NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), null); Response<List<HealthService>> response = consulClient.getHealthServices(taskDO.getServiceName(), true, QueryParams.DEFAULT); List<HealthService> healthServiceList = response.getValue(); Set<String> instanceKeys = new HashSet<>(); overrideAllInstance(taskDO, destNamingService, healthServiceList, instanceKeys); cleanAllOldInstance(taskDO, destNamingService, instanceKeys); specialSyncEventBus.subscribe(taskDO, this::sync); } catch (Exception e) { log.error("Sync task from consul to nacos was failed, taskId:{}", taskDO.getTaskId(), e); metricsManager.recordError(MetricsStatisticsType.SYNC_ERROR); return false; } return true; }
ConsulSyncToNacosServiceImpl implements SyncService { @Override public boolean sync(TaskDO taskDO) { try { ConsulClient consulClient = consulServerHolder.get(taskDO.getSourceClusterId(), null); NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), null); Response<List<HealthService>> response = consulClient.getHealthServices(taskDO.getServiceName(), true, QueryParams.DEFAULT); List<HealthService> healthServiceList = response.getValue(); Set<String> instanceKeys = new HashSet<>(); overrideAllInstance(taskDO, destNamingService, healthServiceList, instanceKeys); cleanAllOldInstance(taskDO, destNamingService, instanceKeys); specialSyncEventBus.subscribe(taskDO, this::sync); } catch (Exception e) { log.error("Sync task from consul to nacos was failed, taskId:{}", taskDO.getTaskId(), e); metricsManager.recordError(MetricsStatisticsType.SYNC_ERROR); return false; } return true; } }
ConsulSyncToNacosServiceImpl implements SyncService { @Override public boolean sync(TaskDO taskDO) { try { ConsulClient consulClient = consulServerHolder.get(taskDO.getSourceClusterId(), null); NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), null); Response<List<HealthService>> response = consulClient.getHealthServices(taskDO.getServiceName(), true, QueryParams.DEFAULT); List<HealthService> healthServiceList = response.getValue(); Set<String> instanceKeys = new HashSet<>(); overrideAllInstance(taskDO, destNamingService, healthServiceList, instanceKeys); cleanAllOldInstance(taskDO, destNamingService, instanceKeys); specialSyncEventBus.subscribe(taskDO, this::sync); } catch (Exception e) { log.error("Sync task from consul to nacos was failed, taskId:{}", taskDO.getTaskId(), e); metricsManager.recordError(MetricsStatisticsType.SYNC_ERROR); return false; } return true; } @Autowired  ConsulSyncToNacosServiceImpl(ConsulServerHolder consulServerHolder,
        SkyWalkerCacheServices skyWalkerCacheServices, NacosServerHolder nacosServerHolder,
        SpecialSyncEventBus specialSyncEventBus); }
ConsulSyncToNacosServiceImpl implements SyncService { @Override public boolean sync(TaskDO taskDO) { try { ConsulClient consulClient = consulServerHolder.get(taskDO.getSourceClusterId(), null); NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), null); Response<List<HealthService>> response = consulClient.getHealthServices(taskDO.getServiceName(), true, QueryParams.DEFAULT); List<HealthService> healthServiceList = response.getValue(); Set<String> instanceKeys = new HashSet<>(); overrideAllInstance(taskDO, destNamingService, healthServiceList, instanceKeys); cleanAllOldInstance(taskDO, destNamingService, instanceKeys); specialSyncEventBus.subscribe(taskDO, this::sync); } catch (Exception e) { log.error("Sync task from consul to nacos was failed, taskId:{}", taskDO.getTaskId(), e); metricsManager.recordError(MetricsStatisticsType.SYNC_ERROR); return false; } return true; } @Autowired  ConsulSyncToNacosServiceImpl(ConsulServerHolder consulServerHolder,
        SkyWalkerCacheServices skyWalkerCacheServices, NacosServerHolder nacosServerHolder,
        SpecialSyncEventBus specialSyncEventBus); @Override boolean delete(TaskDO taskDO); @Override boolean sync(TaskDO taskDO); }
ConsulSyncToNacosServiceImpl implements SyncService { @Override public boolean sync(TaskDO taskDO) { try { ConsulClient consulClient = consulServerHolder.get(taskDO.getSourceClusterId(), null); NamingService destNamingService = nacosServerHolder.get(taskDO.getDestClusterId(), null); Response<List<HealthService>> response = consulClient.getHealthServices(taskDO.getServiceName(), true, QueryParams.DEFAULT); List<HealthService> healthServiceList = response.getValue(); Set<String> instanceKeys = new HashSet<>(); overrideAllInstance(taskDO, destNamingService, healthServiceList, instanceKeys); cleanAllOldInstance(taskDO, destNamingService, instanceKeys); specialSyncEventBus.subscribe(taskDO, this::sync); } catch (Exception e) { log.error("Sync task from consul to nacos was failed, taskId:{}", taskDO.getTaskId(), e); metricsManager.recordError(MetricsStatisticsType.SYNC_ERROR); return false; } return true; } @Autowired  ConsulSyncToNacosServiceImpl(ConsulServerHolder consulServerHolder,
        SkyWalkerCacheServices skyWalkerCacheServices, NacosServerHolder nacosServerHolder,
        SpecialSyncEventBus specialSyncEventBus); @Override boolean delete(TaskDO taskDO); @Override boolean sync(TaskDO taskDO);  }