ConsulRegistry extends Registry { @Override public void register(ProviderConfig config) { String appName = config.getAppName(); if (!registryConfig.isRegister()) { if (LOGGER.isInfoEnabled(appName)) { LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE)); } return; } if (!config.isRegister()) { return; } try { List<NewService> services = buildNewServices(config); if (CommonUtils.isNotEmpty(services)) { if (LOGGER.isInfoEnabled(appName)) { LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_START, config.getInterfaceId())); } for (NewService service : services) { registerConsulService(service); if (LOGGER.isInfoEnabled(appName)) { LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB, config.getInterfaceId())); } } if (LOGGER.isInfoEnabled(appName)) { LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_OVER, config.getInterfaceId())); } } }catch (SofaRpcRuntimeException e){ throw e; } catch (Exception e) { throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_REG_PROVIDER, "consulRegistry", config.buildKey()), e); } if (EventBus.isEnable(ProviderPubEvent.class)) { ProviderPubEvent event = new ProviderPubEvent(config); EventBus.post(event); } } protected  ConsulRegistry(RegistryConfig registryConfig); @Override void init(); @Override void destroy(); @Override void destroy(DestroyHook hook); @Override boolean start(); @Override void register(ProviderConfig config); @Override void unRegister(ProviderConfig config); @Override void batchUnRegister(List<ProviderConfig> configs); @Override List<ProviderGroup> subscribe(ConsumerConfig config); @Override void unSubscribe(ConsumerConfig config); @Override void batchUnSubscribe(List<ConsumerConfig> configs); static final String EXT_NAME; }
@Test public void testRegister() { ProviderConfig<?> providerConfig = providerConfig("consul-test-1", 12200, 12201, 12202); registry.register(providerConfig); ConsulClient consulClient = new ConsulClient("localhost:" + consul.getHttpPort()); HealthServicesRequest request = HealthServicesRequest.newBuilder().setPassing(true).build(); assertUntil(() -> { Response<List<HealthService>> healthServices = consulClient.getHealthServices(INTERFACE_ID, request); Assert.assertEquals(3, healthServices.getValue().size()); }, 10, TimeUnit.SECONDS); registry.unRegister(providerConfig); assertUntil(() -> { Response<List<HealthService>> healthServices = consulClient.getHealthServices(INTERFACE_ID, request); Assert.assertEquals(0, healthServices.getValue().size()); }, 10, TimeUnit.SECONDS); }