Search in sources :

Example 1 with Registry

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;
}
Also used : RegistryFactory(org.apache.dubbo.registry.RegistryFactory) ConfigurationException(org.apache.dubbo.admin.common.exception.ConfigurationException) Registry(org.apache.dubbo.registry.Registry) DependsOn(org.springframework.context.annotation.DependsOn) Bean(org.springframework.context.annotation.Bean)

Example 2 with 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));
}
Also used : Registry(org.apache.dubbo.registry.Registry) Test(org.junit.jupiter.api.Test)

Example 3 with Registry

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;
}
Also used : AbstractRegistry(org.apache.dubbo.registry.support.AbstractRegistry) Registry(org.apache.dubbo.registry.Registry)

Example 4 with Registry

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();
    }
}
Also used : AbstractRegistry(org.apache.dubbo.registry.support.AbstractRegistry) Registry(org.apache.dubbo.registry.Registry)

Example 5 with Registry

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());
}
Also used : ArrayList(java.util.ArrayList) ZookeeperRegistry(org.apache.dubbo.registry.zookeeper.ZookeeperRegistry) RedisRegistry(org.apache.dubbo.registry.redis.RedisRegistry) Registry(org.apache.dubbo.registry.Registry) URL(org.apache.dubbo.common.URL) NotifyListener(org.apache.dubbo.registry.NotifyListener) Test(org.junit.jupiter.api.Test)

Aggregations

Registry (org.apache.dubbo.registry.Registry)26 Test (org.junit.jupiter.api.Test)9 AbstractRegistry (org.apache.dubbo.registry.support.AbstractRegistry)8 URL (org.apache.dubbo.common.URL)7 ArrayList (java.util.ArrayList)3 Status (org.apache.dubbo.common.status.Status)3 ProviderModel (org.apache.dubbo.rpc.model.ProviderModel)3 RegistryStatusChecker (org.apache.dubbo.registry.status.RegistryStatusChecker)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ConfigurationException (org.apache.dubbo.admin.common.exception.ConfigurationException)1 QOS_HOST (org.apache.dubbo.common.constants.QosConstants.QOS_HOST)1 QOS_PORT (org.apache.dubbo.common.constants.QosConstants.QOS_PORT)1 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)1 RegistryConfig (org.apache.dubbo.config.RegistryConfig)1 ServiceConfig (org.apache.dubbo.config.ServiceConfig)1 DubboBootstrap (org.apache.dubbo.config.bootstrap.DubboBootstrap)1 DemoService (org.apache.dubbo.config.spring.api.DemoService)1 MockRegistry (org.apache.dubbo.config.spring.registry.MockRegistry)1 NotifyListener (org.apache.dubbo.registry.NotifyListener)1