Skip to content

Commit

Permalink
fix ServiceNameMapping didn't work problem. (#7723)
Browse files Browse the repository at this point in the history
  • Loading branch information
horizonzy committed May 13, 2021
1 parent e845e16 commit 9633f6b
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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 @@ -82,7 +83,9 @@
import static org.apache.dubbo.common.constants.CommonConstants.REVISION_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_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 @@ -216,7 +219,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 = SERVICE_REGISTRY_PROTOCOL.equals(url.getProtocol());
boolean isServiceDiscovery = UrlUtils.isServiceDiscoveryRegistryType(url);
if (isServiceDiscovery) {
Map<String, String> parameters = getApplication().getParameters();
ServiceNameMapping.getExtension(parameters != null ? parameters.get(MAPPING_KEY) : null).map(url);
Expand Down Expand Up @@ -482,6 +485,10 @@ private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List<URL> r
if (!SCOPE_LOCAL.equalsIgnoreCase(scope)) {
if (CollectionUtils.isNotEmpty(registryURLs)) {
for (URL registryURL : registryURLs) {
if (SERVICE_REGISTRY_PROTOCOL.equals(registryURL.getProtocol())) {
url = url.addParameterIfAbsent(REGISTRY_TYPE_KEY, SERVICE_REGISTRY_TYPE);
}

//if protocol is only injvm ,not register
if (LOCAL_PROTOCOL.equalsIgnoreCase(url.getProtocol())) {
continue;
Expand Down Expand Up @@ -747,7 +754,7 @@ public void setBootstrap(DubboBootstrap bootstrap) {

public String getServiceName() {

if(!StringUtils.isBlank(serviceName)){
if (!StringUtils.isBlank(serviceName)) {
return serviceName;
}
String generateVersion = version;
Expand Down

0 comments on commit 9633f6b

Please sign in to comment.