mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Polish alibaba/spring-cloud-alibaba#1529 : spring-cloud-starter-dubbo消费者订阅服务时No provider available from registry localhost:9090
This commit is contained in:
parent
9b4975ad2a
commit
c419c1ef5d
@ -51,7 +51,6 @@ import org.springframework.util.CollectionUtils;
|
|||||||
|
|
||||||
import static java.lang.String.format;
|
import static java.lang.String.format;
|
||||||
import static java.util.Collections.emptyList;
|
import static java.util.Collections.emptyList;
|
||||||
import static java.util.Collections.singleton;
|
|
||||||
import static java.util.stream.StreamSupport.stream;
|
import static java.util.stream.StreamSupport.stream;
|
||||||
import static org.apache.dubbo.common.URLBuilder.from;
|
import static org.apache.dubbo.common.URLBuilder.from;
|
||||||
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
|
||||||
@ -437,19 +436,19 @@ public class DubboCloudRegistry extends FailbackRegistry {
|
|||||||
|
|
||||||
// Sync subscription
|
// Sync subscription
|
||||||
subscribeDubboMetadataServiceURLs(subscribedURL, listener,
|
subscribeDubboMetadataServiceURLs(subscribedURL, listener,
|
||||||
singleton(getServiceName(subscribedURL)));
|
getServiceName(subscribedURL));
|
||||||
|
|
||||||
// Sync subscription
|
// Sync subscription
|
||||||
if (containsProviderCategory(subscribedURL)) {
|
if (containsProviderCategory(subscribedURL)) {
|
||||||
registerServiceInstancesChangedListener(subscribedURL, event -> {
|
registerServiceInstancesChangedListener(subscribedURL, event -> {
|
||||||
|
|
||||||
Set<String> serviceNames = getServices(subscribedURL);
|
String sourceServiceName = event.getServiceName();
|
||||||
|
String serviceName = getServiceName(subscribedURL);
|
||||||
|
|
||||||
if (!serviceNames.contains(event.getServiceName())) {
|
if (Objects.equals(sourceServiceName, serviceName)) {
|
||||||
return;
|
subscribeDubboMetadataServiceURLs(subscribedURL, listener,
|
||||||
|
sourceServiceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
subscribeDubboMetadataServiceURLs(subscribedURL, listener, serviceNames);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -459,13 +458,13 @@ public class DubboCloudRegistry extends FailbackRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void subscribeDubboMetadataServiceURLs(URL subscribedURL,
|
private void subscribeDubboMetadataServiceURLs(URL subscribedURL,
|
||||||
NotifyListener listener, Set<String> serviceNames) {
|
NotifyListener listener, String serviceName) {
|
||||||
|
|
||||||
String serviceInterface = subscribedURL.getServiceInterface();
|
String serviceInterface = subscribedURL.getServiceInterface();
|
||||||
String version = subscribedURL.getParameter(VERSION_KEY);
|
String version = subscribedURL.getParameter(VERSION_KEY);
|
||||||
String protocol = subscribedURL.getParameter(PROTOCOL_KEY);
|
String protocol = subscribedURL.getParameter(PROTOCOL_KEY);
|
||||||
|
|
||||||
List<ServiceInstance> serviceInstances = getServiceInstances(serviceNames);
|
List<ServiceInstance> serviceInstances = getServiceInstances(serviceName);
|
||||||
|
|
||||||
List<URL> urls = dubboMetadataUtils.getDubboMetadataServiceURLs(serviceInstances,
|
List<URL> urls = dubboMetadataUtils.getDubboMetadataServiceURLs(serviceInstances,
|
||||||
serviceInterface, version, protocol);
|
serviceInterface, version, protocol);
|
||||||
@ -473,6 +472,21 @@ public class DubboCloudRegistry extends FailbackRegistry {
|
|||||||
notifyAllSubscribedURLs(subscribedURL, urls, listener);
|
notifyAllSubscribedURLs(subscribedURL, urls, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// private void subscribeDubboMetadataServiceURLs(URL subscribedURL,
|
||||||
|
// NotifyListener listener, Set<String> serviceNames) {
|
||||||
|
//
|
||||||
|
// String serviceInterface = subscribedURL.getServiceInterface();
|
||||||
|
// String version = subscribedURL.getParameter(VERSION_KEY);
|
||||||
|
// String protocol = subscribedURL.getParameter(PROTOCOL_KEY);
|
||||||
|
//
|
||||||
|
// List<ServiceInstance> serviceInstances = getServiceInstances(serviceNames);
|
||||||
|
//
|
||||||
|
// List<URL> urls = dubboMetadataUtils.getDubboMetadataServiceURLs(serviceInstances,
|
||||||
|
// serviceInterface, version, protocol);
|
||||||
|
//
|
||||||
|
// notifyAllSubscribedURLs(subscribedURL, urls, listener);
|
||||||
|
// }
|
||||||
|
|
||||||
private boolean containsProviderCategory(URL subscribedURL) {
|
private boolean containsProviderCategory(URL subscribedURL) {
|
||||||
String category = subscribedURL.getParameter(CATEGORY_KEY);
|
String category = subscribedURL.getParameter(CATEGORY_KEY);
|
||||||
return category == null ? false : category.contains(PROVIDER);
|
return category == null ? false : category.contains(PROVIDER);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user