Skip to content

Commit

Permalink
use service name mapping key to avoid logic conflict. (#8184)
Browse files Browse the repository at this point in the history
  • Loading branch information
horizonzy committed Jul 2, 2021
1 parent 21b08f0 commit c5a4597
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Expand Up @@ -414,4 +414,5 @@ public interface CommonConstants {

String DISPATHER = "dispather";

String SERVICE_NAME_MAPPING_KEY = "service-name-mapping";
}
Expand Up @@ -27,7 +27,6 @@
import org.apache.dubbo.common.utils.ConfigUtils;
import org.apache.dubbo.common.utils.NamedThreadFactory;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.common.utils.UrlUtils;
import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.event.ServiceConfigExportedEvent;
Expand Down Expand Up @@ -81,12 +80,11 @@
import static org.apache.dubbo.common.constants.CommonConstants.REGISTER_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.REMOTE_METADATA_STORAGE_TYPE;
import static org.apache.dubbo.common.constants.CommonConstants.REVISION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.SERVICE_NAME_MAPPING_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.DYNAMIC_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTRY_TYPE_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.SERVICE_REGISTRY_PROTOCOL;
import static org.apache.dubbo.common.constants.RegistryConstants.SERVICE_REGISTRY_TYPE;
import static org.apache.dubbo.common.utils.NetUtils.getAvailablePort;
import static org.apache.dubbo.common.utils.NetUtils.getLocalHost;
import static org.apache.dubbo.common.utils.NetUtils.isInvalidLocalHost;
Expand Down Expand Up @@ -254,8 +252,7 @@ public void exported() {
exportedURLs.forEach(url -> {
// dubbo2.7.x does not register serviceNameMapping information with the registry by default.
// Only when the user manually turns on the service introspection, can he register with the registration center.
boolean isServiceDiscovery = UrlUtils.isServiceDiscoveryRegistryType(url);
if (isServiceDiscovery) {
if (url.getParameters().containsKey(SERVICE_NAME_MAPPING_KEY)) {
Map<String, String> parameters = getApplication().getParameters();
ServiceNameMapping.getExtension(parameters != null ? parameters.get(MAPPING_KEY) : null).map(url);
}
Expand Down Expand Up @@ -493,7 +490,7 @@ private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List<URL> r
if (CollectionUtils.isNotEmpty(registryURLs)) {
for (URL registryURL : registryURLs) {
if (SERVICE_REGISTRY_PROTOCOL.equals(registryURL.getProtocol())) {
url = url.addParameterIfAbsent(REGISTRY_TYPE_KEY, SERVICE_REGISTRY_TYPE);
url = url.addParameterIfAbsent(SERVICE_NAME_MAPPING_KEY, "true");
}

//if protocol is only injvm ,not register
Expand Down

0 comments on commit c5a4597

Please sign in to comment.