Merge pull request #1992 from DHBin/master

修复dubbo使用服务分组和分组聚合获取不到url
pull/2087/head
TheoneFx 4 years ago committed by GitHub
commit 55b3336b6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,6 +19,7 @@ package com.alibaba.cloud.dubbo.metadata.repository;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@ -41,6 +42,7 @@ import com.alibaba.cloud.dubbo.util.JSONUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.CommonConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -404,9 +406,35 @@ public class DubboServiceMetadataRepository
public List<URL> getExportedURLs(String serviceInterface, String group,
String version) {
if (group != null) {
List<URL> urls = new LinkedList<>();
if (CommonConstants.ANY_VALUE.equals(group)) {
String serviceKey = URL.buildKey(serviceInterface, group, version);
String expectKey = serviceKey.substring(2);
for (String key : allExportedURLs.keySet()) {
if (key.endsWith(expectKey)) {
urls.addAll(allExportedURLs.get(key));
}
}
}
else {
String[] groups = group.split(CommonConstants.COMMA_SEPARATOR);
for (String expectKey : groups) {
String serviceKey = URL.buildKey(serviceInterface, expectKey,
version);
List<URL> urlList = allExportedURLs.get(serviceKey);
if (urlList != null) {
urls.addAll(urlList);
}
}
}
return urls;
}
else {
String serviceKey = URL.buildKey(serviceInterface, null, version);
return allExportedURLs.getOrDefault(serviceKey, Collections.emptyList());
}
}
/**
* Initialize the specified service's {@link ServiceRestMetadata}.

Loading…
Cancel
Save