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>
|
<dependency>
|
||||||
<groupId>org.apache.zookeeper</groupId>
|
<groupId>org.apache.zookeeper</groupId>
|
||||||
<artifactId>zookeeper</artifactId>
|
<artifactId>zookeeper</artifactId>
|
||||||
<version>3.4.12</version>
|
<version>3.4.14</version>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
|
@ -49,18 +49,7 @@ public class DubboServiceAutoConfiguration {
|
|||||||
return new DubboGenericServiceFactory();
|
return new DubboGenericServiceFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Configuration(proxyBeanMethods = false)
|
||||||
* 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
|
|
||||||
@Import({ DubboGenericServiceExecutionContextFactory.class,
|
@Import({ DubboGenericServiceExecutionContextFactory.class,
|
||||||
RequestParamServiceParameterResolver.class,
|
RequestParamServiceParameterResolver.class,
|
||||||
RequestBodyServiceParameterResolver.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.ServiceInstancesChangedEvent;
|
||||||
import com.alibaba.cloud.dubbo.registry.event.SubscribedServicesChangedEvent;
|
import com.alibaba.cloud.dubbo.registry.event.SubscribedServicesChangedEvent;
|
||||||
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
||||||
|
import com.alibaba.cloud.nacos.NacosServiceManager;
|
||||||
import com.alibaba.cloud.nacos.discovery.NacosWatch;
|
import com.alibaba.cloud.nacos.discovery.NacosWatch;
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
import com.alibaba.nacos.api.naming.NamingService;
|
import com.alibaba.nacos.api.naming.NamingService;
|
||||||
@ -517,8 +518,10 @@ public class DubboServiceDiscoveryAutoConfiguration {
|
|||||||
*/
|
*/
|
||||||
private final Set<String> listeningServices;
|
private final Set<String> listeningServices;
|
||||||
|
|
||||||
NacosConfiguration(NacosDiscoveryProperties nacosDiscoveryProperties) {
|
NacosConfiguration(NacosServiceManager nacosServiceManager,
|
||||||
this.namingService = nacosDiscoveryProperties.namingServiceInstance();
|
NacosDiscoveryProperties nacosDiscoveryProperties) {
|
||||||
|
this.namingService = nacosServiceManager
|
||||||
|
.getNamingService(nacosDiscoveryProperties.getNacosProperties());
|
||||||
this.nacosDiscoveryProperties = nacosDiscoveryProperties;
|
this.nacosDiscoveryProperties = nacosDiscoveryProperties;
|
||||||
this.listeningServices = new ConcurrentSkipListSet<>();
|
this.listeningServices = new ConcurrentSkipListSet<>();
|
||||||
}
|
}
|
||||||
|
@ -75,12 +75,17 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration {
|
|||||||
|
|
||||||
@Around("execution(* org.springframework.cloud.client.serviceregistry.Registration.getPort())")
|
@Around("execution(* org.springframework.cloud.client.serviceregistry.Registration.getPort())")
|
||||||
public Object getPort(ProceedingJoinPoint pjp) throws Throwable {
|
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();
|
return serverPort != null ? serverPort : pjp.proceed();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventListener(ApplicationStartedEvent.class)
|
@EventListener(ApplicationStartedEvent.class)
|
||||||
public void onApplicationStarted() {
|
public void onApplicationStarted() {
|
||||||
setServerPort();
|
|
||||||
register();
|
register();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,18 +103,22 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration {
|
|||||||
*/
|
*/
|
||||||
private void setServerPort() {
|
private void setServerPort() {
|
||||||
if (serverPort == null) {
|
if (serverPort == null) {
|
||||||
for (List<URL> urls : repository.getAllExportedUrls().values()) {
|
synchronized (this) {
|
||||||
urls.stream()
|
if (serverPort == null) {
|
||||||
.filter(url -> REST_PROTOCOL.equalsIgnoreCase(url.getProtocol()))
|
for (List<URL> urls : repository.getAllExportedUrls().values()) {
|
||||||
|
urls.stream().filter(
|
||||||
|
url -> REST_PROTOCOL.equalsIgnoreCase(url.getProtocol()))
|
||||||
.findFirst().ifPresent(url -> {
|
.findFirst().ifPresent(url -> {
|
||||||
serverPort = url.getPort();
|
serverPort = url.getPort();
|
||||||
});
|
});
|
||||||
|
|
||||||
// If REST protocol is not present, use any applied port.
|
// If REST protocol is not present, use any applied port.
|
||||||
if (serverPort == null) {
|
if (serverPort == null) {
|
||||||
urls.stream().findAny().ifPresent(url -> {
|
urls.stream().findAny().ifPresent(url -> {
|
||||||
serverPort = url.getPort();
|
serverPort = url.getPort();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,6 +134,7 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration {
|
|||||||
@EventListener(ServiceInstancePreRegisteredEvent.class)
|
@EventListener(ServiceInstancePreRegisteredEvent.class)
|
||||||
public void onServiceInstancePreRegistered(
|
public void onServiceInstancePreRegistered(
|
||||||
ServiceInstancePreRegisteredEvent event) {
|
ServiceInstancePreRegisteredEvent event) {
|
||||||
|
setServerPort();
|
||||||
registration.setPort(serverPort);
|
registration.setPort(serverPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,6 @@ public class DubboProtocolConfigSupplier implements Supplier<ProtocolConfig> {
|
|||||||
if (protocolConfig == null) {
|
if (protocolConfig == null) {
|
||||||
protocolConfig = new ProtocolConfig();
|
protocolConfig = new ProtocolConfig();
|
||||||
protocolConfig.setName(DEFAULT_PROTOCOL);
|
protocolConfig.setName(DEFAULT_PROTOCOL);
|
||||||
protocolConfig.setPort(-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return protocolConfig;
|
return protocolConfig;
|
||||||
|
@ -29,7 +29,7 @@ import org.springframework.cloud.client.ServiceInstance;
|
|||||||
public interface ServiceInstanceSelector {
|
public interface ServiceInstanceSelector {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* choose a service instance to get metadata.
|
* Select a service instance to get metadata.
|
||||||
* @param serviceInstances all service instance
|
* @param serviceInstances all service instance
|
||||||
* @return the service instance to get metadata
|
* @return the service instance to get metadata
|
||||||
*/
|
*/
|
||||||
|
@ -16,14 +16,14 @@
|
|||||||
|
|
||||||
package com.alibaba.cloud.dubbo.registry.event;
|
package com.alibaba.cloud.dubbo.registry.event;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.cloud.client.ServiceInstance;
|
import org.springframework.cloud.client.ServiceInstance;
|
||||||
import org.springframework.context.ApplicationEvent;
|
import org.springframework.context.ApplicationEvent;
|
||||||
import org.springframework.context.event.ApplicationEventMulticaster;
|
import org.springframework.context.event.ApplicationEventMulticaster;
|
||||||
import org.springframework.context.event.SimpleApplicationEventMulticaster;
|
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
|
* 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 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
|
* 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.
|
* @throws IllegalArgumentException if source is null.
|
||||||
*/
|
*/
|
||||||
public ServiceInstancesChangedEvent(String serviceName,
|
public ServiceInstancesChangedEvent(String serviceName,
|
||||||
Collection<ServiceInstance> serviceInstances) {
|
List<ServiceInstance> serviceInstances) {
|
||||||
super(serviceName);
|
super(serviceName);
|
||||||
this.serviceName = 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}.
|
* @return all {@link ServiceInstance service instances}.
|
||||||
*/
|
*/
|
||||||
public Collection<ServiceInstance> getServiceInstances() {
|
public List<ServiceInstance> getServiceInstances() {
|
||||||
return serviceInstances;
|
return serviceInstances;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user