use of org.apache.dubbo.registry.Registry in project incubator-dubbo-ops by apache.
the class ConfigCenter method getRegistry.
/*
* generate registry client
*/
@Bean("dubboRegistry")
@DependsOn("governanceConfiguration")
Registry getRegistry() {
Registry registry = null;
if (registryUrl == null) {
if (StringUtils.isBlank(registryAddress)) {
throw new ConfigurationException("Either config center or registry address is needed, please refer to https://github.com/apache/incubator-dubbo-admin/wiki/Dubbo-Admin-configuration");
}
registryUrl = formUrl(registryAddress, registryGroup, registryNameSpace, username, password);
}
RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension();
registry = registryFactory.getRegistry(registryUrl);
return registry;
}
use of org.apache.dubbo.registry.Registry in project dubbo by alibaba.
the class MulticastRegistryFactoryTest method shouldCreateRegistry.
@Test
public void shouldCreateRegistry() {
Registry registry = new MulticastRegistryFactory().createRegistry(URL.valueOf("multicast://239.255.255.255/"));
assertThat(registry, not(nullValue()));
assertThat(registry.isAvailable(), is(true));
}
use of org.apache.dubbo.registry.Registry in project dubbo by alibaba.
the class MultipleRegistry method isAvailable.
@Override
public boolean isAvailable() {
boolean available = serviceRegistries.isEmpty();
for (Registry serviceRegistry : serviceRegistries.values()) {
if (serviceRegistry.isAvailable()) {
available = true;
}
}
if (!available) {
return false;
}
available = referenceRegistries.isEmpty();
for (Registry referenceRegistry : referenceRegistries.values()) {
if (referenceRegistry.isAvailable()) {
available = true;
}
}
if (!available) {
return false;
}
return true;
}
use of org.apache.dubbo.registry.Registry in project dubbo by alibaba.
the class MultipleRegistry method unsubscribe.
@Override
public void unsubscribe(URL url, NotifyListener listener) {
MultipleNotifyListenerWrapper notifyListener = multipleNotifyListenerMap.remove(listener);
for (Registry registry : referenceRegistries.values()) {
SingleNotifyListener singleNotifyListener = notifyListener.registryMap.get(registry.getUrl());
registry.unsubscribe(url, singleNotifyListener);
}
if (notifyListener != null) {
super.unsubscribe(url, notifyListener);
notifyListener.destroy();
}
}
use of org.apache.dubbo.registry.Registry in project dubbo by alibaba.
the class MultipleRegistry2S2RTest method testSubscription.
@Test
public void testSubscription() throws InterruptedException {
URL serviceUrl = URL.valueOf("http2://multiple/" + SERVICE2_NAME + "?notify=false&methods=test1,test2&category=providers");
// URL serviceUrl2 = URL.valueOf("http2://multiple2/" + SERVICE_NAME + "?notify=false&methods=test1,test2&category=providers");
multipleRegistry.register(serviceUrl);
String path = "/dubbo/" + SERVICE2_NAME + "/providers";
List<String> providerList = zookeeperClient.getChildren(path);
Assertions.assertTrue(!providerList.isEmpty());
System.out.println(providerList.get(0));
Assertions.assertNotNull(MultipleRegistryTestUtil.getRedisHashContent(redisServerPort, path, serviceUrl.toFullString()));
final List<URL> list = new ArrayList<URL>();
multipleRegistry.subscribe(serviceUrl, new NotifyListener() {
@Override
public void notify(List<URL> urls) {
System.out.println("invoke notify: " + urls);
list.clear();
list.addAll(urls);
}
});
Thread.sleep(1500);
Assertions.assertEquals(2, list.size());
List<Registry> serviceRegistries = new ArrayList<Registry>(multipleRegistry.getServiceRegistries().values());
serviceRegistries.get(0).unregister(serviceUrl);
Thread.sleep(1500);
Assertions.assertEquals(1, list.size());
List<URL> urls = MultipleRegistryTestUtil.getProviderURLsFromNotifyURLS(list);
Assertions.assertEquals(1, list.size());
Assertions.assertTrue(!"empty".equals(list.get(0).getProtocol()));
serviceRegistries.get(1).unregister(serviceUrl);
Thread.sleep(1500);
Assertions.assertEquals(1, list.size());
urls = MultipleRegistryTestUtil.getProviderURLsFromNotifyURLS(list);
Assertions.assertEquals(1, list.size());
Assertions.assertEquals("empty", list.get(0).getProtocol());
}
Aggregations