diff --git a/common/constant/key.go b/common/constant/key.go index 9f2fe14786d5704e9fbc00b925c12e5ad916e122..d353573e78e9bd9ab1e54b614b0523bfbee901d4 100644 --- a/common/constant/key.go +++ b/common/constant/key.go @@ -215,6 +215,9 @@ const ( KEY_SEPARATOR = ":" DEFAULT_PATH_TAG = "metadata" KEY_REVISON_PREFIX = "revision" + + // metadata service + METADATA_SERVICE_NAME = "org.apache.dubbo.metadata.MetadataService" ) // HealthCheck Router diff --git a/metadata/namemapping/dynamic/service_name_mapping.go b/metadata/namemapping/dynamic/service_name_mapping.go index dfa672e95b2d1c0d0f31272af562026a1a768bf0..e93c256fe093b4a3e3c431e1d012038b2bb7976b 100644 --- a/metadata/namemapping/dynamic/service_name_mapping.go +++ b/metadata/namemapping/dynamic/service_name_mapping.go @@ -28,6 +28,7 @@ import ( ) import ( + "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/config" "github.com/apache/dubbo-go/config_center" "github.com/apache/dubbo-go/metadata" @@ -36,9 +37,6 @@ import ( const ( defaultGroup = config_center.DEFAULT_GROUP slash = "/" - - // metadata service is the admin service, should not be mapped - metadataService = "org.apache.dubbo.metadata.MetadataService" ) // DynamicConfigurationServiceNameMapping is the implementation based on config center @@ -48,7 +46,8 @@ type DynamicConfigurationServiceNameMapping struct { // Map will map the service to this application-level service func (d *DynamicConfigurationServiceNameMapping) Map(serviceInterface string, group string, version string, protocol string) error { - if metadataService == serviceInterface { + // metadata service is admin service, should not be mapped + if constant.METADATA_SERVICE_NAME == serviceInterface { return perrors.New("try to map the metadata service, will be ignored") } @@ -56,7 +55,7 @@ func (d *DynamicConfigurationServiceNameMapping) Map(serviceInterface string, gr value := time.Now().UnixNano() err := d.dc.PublishConfig(appName, - d.buildGroup(serviceInterface, group, version, protocol), + d.buildGroup(serviceInterface), strconv.FormatInt(value, 10)) if err != nil { return perrors.WithStack(err) @@ -67,17 +66,13 @@ func (d *DynamicConfigurationServiceNameMapping) Map(serviceInterface string, gr // Get will return the application-level services. If not found, the empty set will be returned. // if the dynamic configuration got error, the error will return func (d *DynamicConfigurationServiceNameMapping) Get(serviceInterface string, group string, version string, protocol string) (*gxset.HashSet, error) { - return d.dc.GetConfigKeysByGroup(d.buildGroup(serviceInterface, group, version, protocol)) + return d.dc.GetConfigKeysByGroup(d.buildGroup(serviceInterface)) } // buildGroup will return group, now it looks like defaultGroup/serviceInterface -func (d *DynamicConfigurationServiceNameMapping) buildGroup( - serviceInterface string, - group string, - version string, - protocol string) string { +func (d *DynamicConfigurationServiceNameMapping) buildGroup(serviceInterface string) string { // the issue : https://github.com/apache/dubbo/issues/4671 - // so other params are ignored + // so other params are ignored and remove, including group string, version string, protocol string return defaultGroup + slash + serviceInterface } diff --git a/metadata/namemapping/dynamic/service_name_mapping_test.go b/metadata/namemapping/dynamic/service_name_mapping_test.go index 81fe350bcfebe5d36df03fc471d579640d9b642c..e3d620cd738421c256d8fd232b1afcfd425ca989 100644 --- a/metadata/namemapping/dynamic/service_name_mapping_test.go +++ b/metadata/namemapping/dynamic/service_name_mapping_test.go @@ -27,6 +27,7 @@ import ( ) import ( + "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/config" "github.com/apache/dubbo-go/config_center" ) @@ -41,7 +42,7 @@ func TestDynamicConfigurationServiceNameMapping(t *testing.T) { config.GetApplicationConfig().Name = appName mapping := NewServiceNameMapping(dc) - intf := metadataService + intf := constant.METADATA_SERVICE_NAME group := "myGroup" version := "myVersion" protocol := "myProtocol"