Merge pull request #515 from mercyblitz/master

Polish spring-cloud-incubator/spring-cloud-alibaba#510 : Reactor code
pull/516/head^2
Mercy Ma 6 years ago committed by GitHub
commit 02e2892f13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -55,7 +55,7 @@ public class SpringCloudRegistry extends AbstractSpringCloudRegistry {
/**
* The parameter name of the services of Dubbo Provider
*/
public static final String DUBBO_PROVIDER_SERVICES_PARAM_NAME = "dubbo.provider-services";
public static final String DUBBO_PROVIDER_SERVICES_PARAM_NAME = "dubbo-provider-services";
/**
* All services of Dubbo Provider

@ -26,6 +26,7 @@ import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.HashMap;
@ -80,7 +81,17 @@ public class DubboNonWebApplicationEnvironmentPostProcessor implements Environme
return;
}
resetServerPort(environment);
MutablePropertySources propertySources = environment.getPropertySources();
Map<String, Object> defaultProperties = createDefaultProperties(environment);
if (!CollectionUtils.isEmpty(defaultProperties)) {
addOrReplace(propertySources, defaultProperties);
}
}
private Map<String, Object> createDefaultProperties(ConfigurableEnvironment environment) {
Map<String, Object> defaultProperties = new HashMap<String, Object>();
resetServerPort(environment, defaultProperties);
return defaultProperties;
}
/**
@ -88,8 +99,9 @@ public class DubboNonWebApplicationEnvironmentPostProcessor implements Environme
* or "dubbo.protcols.rest.port"
*
* @param environment
* @param defaultProperties
*/
private void resetServerPort(ConfigurableEnvironment environment) {
private void resetServerPort(ConfigurableEnvironment environment, Map<String, Object> defaultProperties) {
String serverPort = environment.getProperty(SERVER_PORT_PROPERTY_NAME, environment.getProperty(PORT_PROPERTY_NAME));
@ -103,8 +115,7 @@ public class DubboNonWebApplicationEnvironmentPostProcessor implements Environme
serverPort = getRestPortFromProtocolsProperties(environment);
}
setServerPort(environment, serverPort);
setServerPort(environment, serverPort, defaultProperties);
}
private String getRestPortFromProtocolProperty(ConfigurableEnvironment environment) {
@ -147,17 +158,14 @@ public class DubboNonWebApplicationEnvironmentPostProcessor implements Environme
return index > -1 ? propertyName.substring(0, index) : null;
}
private void setServerPort(ConfigurableEnvironment environment, String serverPort) {
private void setServerPort(ConfigurableEnvironment environment, String serverPort,
Map<String, Object> defaultProperties) {
if (serverPort == null) {
return;
}
MutablePropertySources propertySources = environment.getPropertySources();
Map<String, Object> properties = new HashMap<>();
properties.put(SERVER_PORT_PROPERTY_NAME, String.valueOf(serverPort));
defaultProperties.put(SERVER_PORT_PROPERTY_NAME, serverPort);
addOrReplace(propertySources, properties);
}
/**

@ -1,7 +1,9 @@
dubbo:
registry:
# The Spring Cloud Dubbo's registry extension
address: spring-cloud://localhost
## the default value of dubbo-provider-services is "*", that means to subscribe all providers,
## thus it's optimized if subscriber specifies the required providers.
address: spring-cloud://localhost?dubbo-provider-services=${provider.application.name}
# The traditional Dubbo's registry
# address: zookeeper://127.0.0.1:2181
server:

Loading…
Cancel
Save