mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Polish alibaba/spring-cloud-alibaba#1739 : Sync the Dubbo from master
This commit is contained in:
parent
300478612f
commit
d50beeccf2
@ -92,7 +92,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.zookeeper</groupId>
|
||||
<artifactId>zookeeper</artifactId>
|
||||
<version>3.4.12</version>
|
||||
<version>3.4.14</version>
|
||||
<optional>true</optional>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
|
@ -49,18 +49,7 @@ public class DubboServiceAutoConfiguration {
|
||||
return new DubboGenericServiceFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a primary {@link PropertyResolver} bean to {@link Autowired @Autowired}.
|
||||
* @param environment {@link Environment}
|
||||
* @return alias bean for {@link Environment}
|
||||
*/
|
||||
@Bean
|
||||
@Primary
|
||||
public PropertyResolver primaryPropertyResolver(Environment environment) {
|
||||
return environment;
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@Import({ DubboGenericServiceExecutionContextFactory.class,
|
||||
RequestParamServiceParameterResolver.class,
|
||||
RequestBodyServiceParameterResolver.class,
|
||||
|
@ -33,6 +33,7 @@ import com.alibaba.cloud.dubbo.registry.AbstractSpringCloudRegistry;
|
||||
import com.alibaba.cloud.dubbo.registry.event.ServiceInstancesChangedEvent;
|
||||
import com.alibaba.cloud.dubbo.registry.event.SubscribedServicesChangedEvent;
|
||||
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
||||
import com.alibaba.cloud.nacos.NacosServiceManager;
|
||||
import com.alibaba.cloud.nacos.discovery.NacosWatch;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.api.naming.NamingService;
|
||||
@ -517,8 +518,10 @@ public class DubboServiceDiscoveryAutoConfiguration {
|
||||
*/
|
||||
private final Set<String> listeningServices;
|
||||
|
||||
NacosConfiguration(NacosDiscoveryProperties nacosDiscoveryProperties) {
|
||||
this.namingService = nacosDiscoveryProperties.namingServiceInstance();
|
||||
NacosConfiguration(NacosServiceManager nacosServiceManager,
|
||||
NacosDiscoveryProperties nacosDiscoveryProperties) {
|
||||
this.namingService = nacosServiceManager
|
||||
.getNamingService(nacosDiscoveryProperties.getNacosProperties());
|
||||
this.nacosDiscoveryProperties = nacosDiscoveryProperties;
|
||||
this.listeningServices = new ConcurrentSkipListSet<>();
|
||||
}
|
||||
|
@ -75,12 +75,17 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration {
|
||||
|
||||
@Around("execution(* org.springframework.cloud.client.serviceregistry.Registration.getPort())")
|
||||
public Object getPort(ProceedingJoinPoint pjp) throws Throwable {
|
||||
/**
|
||||
* move setServerPort from onApplicationStarted() to here for this issue :
|
||||
* https://github.com/alibaba/spring-cloud-alibaba/issues/1383
|
||||
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
||||
*/
|
||||
setServerPort();
|
||||
return serverPort != null ? serverPort : pjp.proceed();
|
||||
}
|
||||
|
||||
@EventListener(ApplicationStartedEvent.class)
|
||||
public void onApplicationStarted() {
|
||||
setServerPort();
|
||||
register();
|
||||
}
|
||||
|
||||
@ -98,18 +103,22 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration {
|
||||
*/
|
||||
private void setServerPort() {
|
||||
if (serverPort == null) {
|
||||
for (List<URL> urls : repository.getAllExportedUrls().values()) {
|
||||
urls.stream()
|
||||
.filter(url -> REST_PROTOCOL.equalsIgnoreCase(url.getProtocol()))
|
||||
synchronized (this) {
|
||||
if (serverPort == null) {
|
||||
for (List<URL> urls : repository.getAllExportedUrls().values()) {
|
||||
urls.stream().filter(
|
||||
url -> REST_PROTOCOL.equalsIgnoreCase(url.getProtocol()))
|
||||
.findFirst().ifPresent(url -> {
|
||||
serverPort = url.getPort();
|
||||
});
|
||||
|
||||
// If REST protocol is not present, use any applied port.
|
||||
if (serverPort == null) {
|
||||
urls.stream().findAny().ifPresent(url -> {
|
||||
serverPort = url.getPort();
|
||||
});
|
||||
// If REST protocol is not present, use any applied port.
|
||||
if (serverPort == null) {
|
||||
urls.stream().findAny().ifPresent(url -> {
|
||||
serverPort = url.getPort();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -125,6 +134,7 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration {
|
||||
@EventListener(ServiceInstancePreRegisteredEvent.class)
|
||||
public void onServiceInstancePreRegistered(
|
||||
ServiceInstancePreRegisteredEvent event) {
|
||||
setServerPort();
|
||||
registration.setPort(serverPort);
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,6 @@ public class DubboProtocolConfigSupplier implements Supplier<ProtocolConfig> {
|
||||
if (protocolConfig == null) {
|
||||
protocolConfig = new ProtocolConfig();
|
||||
protocolConfig.setName(DEFAULT_PROTOCOL);
|
||||
protocolConfig.setPort(-1);
|
||||
}
|
||||
|
||||
return protocolConfig;
|
||||
|
@ -29,7 +29,7 @@ import org.springframework.cloud.client.ServiceInstance;
|
||||
public interface ServiceInstanceSelector {
|
||||
|
||||
/**
|
||||
* choose a service instance to get metadata.
|
||||
* Select a service instance to get metadata.
|
||||
* @param serviceInstances all service instance
|
||||
* @return the service instance to get metadata
|
||||
*/
|
||||
|
@ -16,14 +16,14 @@
|
||||
|
||||
package com.alibaba.cloud.dubbo.registry.event;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.event.ApplicationEventMulticaster;
|
||||
import org.springframework.context.event.SimpleApplicationEventMulticaster;
|
||||
|
||||
import static java.util.Collections.unmodifiableCollection;
|
||||
import static java.util.Collections.unmodifiableList;
|
||||
|
||||
/**
|
||||
* An event raised after the {@link ServiceInstance instances} of one service has been
|
||||
@ -35,7 +35,7 @@ public class ServiceInstancesChangedEvent extends ApplicationEvent {
|
||||
|
||||
private final String serviceName;
|
||||
|
||||
private final Collection<ServiceInstance> serviceInstances;
|
||||
private final List<ServiceInstance> serviceInstances;
|
||||
|
||||
/**
|
||||
* Current event has been processed or not. Typically, Spring Event was based on sync
|
||||
@ -51,10 +51,10 @@ public class ServiceInstancesChangedEvent extends ApplicationEvent {
|
||||
* @throws IllegalArgumentException if source is null.
|
||||
*/
|
||||
public ServiceInstancesChangedEvent(String serviceName,
|
||||
Collection<ServiceInstance> serviceInstances) {
|
||||
List<ServiceInstance> serviceInstances) {
|
||||
super(serviceName);
|
||||
this.serviceName = serviceName;
|
||||
this.serviceInstances = unmodifiableCollection(serviceInstances);
|
||||
this.serviceInstances = unmodifiableList(serviceInstances);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -67,7 +67,7 @@ public class ServiceInstancesChangedEvent extends ApplicationEvent {
|
||||
/**
|
||||
* @return all {@link ServiceInstance service instances}.
|
||||
*/
|
||||
public Collection<ServiceInstance> getServiceInstances() {
|
||||
public List<ServiceInstance> getServiceInstances() {
|
||||
return serviceInstances;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user