apache / apache/dubbo

RegistryService#subscribe为和在服务导出时也要执行?

Open
#9,212 3 comments 0 reactions 0 assignees View on GitHub
type/discussion
Dominant language
Java
Stars
41.6k
Forks
26.4k
Avg merge
15h 13m
Merged PRs (30d)
4

Description

在2.7.8版本中,RegistryService#subscribe到入口为RegistryProtocol#export和RegistryProtocol#doRefer方法,前者为服务导出时调用,后者为服务引用是调用,RegistryProtocol#export方法处理过后的overrideSubscribeUrl格式为:provider://127.0.0.1:20880/com.example.DemoService?category=configurators&check=false&Xxxx=xxxx,当使用nacos作为注册中心时,该调用路径为:RegistryProtocol#export->ListenerRegistryWrapper#subscribe->FailbackRegistry#subscribe->NacosRegistry#doSubscribe->NacosRegistry#notifySubscriber->FailbackRegistry#notify->AbstractRegistry#notify.在这个调用链中,并没有发现有用信息,请问在服务导出时,为啥要调用RegistryService#subscribe方法?

再看下AbstractRegistry#notify方法:
```
protected void notify(URL url, NotifyListener listener, List urls) {
if (url == null) {
throw new IllegalArgumentException("notify url == null");
}
if (listener == null) {
throw new IllegalArgumentException("notify listener == null");
}
if ((CollectionUtils.isEmpty(urls))
&& !ANY_VALUE.equals(url.getServiceInterface())) {
logger.warn("Ignore empty notify urls for subscribe url " + url);
return;
}
if (logger.isInfoEnabled()) {
logger.info("Notify urls for subscribe url " + url + ", urls: " + urls);
}
// 保留每个provider的category
Map> result = new HashMap<>();
for (URL u : urls) {
if (UrlUtils.isMatch(url, u)) {
String category = u.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY);
List categoryList = result.computeIfAbsent(category, k -> new ArrayList<>());
categoryList.add(u);
}
}
// 服务导出时的订阅,执行到此就结束了
if (result.size() == 0) {
return;
}
// 添加缓存
Map> categoryNotified = notified.computeIfAbsent(url, u -> new ConcurrentHashMap<>());
for (Map.Entry> entry : result.entrySet()) {
String category = entry.getKey();
List categoryList = entry.getValue();
categoryNotified.put(category, categoryList);
listener.notify(categoryList);
// 我们将在每次通知后更新缓存文件。
// 当我们的注册表由于网络抖动而订阅失败时,我们至少可以返回现有的缓存URL。
saveProperties(url);
}
}

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.