mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
parent
b56464c5c7
commit
0485c6d06d
@ -278,8 +278,7 @@ public class DubboServiceMetadataRepository
|
|||||||
serviceName);
|
serviceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (initSubscribedDubboMetadataService(serviceName)) {
|
||||||
if (initSubscribedDubboMetadataService(serviceName)){
|
|
||||||
// mark this service name having been initialized
|
// mark this service name having been initialized
|
||||||
initializedServices.add(serviceName);
|
initializedServices.add(serviceName);
|
||||||
}
|
}
|
||||||
@ -297,9 +296,9 @@ public class DubboServiceMetadataRepository
|
|||||||
synchronized (monitor) {
|
synchronized (monitor) {
|
||||||
initializedServices.remove(serviceName);
|
initializedServices.remove(serviceName);
|
||||||
dubboRestServiceMetadataRepository.remove(serviceName);
|
dubboRestServiceMetadataRepository.remove(serviceName);
|
||||||
// fix #1260 if the subscribedDubboMetadataServiceURLs removed fail,old meta information will be retained
|
// fix #1260 if the subscribedDubboMetadataServiceURLs removed fail,old meta
|
||||||
if( DubboMetadataService.class
|
// information will be retained
|
||||||
.getName().equals(url.getServiceInterface() )) {
|
if (DubboMetadataService.class.getName().equals(url.getServiceInterface())) {
|
||||||
String serviceKey = url.getServiceKey();
|
String serviceKey = url.getServiceKey();
|
||||||
subscribedDubboMetadataServiceURLs.remove(serviceKey);
|
subscribedDubboMetadataServiceURLs.remove(serviceKey);
|
||||||
}
|
}
|
||||||
@ -613,30 +612,34 @@ public class DubboServiceMetadataRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Boolean initSubscribedDubboMetadataService(String serviceName) {
|
protected Boolean initSubscribedDubboMetadataService(String serviceName) {
|
||||||
// this need to judge whether the initialization is successful or not. The failed initialization will not change the initializedServices
|
// this need to judge whether the initialization is successful or not. The failed
|
||||||
Optional<ServiceInstance> optionalServiceInstance = metadataServiceInstanceSelector.choose(discoveryClient.getInstances(serviceName));
|
// initialization will not change the initializedServices
|
||||||
if(!optionalServiceInstance.isPresent() ){
|
Optional<ServiceInstance> optionalServiceInstance = metadataServiceInstanceSelector
|
||||||
|
.choose(discoveryClient.getInstances(serviceName));
|
||||||
|
if (!optionalServiceInstance.isPresent()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ServiceInstance serviceInstance = optionalServiceInstance.get();
|
ServiceInstance serviceInstance = optionalServiceInstance.get();
|
||||||
if(null == serviceInstance ){
|
if (null == serviceInstance) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
List<URL> dubboMetadataServiceURLs = getDubboMetadataServiceURLs(serviceInstance);
|
List<URL> dubboMetadataServiceURLs = getDubboMetadataServiceURLs(serviceInstance);
|
||||||
if(dubboMetadataServiceURLs.isEmpty()){
|
if (dubboMetadataServiceURLs.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for(URL dubboMetadataServiceURL : dubboMetadataServiceURLs){
|
for (URL dubboMetadataServiceURL : dubboMetadataServiceURLs) {
|
||||||
try {
|
try {
|
||||||
initSubscribedDubboMetadataServiceURL(
|
initSubscribedDubboMetadataServiceURL(dubboMetadataServiceURL);
|
||||||
dubboMetadataServiceURL);
|
DubboMetadataService dubboMetadataService = dubboMetadataConfigServiceProxy
|
||||||
DubboMetadataService dubboMetadataService = dubboMetadataConfigServiceProxy.getProxy(serviceName);
|
.getProxy(serviceName);
|
||||||
if(dubboMetadataService == null){
|
if (dubboMetadataService == null) {
|
||||||
dubboMetadataService = initDubboMetadataServiceProxy(dubboMetadataServiceURL);
|
dubboMetadataService = initDubboMetadataServiceProxy(
|
||||||
|
dubboMetadataServiceURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dubboMetadataService == null){
|
if (dubboMetadataService == null) {
|
||||||
removeMetadataAndInitializedService(serviceName, dubboMetadataServiceURL);
|
removeMetadataAndInitializedService(serviceName,
|
||||||
|
dubboMetadataServiceURL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -646,30 +649,6 @@ public class DubboServiceMetadataRepository
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*metadataServiceInstanceSelector.choose(discoveryClient.getInstances(serviceName))
|
|
||||||
.map(this::getDubboMetadataServiceURLs)
|
|
||||||
.ifPresent(dubboMetadataServiceURLs -> {
|
|
||||||
if( dubboMetadataServiceURLs.isEmpty()){
|
|
||||||
initializedServices.remove(serviceName);
|
|
||||||
}else{
|
|
||||||
dubboMetadataServiceURLs.forEach(dubboMetadataServiceURL -> {
|
|
||||||
try {
|
|
||||||
initSubscribedDubboMetadataServiceURL(
|
|
||||||
dubboMetadataServiceURL);
|
|
||||||
DubboMetadataService dubboMetadataService = initDubboMetadataServiceProxy(dubboMetadataServiceURL);
|
|
||||||
if(dubboMetadataService == null){
|
|
||||||
initializedServices.remove(serviceName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Throwable e) {
|
|
||||||
if (logger.isErrorEnabled()) {
|
|
||||||
logger.error(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
});*/
|
|
||||||
initDubboRestServiceMetadataRepository(serviceName);
|
initDubboRestServiceMetadataRepository(serviceName);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -680,7 +659,8 @@ public class DubboServiceMetadataRepository
|
|||||||
subscribedDubboMetadataServiceURLs.add(serviceKey, dubboMetadataServiceURL);
|
subscribedDubboMetadataServiceURLs.add(serviceKey, dubboMetadataServiceURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DubboMetadataService initDubboMetadataServiceProxy(URL dubboMetadataServiceURL) {
|
private DubboMetadataService initDubboMetadataServiceProxy(
|
||||||
|
URL dubboMetadataServiceURL) {
|
||||||
String serviceName = dubboMetadataServiceURL.getParameter(APPLICATION_KEY);
|
String serviceName = dubboMetadataServiceURL.getParameter(APPLICATION_KEY);
|
||||||
String version = dubboMetadataServiceURL.getParameter(VERSION_KEY);
|
String version = dubboMetadataServiceURL.getParameter(VERSION_KEY);
|
||||||
// Initialize DubboMetadataService with right version
|
// Initialize DubboMetadataService with right version
|
||||||
|
@ -153,8 +153,10 @@ public abstract class AbstractSpringCloudRegistry extends FailbackRegistry {
|
|||||||
}
|
}
|
||||||
else if (isDubboMetadataServiceURL(url)) { // for DubboMetadataService
|
else if (isDubboMetadataServiceURL(url)) { // for DubboMetadataService
|
||||||
subscribeDubboMetadataServiceURLs(url, listener);
|
subscribeDubboMetadataServiceURLs(url, listener);
|
||||||
if( from(url).getParameter(CATEGORY_KEY) != null && from(url).getParameter(CATEGORY_KEY).contains(PROVIDER)){
|
if (from(url).getParameter(CATEGORY_KEY) != null
|
||||||
// Fix #1259 and #753 Listene meta service change events to remove useless clients
|
&& from(url).getParameter(CATEGORY_KEY).contains(PROVIDER)) {
|
||||||
|
// Fix #1259 and #753 Listene meta service change events to remove useless
|
||||||
|
// clients
|
||||||
registerServiceInstancesChangedEventListener(url, listener);
|
registerServiceInstancesChangedEventListener(url, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +227,9 @@ public abstract class AbstractSpringCloudRegistry extends FailbackRegistry {
|
|||||||
// Re-obtain the latest list of available metadata address here, ip or port may
|
// Re-obtain the latest list of available metadata address here, ip or port may
|
||||||
// change.
|
// change.
|
||||||
// by https://github.com/wangzihaogithub
|
// by https://github.com/wangzihaogithub
|
||||||
// When the last service provider is closed, 【fix 1259】while close the channel,when up a new provider then repository.initializeMetadata(serviceName) will throw Exception.
|
// When the last service provider is closed, 【fix 1259】while close the
|
||||||
|
// channel,when up a new provider then repository.initializeMetadata(serviceName)
|
||||||
|
// will throw Exception.
|
||||||
// dubboMetadataConfigServiceProxy.removeProxy(serviceName);
|
// dubboMetadataConfigServiceProxy.removeProxy(serviceName);
|
||||||
// repository.removeMetadataAndInitializedService(serviceName);
|
// repository.removeMetadataAndInitializedService(serviceName);
|
||||||
// dubboGenericServiceFactory.destroy(serviceName);
|
// dubboGenericServiceFactory.destroy(serviceName);
|
||||||
@ -237,13 +241,15 @@ public abstract class AbstractSpringCloudRegistry extends FailbackRegistry {
|
|||||||
+ "available , please make sure the further impact",
|
+ "available , please make sure the further impact",
|
||||||
serviceName, url.getServiceKey());
|
serviceName, url.getServiceKey());
|
||||||
}
|
}
|
||||||
if(isDubboMetadataServiceURL(url)){
|
if (isDubboMetadataServiceURL(url)) {
|
||||||
// if meta service change, and serviceInstances is zero, will clean up information about this client
|
// if meta service change, and serviceInstances is zero, will clean up
|
||||||
|
// information about this client
|
||||||
dubboMetadataConfigServiceProxy.removeProxy(serviceName);
|
dubboMetadataConfigServiceProxy.removeProxy(serviceName);
|
||||||
repository.removeMetadataAndInitializedService(serviceName, url);
|
repository.removeMetadataAndInitializedService(serviceName, url);
|
||||||
dubboGenericServiceFactory.destroy(serviceName);
|
dubboGenericServiceFactory.destroy(serviceName);
|
||||||
String listenerId = generateId(url);
|
String listenerId = generateId(url);
|
||||||
// The metaservice will restart the new listener. It needs to be optimized to see whether the original listener can be reused.
|
// The metaservice will restart the new listener. It needs to be optimized
|
||||||
|
// to see whether the original listener can be reused.
|
||||||
this.registerListeners.remove(listenerId);
|
this.registerListeners.remove(listenerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -258,7 +264,7 @@ public abstract class AbstractSpringCloudRegistry extends FailbackRegistry {
|
|||||||
listener.notify(allSubscribedURLs);
|
listener.notify(allSubscribedURLs);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if( isDubboMetadataServiceURL(url) ){
|
if (isDubboMetadataServiceURL(url)) {
|
||||||
// Prevent duplicate generation of DubboMetadataService
|
// Prevent duplicate generation of DubboMetadataService
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -314,9 +320,11 @@ public abstract class AbstractSpringCloudRegistry extends FailbackRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<URL> emptyURLs(URL url) {
|
private List<URL> emptyURLs(URL url) {
|
||||||
// issue : When the last service provider is closed, the client still periodically connects to the last provider.n
|
// issue : When the last service provider is closed, the client still periodically
|
||||||
|
// connects to the last provider.n
|
||||||
// fix https://github.com/alibaba/spring-cloud-alibaba/issues/1259
|
// fix https://github.com/alibaba/spring-cloud-alibaba/issues/1259
|
||||||
return asList(from(url).setProtocol(EMPTY_PROTOCOL).removeParameter(CATEGORY_KEY).build());
|
return asList(from(url).setProtocol(EMPTY_PROTOCOL).removeParameter(CATEGORY_KEY)
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ServiceInstance> getServiceInstances(String serviceName) {
|
private List<ServiceInstance> getServiceInstances(String serviceName) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user