The concept of URL-based design runs through Dubbo. There are two main threads, the provider and consumer.
Provider
registry-url: It provides all information related the registry center, which is built by RegistryConfig and the protocol begins with registry, such as :
// For providers, this is used to enable custom proxy to generate invoker
String proxy = url.getParameter(PROXY_KEY);
if (StringUtils.isNotEmpty(proxy)) {
registryURL = registryURL.addParameter(PROXY_KEY, proxy);
}
Finally, there are some changes in registry-url as follows:
registry-url's protocol will be updated from registry to zookeeper (if you use zookeeper as the registry center)
registry-url will add the parameter export and its value is provider-url(see below)
// You can customize Configurator to append extra parameters
if (ExtensionLoader.getExtensionLoader(ConfiguratorFactory.class)
.hasExtension(url.getProtocol())) {
url = ExtensionLoader.getExtensionLoader(ConfiguratorFactory.class)
.getExtension(url.getProtocol()).getConfigurator(url).configure(url);
}
override-substribe-url: it used to avoid to cover subscription information when the provider subscribed
// 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);
protected void notify(URL url, NotifyListener listener, List<URL> urls) {
//omit some codes
// keep every provider's category.
Map<String, List<URL>> result = new HashMap<>();
for (URL u : urls) {
if (UrlUtils.isMatch(url, u)) {
String category = u.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY);
List<URL> categoryList = result.computeIfAbsent(category, k -> new ArrayList<>());
categoryList.add(u);
}
}
//omit some codes
for (Map.Entry<String, List<URL>> entry : result.entrySet()) {
String category = entry.getKey();
List<URL> categoryList = entry.getValue();
categoryNotified.put(category, categoryList);
listener.notify(categoryList);
// We will update our cache file after each notification.
// When our Registry has a subscribe failure due to network jitter, we can return at least the existing cache URL.
saveProperties(url);
}
}
The cache-url was in the dubbo-registry-dubbo-demo-api-provider-127.0.0.1-2181.cache file
private static List<URL> genCompatibleRegistries(List<URL> registryList, boolean provider) {
List<URL> result = new ArrayList<>(registryList.size());
registryList.forEach(registryURL -> {
result.add(registryURL);
if (provider) {
// for registries enabled service discovery, automatically register interface compatible addresses.
if (SERVICE_REGISTRY_PROTOCOL.equals(registryURL.getProtocol())
&& registryURL.getParameter(REGISTRY_PUBLISH_INTERFACE_KEY, ConfigurationUtils.getDynamicGlobalConfiguration().getBoolean(DUBBO_PUBLISH_INTERFACE_DEFAULT_KEY, false))
&& registryNotExists(registryURL, registryList, REGISTRY_PROTOCOL)) {
URL interfaceCompatibleRegistryURL = URLBuilder.from(registryURL)
.setProtocol(REGISTRY_PROTOCOL)
.removeParameter(REGISTRY_TYPE_KEY)
.build();
result.add(interfaceCompatibleRegistryURL);
}
}
});
return result;
}
Add monitor-url if it exists (you can see above to how to generate monitor-url), also add parameter as refer and value as all configuration of ReferenceConfig
// if protocols not injvm checkRegistry
if (!LOCAL_PROTOCOL.equalsIgnoreCase(getProtocol())) {
checkRegistry();
List<URL> us = ConfigValidationUtils.loadRegistries(this, false);
if (CollectionUtils.isNotEmpty(us)) {
for (URL u : us) {
URL monitorUrl = ConfigValidationUtils.loadMonitor(this, u);
if (monitorUrl != null) {
map.put(MONITOR_KEY, URL.encode(monitorUrl.toFullString()));
}
urls.add(u.addParameterAndEncoded(REFER_KEY, StringUtils.toQueryString(map)));
}
}
// omit some codes
}
The concept of URL-based design runs through Dubbo. There are two main threads, the provider and consumer.
Provider
registry-url: It provides all information related the registry center, which is built by
RegistryConfig
and the protocol begins with registry, such as :And then, registry-url will be enhanced if the proxy has been customized by users. You can see ServicesConfig#doExportUrlsFor1Protocol
Finally, there are some changes in registry-url as follows:
registry-url's protocol will be updated from registry to zookeeper (if you use zookeeper as the registry center)
registry-url will add the parameter
export
and its value is provider-url(see below)monitor-url: It‘s designed for monitor and built by
MonitorConfig
and registry-url, which begins with dubbo, such aslocal-url: It provides local-to-local call for debugging, which begins with injvm, such as
provider-url: It's the core url, which is to describe the provider's information and begins with dubbo. Also it's will be changed at runtime.
ServiceConfig
firstconfigurator
dynamic
parameter if it's absentmonitor
and value as monitor-urlthe url will be
override-substribe-url: it used to avoid to cover subscription information when the provider subscribed
And the url begins with provider, such as
cache-url: It saves in the disk and also will be updated if receive an notification of changes from registry center, which begins with empty, such as
dubbo-registry-dubbo-demo-api-provider-127.0.0.1-2181.cache
fileConsumer
local-url: It's for checking if it's in JVM, which begins with injvm
registry-url: It provides registry center information, which is built by
ReferenceConfig
and begins with registryAlso, it will be changed at runtime as follows:
refer
and value as all configuration ofReferenceConfig
such as
customer-url: it's generated from registry-url, which begins with consumer. There are two kinds of it as follows
generic
is settrue
or
false
finally, its protocol will be changed, such as
directory-url: it's generated from registry-url, which begins with dubbo.
such as
override-directory-url: it's generated from registry-url, which begins with dubbo. The override-directory-url is the same as directory-url first.
url-to-registry: It generated by all parameters in registry-url
such as
subscribed-url: It generated by url-to-registry and add parameter
category
such as