Search in sources :

Example 11 with Registry

use of org.apache.dubbo.registry.Registry in project dubbo by alibaba.

the class ZookeeperRegistryTest method testStatusChecker.

@Disabled
@Test
public /*
      This UT is unstable, consider remove it later.
      @see https://github.com/apache/dubbo/issues/1787
     */
void testStatusChecker() {
    RegistryStatusChecker registryStatusChecker = new RegistryStatusChecker();
    Status status = registryStatusChecker.check();
    assertThat(status.getLevel(), is(Status.Level.UNKNOWN));
    Registry registry = zookeeperRegistryFactory.getRegistry(registryUrl);
    assertThat(registry, not(nullValue()));
    status = registryStatusChecker.check();
    assertThat(status.getLevel(), is(Status.Level.ERROR));
    registry.register(serviceUrl);
    status = registryStatusChecker.check();
    assertThat(status.getLevel(), is(Status.Level.OK));
}
Also used : Status(org.apache.dubbo.common.status.Status) Registry(org.apache.dubbo.registry.Registry) RegistryStatusChecker(org.apache.dubbo.registry.status.RegistryStatusChecker) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 12 with Registry

use of org.apache.dubbo.registry.Registry in project dubbo by alibaba.

the class RegistryProtocol method export.

@Override
public <T> Exporter<T> export(final Invoker<T> originInvoker) throws RpcException {
    URL registryUrl = getRegistryUrl(originInvoker);
    // url to export locally
    URL providerUrl = getProviderUrl(originInvoker);
    // Subscribe the override data
    // FIXME When the provider subscribes, it will affect the scene : a certain JVM exposes the service and call
    // the same service. Because the subscribed is cached key with the name of the service, it causes the
    // subscription information to cover.
    final URL overrideSubscribeUrl = getSubscribedOverrideUrl(providerUrl);
    final OverrideListener overrideSubscribeListener = new OverrideListener(overrideSubscribeUrl, originInvoker);
    overrideListeners.put(overrideSubscribeUrl, overrideSubscribeListener);
    providerUrl = overrideUrlWithConfig(providerUrl, overrideSubscribeListener);
    // export invoker
    final ExporterChangeableWrapper<T> exporter = doLocalExport(originInvoker, providerUrl);
    // url to registry
    final Registry registry = getRegistry(originInvoker);
    final URL registeredProviderUrl = getUrlToRegistry(providerUrl, registryUrl);
    // decide if we need to delay publish
    boolean register = providerUrl.getParameter(REGISTER_KEY, true);
    if (register) {
        registry.register(registeredProviderUrl);
    }
    // register stated url on provider model
    registerStatedUrl(registryUrl, registeredProviderUrl, register);
    exporter.setRegisterUrl(registeredProviderUrl);
    exporter.setSubscribeUrl(overrideSubscribeUrl);
    // Deprecated! Subscribe to override rules in 2.6.x or before.
    registry.subscribe(overrideSubscribeUrl, overrideSubscribeListener);
    notifyExport(exporter);
    // Ensure that a new exporter instance is returned every time export
    return new DestroyableExporter<>(exporter);
}
Also used : QOS_PORT(org.apache.dubbo.common.constants.QosConstants.QOS_PORT) QOS_HOST(org.apache.dubbo.common.constants.QosConstants.QOS_HOST) Registry(org.apache.dubbo.registry.Registry) URL(org.apache.dubbo.common.URL)

Example 13 with Registry

use of org.apache.dubbo.registry.Registry in project dubbo by alibaba.

the class MigrationInvoker method doReSubscribe.

private void doReSubscribe(ClusterInvoker<T> invoker, URL newSubscribeUrl) {
    DynamicDirectory<T> directory = (DynamicDirectory<T>) invoker.getDirectory();
    URL oldSubscribeUrl = directory.getRegisteredConsumerUrl();
    Registry registry = directory.getRegistry();
    registry.unregister(directory.getRegisteredConsumerUrl());
    directory.unSubscribe(RegistryProtocol.toSubscribeUrl(oldSubscribeUrl));
    if (directory.isShouldRegister()) {
        registry.register(directory.getRegisteredConsumerUrl());
        directory.setRegisteredConsumerUrl(newSubscribeUrl);
    }
    directory.buildRouterChain(newSubscribeUrl);
    directory.subscribe(RegistryProtocol.toSubscribeUrl(newSubscribeUrl));
}
Also used : DynamicDirectory(org.apache.dubbo.registry.integration.DynamicDirectory) Registry(org.apache.dubbo.registry.Registry) URL(org.apache.dubbo.common.URL)

Example 14 with Registry

use of org.apache.dubbo.registry.Registry in project dubbo by alibaba.

the class ConsulRegistryTest method testStatusChecker.

@Test
public void testStatusChecker() {
    RegistryStatusChecker registryStatusChecker = new RegistryStatusChecker();
    Status status = registryStatusChecker.check();
    assertThat(status.getLevel(), is(Status.Level.UNKNOWN));
    Registry registry = consulRegistryFactory.getRegistry(registryUrl);
    assertThat(registry, not(nullValue()));
    status = registryStatusChecker.check();
    assertThat(status.getLevel(), is(Status.Level.OK));
    registry.register(serviceUrl);
    status = registryStatusChecker.check();
    assertThat(status.getLevel(), is(Status.Level.OK));
}
Also used : Status(org.apache.dubbo.common.status.Status) Registry(org.apache.dubbo.registry.Registry) RegistryStatusChecker(org.apache.dubbo.registry.status.RegistryStatusChecker) Test(org.junit.jupiter.api.Test)

Example 15 with Registry

use of org.apache.dubbo.registry.Registry in project dubbo by alibaba.

the class AbstractRegistryFactoryTest method testRegistryFactoryGroupCache.

@Test
public void testRegistryFactoryGroupCache() throws Exception {
    Registry registry1 = registryFactory.getRegistry(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":2233?group=aaa"));
    Registry registry2 = registryFactory.getRegistry(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":2233?group=bbb"));
    Assertions.assertNotSame(registry1, registry2);
}
Also used : Registry(org.apache.dubbo.registry.Registry) 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