public class ServiceDiscoveryRegistry extends FailbackRegistry
ServiceDiscoveryRegistry that is a new service-oriented
Registry based on ServiceDiscovery, it will not interact in the external registry directly,
but store the urls that Dubbo services exported and referenced into WritableMetadataService
when register(URL) and subscribe(URL, NotifyListener) methods are executed. After that the exported
urls can be get from MetadataService.getExportedURLs() and its variant methods. In contrast,
MetadataService.getSubscribedURLs() method offers the subscribed URLs.
Every ServiceDiscoveryRegistry object has its own ServiceDiscovery instance that was initialized
under the construction. As the primary argument of constructor , the
URL of connection the registry decides what the kind of ServiceDiscovery is. Generally, each
protocol associates with a kind of ServiceDiscovery's implementation if present, or the
FileSystemServiceDiscovery will be the default one. Obviously, it's also allowed to extend
ServiceDiscovery using the Dubbo SPI.
In the subscription phase, the ServiceDiscovery instance will be used
to discovery the service instances via the ServiceDiscovery.getInstances(String).
However, the argument of this method requires the service name that the subscribed URL can't find, thus,
ServiceNameMapping will help to figure out one or more services that exported correlative Dubbo services. If
the service names can be found, the exported URLs will be get from the remote MetadataService
being deployed on all instances of services. The whole process runs under the
subscribeURLs(URL, NotifyListener, String, Collection) method. It's very expensive to invoke
MetadataService for each service instance, thus ServiceDiscoveryRegistry
introduces a cache to optimize the calculation with "revisions". If the revisions of N
service instances are same, MetadataService is invoked just only once, and then it
does return the exported URLs as a template by which others are
cloned.
In contrast, current service instance will not be registered to the registry whether any
Dubbo service is exported or not.
ServiceDiscovery,
FailbackRegistry,
WritableMetadataService| Constructor and Description |
|---|
ServiceDiscoveryRegistry(URL registryURL) |
| Modifier and Type | Method and Description |
|---|---|
static ServiceDiscoveryRegistry |
create(URL registryURL)
Create an instance of
ServiceDiscoveryRegistry if supported |
void |
destroy() |
void |
doRegister(URL url) |
void |
doSubscribe(URL url,
NotifyListener listener) |
void |
doUnregister(URL url) |
void |
doUnsubscribe(URL url,
NotifyListener listener) |
ServiceDiscovery |
getServiceDiscovery() |
Set<String> |
getSubscribedServices()
Get the subscribed service names
|
static Set<String> |
getSubscribedServices(URL registryURL)
Get the subscribed services from the specified registry
url |
boolean |
isAvailable() |
static Set<String> |
parseServices(String literalServices) |
void |
register(URL url)
Register data, such as : provider service, consumer address, route rule, override rule and other data.
|
void |
subscribe(URL url,
NotifyListener listener)
Subscribe to eligible registered data and automatically push when the registered data is changed.
|
static boolean |
supports(URL registryURL)
Supports or not ?
|
void |
unregister(URL url)
Unregister
|
void |
unsubscribe(URL url,
NotifyListener listener)
Unsubscribe
|
removeFailedNotifiedTask, removeFailedRegisteredTask, removeFailedSubscribedTask, removeFailedUnregisteredTask, removeFailedUnsubscribedTaskdoSaveProperties, getCacheFile, getCacheProperties, getCacheUrls, getLastCacheChanged, getNotified, getRegistered, getSubscribed, getUrl, lookup, toStringpublic ServiceDiscoveryRegistry(URL registryURL)
public ServiceDiscovery getServiceDiscovery()
public static Set<String> getSubscribedServices(URL registryURL)
urlregistryURL - the specified registry urlpublic final void register(URL url)
RegistryService
Registering is required to support the contract:
1. When the URL sets the check=false parameter. When the registration fails, the exception is not thrown and retried in the background. Otherwise, the exception will be thrown.
2. When URL sets the dynamic=false parameter, it needs to be stored persistently, otherwise, it should be deleted automatically when the registrant has an abnormal exit.
3. When the URL sets category=routers, it means classified storage, the default category is providers, and the data can be notified by the classified section.
4. When the registry is restarted, network jitter, data can not be lost, including automatically deleting data from the broken line.
5. Allow URLs which have the same URL but different parameters to coexist,they can't cover each other.
register in interface RegistryServiceregister in class FailbackRegistryurl - Registration information , is not allowed to be empty, e.g: dubbo://10.20.153.10/org.apache.dubbo.foo.BarService?version=1.0.0&application=kylinpublic void doRegister(URL url)
doRegister in class FailbackRegistrypublic final void unregister(URL url)
RegistryService
Unregistering is required to support the contract:
1. If it is the persistent stored data of dynamic=false, the registration data can not be found, then the IllegalStateException is thrown, otherwise it is ignored.
2. Unregister according to the full url match.
unregister in interface RegistryServiceunregister in class FailbackRegistryurl - Registration information , is not allowed to be empty, e.g: dubbo://10.20.153.10/org.apache.dubbo.foo.BarService?version=1.0.0&application=kylinpublic void doUnregister(URL url)
doUnregister in class FailbackRegistrypublic final void subscribe(URL url, NotifyListener listener)
RegistryService
Subscribing need to support contracts:
1. When the URL sets the check=false parameter. When the registration fails, the exception is not thrown and retried in the background.
2. When URL sets category=routers, it only notifies the specified classification data. Multiple classifications are separated by commas, and allows asterisk to match, which indicates that all categorical data are subscribed.
3. Allow interface, group, version, and classifier as a conditional query, e.g.: interface=org.apache.dubbo.foo.BarService&version=1.0.0
4. And the query conditions allow the asterisk to be matched, subscribe to all versions of all the packets of all interfaces, e.g. :interface=*&group=*&version=*&classifier=*
5. When the registry is restarted and network jitter, it is necessary to automatically restore the subscription request.
6. Allow URLs which have the same URL but different parameters to coexist,they can't cover each other.
7. The subscription process must be blocked, when the first notice is finished and then returned.
subscribe in interface RegistryServicesubscribe in class FailbackRegistryurl - Subscription condition, not allowed to be empty, e.g. consumer://10.20.153.10/org.apache.dubbo.foo.BarService?version=1.0.0&application=kylinlistener - A listener of the change event, not allowed to be emptypublic void doSubscribe(URL url, NotifyListener listener)
doSubscribe in class FailbackRegistrypublic final void unsubscribe(URL url, NotifyListener listener)
RegistryService
Unsubscribing is required to support the contract:
1. If don't subscribe, ignore it directly.
2. Unsubscribe by full URL match.
unsubscribe in interface RegistryServiceunsubscribe in class FailbackRegistryurl - Subscription condition, not allowed to be empty, e.g. consumer://10.20.153.10/org.apache.dubbo.foo.BarService?version=1.0.0&application=kylinlistener - A listener of the change event, not allowed to be emptypublic void doUnsubscribe(URL url, NotifyListener listener)
doUnsubscribe in class FailbackRegistrypublic boolean isAvailable()
public void destroy()
destroy in interface Nodedestroy in class FailbackRegistrypublic Set<String> getSubscribedServices()
public static ServiceDiscoveryRegistry create(URL registryURL)
ServiceDiscoveryRegistry if supportedregistryURL - the url of registrynull if not supportedCopyright © 2011–2019 The Apache Software Foundation. All rights reserved.