Search in sources :

Example 1 with ServiceDiscovery

use of org.apache.dubbo.registry.client.ServiceDiscovery in project dubbo by alibaba.

the class ZookeeperServiceDiscoveryFactoryTest method testCreateZookeeperServiceDiscovery.

@Test
public void testCreateZookeeperServiceDiscovery() {
    final URL url = URL.valueOf("test://test:80");
    final ZookeeperServiceDiscoveryFactory factory = new ZookeeperServiceDiscoveryFactory();
    ServiceDiscovery discovery = factory.createDiscovery(url);
    Assertions.assertTrue(discovery instanceof ZookeeperServiceDiscovery);
}
Also used : URL(org.apache.dubbo.common.URL) ServiceDiscovery(org.apache.dubbo.registry.client.ServiceDiscovery) Test(org.junit.jupiter.api.Test)

Example 2 with ServiceDiscovery

use of org.apache.dubbo.registry.client.ServiceDiscovery in project dubbo by alibaba.

the class LoggingEventListenerTest method testOnEvent.

@Test
public void testOnEvent() throws Exception {
    URL connectionURL = URL.valueOf("file:///Users/Home");
    ServiceDiscovery serviceDiscovery = new FileSystemServiceDiscovery();
    serviceDiscovery.initialize(connectionURL);
    // ServiceDiscoveryStartingEvent
    listener.onEvent(new ServiceDiscoveryInitializingEvent(serviceDiscovery, serviceDiscovery));
    // ServiceDiscoveryStartedEvent
    listener.onEvent(new ServiceDiscoveryInitializedEvent(serviceDiscovery, serviceDiscovery));
    // ServiceInstancePreRegisteredEvent
    listener.onEvent(new ServiceInstancePreRegisteredEvent(serviceDiscovery, createInstance()));
    // ServiceInstanceRegisteredEvent
    listener.onEvent(new ServiceInstanceRegisteredEvent(serviceDiscovery, createInstance()));
    // ServiceInstancesChangedEvent
    listener.onEvent(new ServiceInstancesChangedEvent("test", Arrays.asList(createInstance())));
    // ServiceInstancePreUnregisteredEvent
    listener.onEvent(new ServiceInstancePreUnregisteredEvent(serviceDiscovery, createInstance()));
    // ServiceInstanceUnregisteredEvent
    listener.onEvent(new ServiceInstanceUnregisteredEvent(serviceDiscovery, createInstance()));
    // ServiceDiscoveryStoppingEvent
    listener.onEvent(new ServiceDiscoveryDestroyingEvent(serviceDiscovery, serviceDiscovery));
    // ServiceDiscoveryStoppedEvent
    listener.onEvent(new ServiceDiscoveryDestroyedEvent(serviceDiscovery, serviceDiscovery));
}
Also used : ServiceDiscoveryInitializingEvent(org.apache.dubbo.registry.client.event.ServiceDiscoveryInitializingEvent) ServiceInstancePreUnregisteredEvent(org.apache.dubbo.registry.client.event.ServiceInstancePreUnregisteredEvent) ServiceDiscoveryInitializedEvent(org.apache.dubbo.registry.client.event.ServiceDiscoveryInitializedEvent) ServiceInstancePreRegisteredEvent(org.apache.dubbo.registry.client.event.ServiceInstancePreRegisteredEvent) ServiceDiscoveryDestroyingEvent(org.apache.dubbo.registry.client.event.ServiceDiscoveryDestroyingEvent) ServiceInstanceRegisteredEvent(org.apache.dubbo.registry.client.event.ServiceInstanceRegisteredEvent) ServiceInstancesChangedEvent(org.apache.dubbo.registry.client.event.ServiceInstancesChangedEvent) ServiceInstanceUnregisteredEvent(org.apache.dubbo.registry.client.event.ServiceInstanceUnregisteredEvent) ServiceDiscoveryDestroyedEvent(org.apache.dubbo.registry.client.event.ServiceDiscoveryDestroyedEvent) FileSystemServiceDiscovery(org.apache.dubbo.registry.client.FileSystemServiceDiscovery) URL(org.apache.dubbo.common.URL) FileSystemServiceDiscovery(org.apache.dubbo.registry.client.FileSystemServiceDiscovery) ServiceDiscovery(org.apache.dubbo.registry.client.ServiceDiscovery) Test(org.junit.jupiter.api.Test)

Example 3 with ServiceDiscovery

use of org.apache.dubbo.registry.client.ServiceDiscovery in project dubbo by alibaba.

the class MultipleRegistryServiceDiscovery method initialize.

@Override
public void initialize(URL registryURL) throws Exception {
    this.registryURL = registryURL;
    this.applicationName = registryURL.getParameter(CommonConstants.APPLICATION_KEY);
    Map<String, String> parameters = registryURL.getParameters();
    for (String key : parameters.keySet()) {
        if (key.startsWith(REGISTRY_PREFIX_KEY)) {
            URL url = URL.valueOf(registryURL.getParameter(key)).addParameter(CommonConstants.APPLICATION_KEY, applicationName).addParameter("registry-type", "service");
            ServiceDiscovery serviceDiscovery = ServiceDiscoveryFactory.getExtension(url).getServiceDiscovery(url);
            serviceDiscovery.initialize(url);
            serviceDiscoveries.put(key, serviceDiscovery);
        }
    }
}
Also used : URL(org.apache.dubbo.common.URL) AbstractServiceDiscovery(org.apache.dubbo.registry.client.AbstractServiceDiscovery) ServiceDiscovery(org.apache.dubbo.registry.client.ServiceDiscovery)

Example 4 with ServiceDiscovery

use of org.apache.dubbo.registry.client.ServiceDiscovery in project incubator-dubbo-ops by apache.

the class ConfigCenter method getServiceDiscoveryRegistry.

@Bean(destroyMethod = "destroy")
@DependsOn("dubboRegistry")
ServiceDiscovery getServiceDiscoveryRegistry() throws Exception {
    URL registryURL = registryUrl.setPath(RegistryService.class.getName());
    ServiceDiscoveryFactory factory = getExtension(registryURL);
    ServiceDiscovery serviceDiscovery = factory.getServiceDiscovery(registryURL);
    serviceDiscovery.initialize(registryURL);
    return serviceDiscovery;
}
Also used : ServiceDiscoveryFactory(org.apache.dubbo.registry.client.ServiceDiscoveryFactory) RegistryService(org.apache.dubbo.registry.RegistryService) URL(org.apache.dubbo.common.URL) ServiceDiscovery(org.apache.dubbo.registry.client.ServiceDiscovery) DependsOn(org.springframework.context.annotation.DependsOn) Bean(org.springframework.context.annotation.Bean)

Aggregations

URL (org.apache.dubbo.common.URL)4 ServiceDiscovery (org.apache.dubbo.registry.client.ServiceDiscovery)4 Test (org.junit.jupiter.api.Test)2 RegistryService (org.apache.dubbo.registry.RegistryService)1 AbstractServiceDiscovery (org.apache.dubbo.registry.client.AbstractServiceDiscovery)1 FileSystemServiceDiscovery (org.apache.dubbo.registry.client.FileSystemServiceDiscovery)1 ServiceDiscoveryFactory (org.apache.dubbo.registry.client.ServiceDiscoveryFactory)1 ServiceDiscoveryDestroyedEvent (org.apache.dubbo.registry.client.event.ServiceDiscoveryDestroyedEvent)1 ServiceDiscoveryDestroyingEvent (org.apache.dubbo.registry.client.event.ServiceDiscoveryDestroyingEvent)1 ServiceDiscoveryInitializedEvent (org.apache.dubbo.registry.client.event.ServiceDiscoveryInitializedEvent)1 ServiceDiscoveryInitializingEvent (org.apache.dubbo.registry.client.event.ServiceDiscoveryInitializingEvent)1 ServiceInstancePreRegisteredEvent (org.apache.dubbo.registry.client.event.ServiceInstancePreRegisteredEvent)1 ServiceInstancePreUnregisteredEvent (org.apache.dubbo.registry.client.event.ServiceInstancePreUnregisteredEvent)1 ServiceInstanceRegisteredEvent (org.apache.dubbo.registry.client.event.ServiceInstanceRegisteredEvent)1 ServiceInstanceUnregisteredEvent (org.apache.dubbo.registry.client.event.ServiceInstanceUnregisteredEvent)1 ServiceInstancesChangedEvent (org.apache.dubbo.registry.client.event.ServiceInstancesChangedEvent)1 Bean (org.springframework.context.annotation.Bean)1 DependsOn (org.springframework.context.annotation.DependsOn)1