|
|
|
@ -30,6 +30,7 @@ import org.springframework.cloud.alibaba.dubbo.metadata.DubboRestServiceMetadata
|
|
|
|
|
import org.springframework.cloud.alibaba.dubbo.metadata.RequestMetadata;
|
|
|
|
|
import org.springframework.cloud.alibaba.dubbo.metadata.ServiceRestMetadata;
|
|
|
|
|
import org.springframework.cloud.alibaba.dubbo.service.DubboMetadataService;
|
|
|
|
|
import org.springframework.cloud.alibaba.dubbo.service.DubboMetadataServiceExporter;
|
|
|
|
|
import org.springframework.cloud.alibaba.dubbo.service.DubboMetadataServiceProxy;
|
|
|
|
|
import org.springframework.cloud.alibaba.dubbo.util.JSONUtils;
|
|
|
|
|
import org.springframework.cloud.client.ServiceInstance;
|
|
|
|
@ -37,12 +38,12 @@ import org.springframework.cloud.client.discovery.DiscoveryClient;
|
|
|
|
|
import org.springframework.http.HttpRequest;
|
|
|
|
|
import org.springframework.stereotype.Repository;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.LinkedHashMap;
|
|
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
@ -51,10 +52,19 @@ import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static java.lang.String.format;
|
|
|
|
|
import static java.lang.String.valueOf;
|
|
|
|
|
import static java.util.Collections.emptyList;
|
|
|
|
|
import static java.util.Collections.emptySet;
|
|
|
|
|
import static java.util.Collections.unmodifiableList;
|
|
|
|
|
import static java.util.Collections.unmodifiableMap;
|
|
|
|
|
import static java.util.Collections.unmodifiableSet;
|
|
|
|
|
import static org.apache.dubbo.common.Constants.APPLICATION_KEY;
|
|
|
|
|
import static org.apache.dubbo.common.Constants.VERSION_KEY;
|
|
|
|
|
import static org.springframework.cloud.alibaba.dubbo.env.DubboCloudProperties.ALL_DUBBO_SERVICES;
|
|
|
|
|
import static org.springframework.cloud.alibaba.dubbo.http.DefaultHttpRequest.builder;
|
|
|
|
|
import static org.springframework.util.CollectionUtils.isEmpty;
|
|
|
|
|
import static org.springframework.util.StringUtils.hasText;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Dubbo Service Metadata {@link Repository}
|
|
|
|
@ -65,17 +75,56 @@ import static org.springframework.util.CollectionUtils.isEmpty;
|
|
|
|
|
public class DubboServiceMetadataRepository {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The property name of Dubbo {@link URL URLs} metadata
|
|
|
|
|
* The prefix of {@link DubboMetadataService} : "dubbo.metadata-service."
|
|
|
|
|
*/
|
|
|
|
|
public static final String DUBBO_URLS_METADATA_PROPERTY_NAME = "dubbo.urls";
|
|
|
|
|
public static final String DUBBO_METADATA_SERVICE_PREFIX = "dubbo.metadata-service.";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The {@link URL URLs} property name of {@link DubboMetadataService} : "dubbo.metadata-service.urls"
|
|
|
|
|
*/
|
|
|
|
|
public static final String DUBBO_METADATA_SERVICE_URLS_PROPERTY_NAME = DUBBO_METADATA_SERVICE_PREFIX + "urls";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The {@link String#format(String, Object...) pattern} of dubbo protocols port
|
|
|
|
|
*/
|
|
|
|
|
public static final String DUBBO_PROTOCOLS_PORT_PROPERTY_NAME_PATTERN = "dubbo.protocols.%s.port";
|
|
|
|
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
|
|
|
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
|
|
|
|
|
|
|
|
|
private final Set<URL> registeredURLs = new LinkedHashSet<>();
|
|
|
|
|
// =================================== Registration =================================== //
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* All exported {@link URL urls} {@link Map} whose key is the return value of {@link URL#getServiceKey()} method
|
|
|
|
|
* and value is the {@link List} of {@link URL URLs}
|
|
|
|
|
*/
|
|
|
|
|
private final MultiValueMap<String, URL> allExportedURLs = new LinkedMultiValueMap<>();
|
|
|
|
|
|
|
|
|
|
// ==================================================================================== //
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// =================================== Subscription =================================== //
|
|
|
|
|
|
|
|
|
|
private Set<String> subscribedServices;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The subscribed {@link URL urls} {@link Map} of {@link DubboMetadataService},
|
|
|
|
|
* whose key is the return value of {@link URL#getServiceKey()} method and value is the {@link List} of
|
|
|
|
|
* {@link URL URLs}
|
|
|
|
|
*/
|
|
|
|
|
private final MultiValueMap<String, URL> subscribedDubboMetadataServiceURLs = new LinkedMultiValueMap<>();
|
|
|
|
|
|
|
|
|
|
// ==================================================================================== //
|
|
|
|
|
|
|
|
|
|
private final Map<String, String> dubboServiceKeysRepository = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
// =================================== REST Metadata ================================== //
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A Map to store REST metadata temporary, its' key is the special service name for a Dubbo service,
|
|
|
|
|
* the value is a JSON content of JAX-RS or Spring MVC REST metadata from the annotated methods.
|
|
|
|
|
*/
|
|
|
|
|
private final Set<ServiceRestMetadata> serviceRestMetadata = new LinkedHashSet<>();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Key is application name
|
|
|
|
@ -83,7 +132,10 @@ public class DubboServiceMetadataRepository {
|
|
|
|
|
*/
|
|
|
|
|
private Map<String, Map<RequestMetadataMatcher, DubboRestServiceMetadata>> dubboRestServiceMetadataRepository = newHashMap();
|
|
|
|
|
|
|
|
|
|
private Set<String> subscribedServices;
|
|
|
|
|
// ==================================================================================== //
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// =================================== Dependencies =================================== //
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private DubboCloudProperties dubboCloudProperties;
|
|
|
|
@ -100,67 +152,179 @@ public class DubboServiceMetadataRepository {
|
|
|
|
|
@Value("${spring.application.name}")
|
|
|
|
|
private String currentApplicationName;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private DubboMetadataServiceExporter dubboMetadataServiceExporter;
|
|
|
|
|
|
|
|
|
|
// ==================================================================================== //
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct
|
|
|
|
|
public void init() {
|
|
|
|
|
// Keep the order in following invocations
|
|
|
|
|
initSubscribedServices();
|
|
|
|
|
initDubboServiceKeysRepository();
|
|
|
|
|
retainAvailableSubscribedServices();
|
|
|
|
|
initSubscribedDubboMetadataServices();
|
|
|
|
|
initDubboRestServiceMetadataRepository();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The specified service is subscribe or not
|
|
|
|
|
* Get the metadata {@link Map} of {@link DubboMetadataService}
|
|
|
|
|
*
|
|
|
|
|
* @param serviceName the service name
|
|
|
|
|
* @return
|
|
|
|
|
* @return non-null read-only {@link Map}
|
|
|
|
|
*/
|
|
|
|
|
public boolean isSubscribedService(String serviceName) {
|
|
|
|
|
return subscribedServices.contains(serviceName);
|
|
|
|
|
public Map<String, String> getDubboMetadataServiceMetadata() {
|
|
|
|
|
|
|
|
|
|
List<URL> dubboMetadataServiceURLs = dubboMetadataServiceExporter.export();
|
|
|
|
|
|
|
|
|
|
// remove the exported URLs of DubboMetadataService
|
|
|
|
|
removeDubboMetadataServiceURLs(dubboMetadataServiceURLs);
|
|
|
|
|
|
|
|
|
|
Map<String, String> metadata = newHashMap();
|
|
|
|
|
|
|
|
|
|
addDubboMetadataServiceURLsMetadata(metadata, dubboMetadataServiceURLs);
|
|
|
|
|
addDubboProtocolsPortMetadata(metadata);
|
|
|
|
|
|
|
|
|
|
return Collections.unmodifiableMap(metadata);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void removeDubboMetadataServiceURLs(List<URL> dubboMetadataServiceURLs) {
|
|
|
|
|
dubboMetadataServiceURLs.forEach(this::unexportURL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addDubboMetadataServiceURLsMetadata(Map<String, String> metadata, List<URL> dubboMetadataServiceURLs) {
|
|
|
|
|
String dubboMetadataServiceURLsJSON = jsonUtils.toJSON(dubboMetadataServiceURLs);
|
|
|
|
|
metadata.put(DUBBO_METADATA_SERVICE_URLS_PROPERTY_NAME, dubboMetadataServiceURLsJSON);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addDubboProtocolsPortMetadata(Map<String, String> metadata) {
|
|
|
|
|
|
|
|
|
|
allExportedURLs.values()
|
|
|
|
|
.stream()
|
|
|
|
|
.flatMap(v -> v.stream())
|
|
|
|
|
.forEach(url -> {
|
|
|
|
|
String protocol = url.getProtocol();
|
|
|
|
|
String propertyName = getDubboProtocolPropertyName(protocol);
|
|
|
|
|
String propertyValue = valueOf(url.getPort());
|
|
|
|
|
metadata.put(propertyName, propertyValue);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the service name by the {@link URL#getServiceKey() service key}
|
|
|
|
|
* Get the property name of Dubbo Protocol
|
|
|
|
|
*
|
|
|
|
|
* @param url {@link URL}
|
|
|
|
|
* @return the service name if found
|
|
|
|
|
* @param protocol Dubbo Protocol
|
|
|
|
|
* @return non-null
|
|
|
|
|
*/
|
|
|
|
|
public String getServiceName(URL url) {
|
|
|
|
|
return getServiceName(url.getServiceKey());
|
|
|
|
|
public String getDubboProtocolPropertyName(String protocol) {
|
|
|
|
|
return format(DUBBO_PROTOCOLS_PORT_PROPERTY_NAME_PATTERN, protocol);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the service name by the {@link URL#getServiceKey() service key}
|
|
|
|
|
* Publish the {@link Set} of {@link ServiceRestMetadata}
|
|
|
|
|
*
|
|
|
|
|
* @param serviceKey the {@link URL#getServiceKey() service key}
|
|
|
|
|
* @return the service name if found
|
|
|
|
|
* @param serviceRestMetadataSet the {@link Set} of {@link ServiceRestMetadata}
|
|
|
|
|
*/
|
|
|
|
|
public String getServiceName(String serviceKey) {
|
|
|
|
|
return dubboServiceKeysRepository.get(serviceKey);
|
|
|
|
|
public void publishServiceRestMetadata(Set<ServiceRestMetadata> serviceRestMetadataSet) {
|
|
|
|
|
for (ServiceRestMetadata serviceRestMetadata : serviceRestMetadataSet) {
|
|
|
|
|
if (!isEmpty(serviceRestMetadata.getMeta())) {
|
|
|
|
|
this.serviceRestMetadata.add(serviceRestMetadata);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the {@link Set} of {@link ServiceRestMetadata}
|
|
|
|
|
*
|
|
|
|
|
* @return non-null read-only {@link Set}
|
|
|
|
|
*/
|
|
|
|
|
public Set<ServiceRestMetadata> getServiceRestMetadata() {
|
|
|
|
|
return unmodifiableSet(serviceRestMetadata);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
|
// * Get The subscribed {@link DubboMetadataService}'s {@link URL URLs}
|
|
|
|
|
// *
|
|
|
|
|
// * @return non-null read-only {@link List}
|
|
|
|
|
// */
|
|
|
|
|
// public List<URL> getSubscribedDubboMetadataServiceURLs() {
|
|
|
|
|
// return Collections.unmodifiableList(subscribedDubboMetadataServiceURLs);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
public List<URL> findSubscribedDubboMetadataServiceURLs(String serviceName, String group, String version,
|
|
|
|
|
String protocol) {
|
|
|
|
|
String serviceKey = URL.buildKey(serviceName, group, version);
|
|
|
|
|
List<URL> urls = subscribedDubboMetadataServiceURLs.get(serviceKey);
|
|
|
|
|
|
|
|
|
|
if (isEmpty(urls)) {
|
|
|
|
|
return emptyList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hasText(protocol) ?
|
|
|
|
|
urls.stream().filter(url -> url.getProtocol().equalsIgnoreCase(protocol)).collect(Collectors.toList()) :
|
|
|
|
|
unmodifiableList(urls)
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The specified service is subscribe or not
|
|
|
|
|
*
|
|
|
|
|
* @param serviceName the service name
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public boolean isSubscribedService(String serviceName) {
|
|
|
|
|
return subscribedServices.contains(serviceName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void registerURL(URL url) {
|
|
|
|
|
this.registeredURLs.add(url);
|
|
|
|
|
public void exportURL(URL url) {
|
|
|
|
|
this.allExportedURLs.add(url.getServiceKey(), url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void unregisterURL(URL url) {
|
|
|
|
|
this.registeredURLs.remove(url);
|
|
|
|
|
public void unexportURL(URL url) {
|
|
|
|
|
String key = url.getServiceKey();
|
|
|
|
|
List<URL> urls = allExportedURLs.get(key);
|
|
|
|
|
urls.remove(url);
|
|
|
|
|
this.allExportedURLs.addAll(key, urls);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Collection<URL> getRegisteredUrls() {
|
|
|
|
|
return Collections.unmodifiableSet(registeredURLs);
|
|
|
|
|
/**
|
|
|
|
|
* Get all exported {@link URL urls}.
|
|
|
|
|
*
|
|
|
|
|
* @return non-null read-only
|
|
|
|
|
*/
|
|
|
|
|
public Map<String, List<URL>> getAllExportedUrls() {
|
|
|
|
|
return unmodifiableMap(allExportedURLs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Build the {@link URL urls} by the specified {@link ServiceInstance}
|
|
|
|
|
* Get all exported {@link URL#getServiceKey() service keys}
|
|
|
|
|
*
|
|
|
|
|
* @return non-null read-only
|
|
|
|
|
*/
|
|
|
|
|
public Set<String> getAllServiceKeys() {
|
|
|
|
|
return allExportedURLs.keySet();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the {@link URL urls} that {@link DubboMetadataService} exported by the specified {@link ServiceInstance}
|
|
|
|
|
*
|
|
|
|
|
* @param serviceInstance {@link ServiceInstance}
|
|
|
|
|
* @return the mutable {@link URL urls}
|
|
|
|
|
*/
|
|
|
|
|
public List<URL> buildURLs(ServiceInstance serviceInstance) {
|
|
|
|
|
public List<URL> getDubboMetadataServiceURLs(ServiceInstance serviceInstance) {
|
|
|
|
|
Map<String, String> metadata = serviceInstance.getMetadata();
|
|
|
|
|
String dubboURLsJSON = metadata.get(DUBBO_METADATA_SERVICE_URLS_PROPERTY_NAME);
|
|
|
|
|
return jsonUtils.toURLs(dubboURLsJSON);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Integer getDubboProtocolPort(ServiceInstance serviceInstance, String protocol) {
|
|
|
|
|
String protocolProperty = getDubboProtocolPropertyName(protocol);
|
|
|
|
|
Map<String, String> metadata = serviceInstance.getMetadata();
|
|
|
|
|
String dubboURLsJSON = metadata.get(DUBBO_URLS_METADATA_PROPERTY_NAME);
|
|
|
|
|
List<String> urlValues = jsonUtils.toList(dubboURLsJSON);
|
|
|
|
|
return urlValues.stream().map(URL::valueOf).collect(Collectors.toList());
|
|
|
|
|
String protocolPort = metadata.get(protocolProperty);
|
|
|
|
|
return hasText(protocolPort) ? Integer.valueOf(protocolPort) : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<URL> getExportedURLs(String serviceInstance, String group, String version) {
|
|
|
|
|
String serviceKey = URL.buildKey(serviceInstance, group, version);
|
|
|
|
|
return allExportedURLs.getOrDefault(serviceKey, Collections.emptyList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -212,6 +376,10 @@ public class DubboServiceMetadataRepository {
|
|
|
|
|
return match(dubboRestServiceMetadataRepository, serviceName, requestMetadata);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Set<String> getSubscribedServices() {
|
|
|
|
|
return Collections.unmodifiableSet(subscribedServices);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private <T> T match(Map<String, Map<RequestMetadataMatcher, T>> repository, String serviceName,
|
|
|
|
|
RequestMetadata requestMetadata) {
|
|
|
|
|
|
|
|
|
@ -256,18 +424,22 @@ public class DubboServiceMetadataRepository {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Set<ServiceRestMetadata> getServiceRestMetadataSet(String serviceName) {
|
|
|
|
|
DubboMetadataService dubboMetadataService = dubboMetadataConfigServiceProxy.newProxy(serviceName);
|
|
|
|
|
|
|
|
|
|
Set<ServiceRestMetadata> metadata = Collections.emptySet();
|
|
|
|
|
try {
|
|
|
|
|
String serviceRestMetadataJsonConfig = dubboMetadataService.getServiceRestMetadata();
|
|
|
|
|
if(StringUtils.hasText(serviceRestMetadataJsonConfig)) {
|
|
|
|
|
metadata = objectMapper.readValue(serviceRestMetadataJsonConfig,
|
|
|
|
|
TypeFactory.defaultInstance().constructCollectionType(LinkedHashSet.class, ServiceRestMetadata.class));
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
if (logger.isErrorEnabled()) {
|
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
|
|
|
|
|
|
Set<ServiceRestMetadata> metadata = emptySet();
|
|
|
|
|
|
|
|
|
|
DubboMetadataService dubboMetadataService = dubboMetadataConfigServiceProxy.getProxy(serviceName);
|
|
|
|
|
|
|
|
|
|
if (dubboMetadataService != null) {
|
|
|
|
|
try {
|
|
|
|
|
String serviceRestMetadataJsonConfig = dubboMetadataService.getServiceRestMetadata();
|
|
|
|
|
if (hasText(serviceRestMetadataJsonConfig)) {
|
|
|
|
|
metadata = objectMapper.readValue(serviceRestMetadataJsonConfig,
|
|
|
|
|
TypeFactory.defaultInstance().constructCollectionType(LinkedHashSet.class, ServiceRestMetadata.class));
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
if (logger.isErrorEnabled()) {
|
|
|
|
|
logger.error(e.getMessage(), e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return metadata;
|
|
|
|
@ -292,8 +464,16 @@ public class DubboServiceMetadataRepository {
|
|
|
|
|
|
|
|
|
|
private void initSubscribedServices() {
|
|
|
|
|
// If subscribes all services
|
|
|
|
|
if (ALL_DUBBO_SERVICES.equalsIgnoreCase(dubboCloudProperties.getSubscribedServices())) {
|
|
|
|
|
subscribedServices = new HashSet<>(discoveryClient.getServices());
|
|
|
|
|
if (ALL_DUBBO_SERVICES.equals(dubboCloudProperties.getSubscribedServices())) {
|
|
|
|
|
List<String> services = discoveryClient.getServices();
|
|
|
|
|
subscribedServices = new HashSet<>(services);
|
|
|
|
|
if (logger.isWarnEnabled()) {
|
|
|
|
|
logger.warn("Current application will subscribe all services(size:{}) in registry, " +
|
|
|
|
|
"a lot of memory and CPU cycles may be used, " +
|
|
|
|
|
"thus it's strongly recommend you using the externalized property '{}' " +
|
|
|
|
|
"to specify the services",
|
|
|
|
|
subscribedServices.size(), "dubbo.cloud.subscribed-services");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
subscribedServices = new HashSet<>(dubboCloudProperties.subscribedServices());
|
|
|
|
|
}
|
|
|
|
@ -305,23 +485,33 @@ public class DubboServiceMetadataRepository {
|
|
|
|
|
subscribedServices.remove(currentApplicationName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initDubboServiceKeysRepository() {
|
|
|
|
|
private void initSubscribedDubboMetadataServices() {
|
|
|
|
|
// clear subscribedDubboMetadataServiceURLs
|
|
|
|
|
subscribedDubboMetadataServiceURLs.clear();
|
|
|
|
|
|
|
|
|
|
subscribedServices.stream()
|
|
|
|
|
.map(discoveryClient::getInstances)
|
|
|
|
|
.filter(this::isNotEmpty)
|
|
|
|
|
.forEach(serviceInstances -> {
|
|
|
|
|
ServiceInstance serviceInstance = serviceInstances.get(0);
|
|
|
|
|
buildURLs(serviceInstance).forEach(url -> {
|
|
|
|
|
String serviceKey = url.getServiceKey();
|
|
|
|
|
String serviceName = url.getParameter(APPLICATION_KEY);
|
|
|
|
|
dubboServiceKeysRepository.put(serviceKey, serviceName);
|
|
|
|
|
getDubboMetadataServiceURLs(serviceInstance).forEach(dubboMetadataServiceURL -> {
|
|
|
|
|
initSubscribedDubboMetadataServiceURLs(dubboMetadataServiceURL);
|
|
|
|
|
initDubboMetadataServiceProxy(dubboMetadataServiceURL);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void retainAvailableSubscribedServices() {
|
|
|
|
|
// dubboServiceKeysRepository.values() returns the available services(possible duplicated ones)
|
|
|
|
|
subscribedServices = new HashSet<>(dubboServiceKeysRepository.values());
|
|
|
|
|
private void initSubscribedDubboMetadataServiceURLs(URL dubboMetadataServiceURL) {
|
|
|
|
|
// add subscriptions
|
|
|
|
|
String serviceKey = dubboMetadataServiceURL.getServiceKey();
|
|
|
|
|
subscribedDubboMetadataServiceURLs.add(serviceKey, dubboMetadataServiceURL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initDubboMetadataServiceProxy(URL dubboMetadataServiceURL) {
|
|
|
|
|
String serviceName = dubboMetadataServiceURL.getParameter(APPLICATION_KEY);
|
|
|
|
|
String version = dubboMetadataServiceURL.getParameter(VERSION_KEY);
|
|
|
|
|
// Initialize DubboMetadataService with right version
|
|
|
|
|
dubboMetadataConfigServiceProxy.initProxy(serviceName, version);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initDubboRestServiceMetadataRepository() {
|
|
|
|
|