From 5cd89c3a6599864c4716bacb2bc23bd49943e739 Mon Sep 17 00:00:00 2001
From: flycash <mingflycash@gmail.com>
Date: Mon, 8 Jun 2020 23:59:31 +0800
Subject: [PATCH] Add metadata service factory

---
 common/constant/default.go                    |   1 +
 common/extension/metadata_service.go          |   2 +-
 .../metadata_service_proxy_factory.go         |  41 +++++
 config/base_config.go                         |   4 +
 config/config_loader.go                       |  10 +-
 config/consumer_config.go                     |   2 -
 config/provider_config.go                     |   2 -
 config/reference_config.go                    |   2 +
 config_center/nacos/impl.go                   |   2 +-
 .../metadata_service_proxy_factory.go         |  35 ++++
 metadata/service/inmemory/service.go          |  11 +-
 .../remote/metadata_service_proxy_factory.go  |  30 ++++
 metadata/service/remote/service.go            |   7 +-
 metadata/service/remote/service_proxy.go      | 153 ++++++++++++++++++
 metadata/service/service.go                   |  34 ++++
 .../proxy/metadata_service_proxy_factory.go   |  14 +-
 .../servicediscovery/proxy/service_proxy.go   |  11 --
 .../service_discovery_registry.go             |  14 +-
 18 files changed, 333 insertions(+), 42 deletions(-)
 create mode 100644 common/extension/metadata_service_proxy_factory.go
 create mode 100644 metadata/service/inmemory/metadata_service_proxy_factory.go
 create mode 100644 metadata/service/remote/metadata_service_proxy_factory.go
 create mode 100644 metadata/service/remote/service_proxy.go

diff --git a/common/constant/default.go b/common/constant/default.go
index 211bfc06b..45fc38f13 100644
--- a/common/constant/default.go
+++ b/common/constant/default.go
@@ -77,6 +77,7 @@ const (
 
 const (
 	SIMPLE_METADATA_SERVICE_NAME = "MetadataService"
+	DEFAULT_REVIESION            = "N/A"
 )
 
 const (
diff --git a/common/extension/metadata_service.go b/common/extension/metadata_service.go
index c6a165c48..93ff40aa7 100644
--- a/common/extension/metadata_service.go
+++ b/common/extension/metadata_service.go
@@ -36,7 +36,7 @@ func GetMetadataService(msType string) (service.MetadataService, error) {
 	if creator, ok := metadataServiceInsMap[msType]; ok {
 		return creator()
 	}
-	panic(fmt.Sprintf("could not find the creator for metadataType: %s, please check whether you have imported relative packages, \n"+
+	panic(fmt.Sprintf("could not find the metadata service creator for metadataType: %s, please check whether you have imported relative packages, \n"+
 		"local - github.com/apache/dubbo-go/metadata/service/inmemory, \n"+
 		"remote - github.com/apache/dubbo-go/metadata/service/remote", msType))
 }
diff --git a/common/extension/metadata_service_proxy_factory.go b/common/extension/metadata_service_proxy_factory.go
new file mode 100644
index 000000000..35f63c5fa
--- /dev/null
+++ b/common/extension/metadata_service_proxy_factory.go
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package extension
+
+import (
+	"fmt"
+
+	"github.com/apache/dubbo-go/metadata/service"
+)
+
+var (
+	metadataServiceProxyFactoryMap = make(map[string]func() service.MetadataServiceProxyFactory)
+)
+
+func SetMetadataServiceProxyFactory(name string, creator func() service.MetadataServiceProxyFactory) {
+	metadataServiceProxyFactoryMap[name] = creator
+}
+
+func GetMetadataServiceProxyFactory(name string) service.MetadataServiceProxyFactory {
+	if f, ok := metadataServiceProxyFactoryMap[name]; ok {
+		return f()
+	}
+	panic(fmt.Sprintf("could not find the metadata service factory creator for name: %s, please check whether you have imported relative packages, \n"+
+		"local - github.com/apache/dubbo-go/metadata/service/inmemory, \n"+
+		"remote - github.com/apache/dubbo-go/metadata/service/remote", name))
+}
diff --git a/config/base_config.go b/config/base_config.go
index dad4d7f7e..f04a09f49 100644
--- a/config/base_config.go
+++ b/config/base_config.go
@@ -45,6 +45,10 @@ type BaseConfig struct {
 	ConfigCenterConfig *ConfigCenterConfig                `yaml:"config_center" json:"config_center,omitempty"`
 	Remotes            map[string]*RemoteConfig           `yaml:"remote" json:"remote,omitempty"`
 	ServiceDiscoveries map[string]*ServiceDiscoveryConfig `yaml:"service_discovery" json:"service_discovery,omitempty"`
+
+	Registry   *RegistryConfig            `yaml:"registry" json:"registry,omitempty" property:"registry"`
+	Registries map[string]*RegistryConfig `yaml:"registries" json:"registries,omitempty" property:"registries"`
+
 	// application config
 	ApplicationConfig *ApplicationConfig `yaml:"application" json:"application,omitempty" property:"application"`
 
diff --git a/config/config_loader.go b/config/config_loader.go
index 4a293e7a9..7d279ff08 100644
--- a/config/config_loader.go
+++ b/config/config_loader.go
@@ -148,7 +148,7 @@ func loadConsumerConfig() {
 					if count > maxWait {
 						errMsg := fmt.Sprintf("Failed to check the status of the service %v . No provider available for the service to the consumer use dubbo version %v", refconfig.InterfaceName, constant.Version)
 						logger.Error(errMsg)
-						panic(errMsg)
+						// panic(errMsg)
 					}
 					time.Sleep(time.Second * 1)
 					break
@@ -222,13 +222,11 @@ func Load() {
 	extension.SetAndInitGlobalDispatcher(GetBaseConfig().EventDispatcherType)
 
 	// start the metadata report if config set
-	if err := startMetadataReport(providerConfig.ApplicationConfig.MetadataType, providerConfig.MetadataReportConfig); err != nil {
+	if err := startMetadataReport(GetApplicationConfig().MetadataType, GetProviderConfig().MetadataReportConfig); err != nil {
 		logger.Errorf("Provider starts metadata report error, and the error is {%#v}", err)
 		return
 	}
 
-	logger.Debugf("provider config{%#v}\n", providerConfig)
-
 	// reference config
 	loadConsumerConfig()
 
@@ -323,3 +321,7 @@ func GetBaseConfig() *BaseConfig {
 	}
 	return baseConfig
 }
+
+func IsProvider() bool {
+	return providerConfig != nil
+}
diff --git a/config/consumer_config.go b/config/consumer_config.go
index bee9b1e3f..fd3d30e6f 100644
--- a/config/consumer_config.go
+++ b/config/consumer_config.go
@@ -51,8 +51,6 @@ type ConsumerConfig struct {
 	ProxyFactory    string `yaml:"proxy_factory" default:"default" json:"proxy_factory,omitempty" property:"proxy_factory"`
 	Check           *bool  `yaml:"check"  json:"check,omitempty" property:"check"`
 
-	Registry       *RegistryConfig             `yaml:"registry" json:"registry,omitempty" property:"registry"`
-	Registries     map[string]*RegistryConfig  `yaml:"registries" json:"registries,omitempty" property:"registries"`
 	References     map[string]*ReferenceConfig `yaml:"references" json:"references,omitempty" property:"references"`
 	ProtocolConf   interface{}                 `yaml:"protocol_conf" json:"protocol_conf,omitempty" property:"protocol_conf"`
 	FilterConf     interface{}                 `yaml:"filter_conf" json:"filter_conf,omitempty" property:"filter_conf" `
diff --git a/config/provider_config.go b/config/provider_config.go
index 0f14c9f1d..99c532a38 100644
--- a/config/provider_config.go
+++ b/config/provider_config.go
@@ -42,8 +42,6 @@ type ProviderConfig struct {
 	ProxyFactory string `yaml:"proxy_factory" default:"default" json:"proxy_factory,omitempty" property:"proxy_factory"`
 	// metadata-report
 	MetadataReportConfig *MetadataReportConfig      `yaml:"metadata_report" json:"metadata_report,omitempty" property:"metadata_report"`
-	Registry             *RegistryConfig            `yaml:"registry" json:"registry,omitempty" property:"registry"`
-	Registries           map[string]*RegistryConfig `yaml:"registries" json:"registries,omitempty" property:"registries"`
 	Services             map[string]*ServiceConfig  `yaml:"services" json:"services,omitempty" property:"services"`
 	Protocols            map[string]*ProtocolConfig `yaml:"protocols" json:"protocols,omitempty" property:"protocols"`
 	ProtocolConf         interface{}                `yaml:"protocol_conf" json:"protocol_conf,omitempty" property:"protocol_conf" `
diff --git a/config/reference_config.go b/config/reference_config.go
index f343a9a23..e935c7646 100644
--- a/config/reference_config.go
+++ b/config/reference_config.go
@@ -55,6 +55,7 @@ type ReferenceConfig struct {
 	Retries        string            `yaml:"retries"  json:"retries,omitempty" property:"retries"`
 	Group          string            `yaml:"group"  json:"group,omitempty" property:"group"`
 	Version        string            `yaml:"version"  json:"version,omitempty" property:"version"`
+	ProvideBy      string            `yaml:"provide_by"  json:"provide_by,omitempty" property:"provide_by"`
 	Methods        []*MethodConfig   `yaml:"methods"  json:"methods,omitempty" property:"methods"`
 	Async          bool              `yaml:"async"  json:"async,omitempty" property:"async"`
 	Params         map[string]string `yaml:"params"  json:"params,omitempty" property:"params"`
@@ -190,6 +191,7 @@ func (c *ReferenceConfig) getUrlMap() url.Values {
 	urlMap.Set(constant.VERSION_KEY, c.Version)
 	urlMap.Set(constant.GENERIC_KEY, strconv.FormatBool(c.Generic))
 	urlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.CONSUMER))
+	urlMap.Set(constant.PROVIDER_BY, c.ProvideBy)
 
 	urlMap.Set(constant.RELEASE_KEY, "dubbo-golang-"+constant.Version)
 	urlMap.Set(constant.SIDE_KEY, (common.RoleType(common.CONSUMER)).Role())
diff --git a/config_center/nacos/impl.go b/config_center/nacos/impl.go
index 0b8aceb23..b4a7a5467 100644
--- a/config_center/nacos/impl.go
+++ b/config_center/nacos/impl.go
@@ -125,7 +125,7 @@ func (n *nacosDynamicConfiguration) GetConfigKeysByGroup(group string) (*gxset.H
 		return result, perrors.WithMessage(err, "can not find the client config")
 	}
 	for _, itm := range page.PageItems {
-		result.Add(itm.Content)
+		result.Add(itm.Appname)
 	}
 	return result, nil
 }
diff --git a/metadata/service/inmemory/metadata_service_proxy_factory.go b/metadata/service/inmemory/metadata_service_proxy_factory.go
new file mode 100644
index 000000000..813ed7513
--- /dev/null
+++ b/metadata/service/inmemory/metadata_service_proxy_factory.go
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package inmemory
+
+import (
+	"github.com/apache/dubbo-go/common/extension"
+	"github.com/apache/dubbo-go/metadata/service"
+	"github.com/apache/dubbo-go/registry"
+)
+
+func init() {
+	factory := service.NewBaseMetadataServiceProxyFactory(createProxy)
+	extension.SetMetadataServiceProxyFactory(local, func() service.MetadataServiceProxyFactory {
+		return factory
+	})
+}
+
+func createProxy(ins registry.ServiceInstance) service.MetadataService {
+	return nil
+}
diff --git a/metadata/service/inmemory/service.go b/metadata/service/inmemory/service.go
index c9d2ed47b..b0782fa3d 100644
--- a/metadata/service/inmemory/service.go
+++ b/metadata/service/inmemory/service.go
@@ -37,13 +37,16 @@ import (
 	"github.com/apache/dubbo-go/metadata/service"
 )
 
+// version will be used by Version func
+const (
+	version = "1.0.0"
+	local   = "local"
+)
+
 func init() {
-	extension.SetMetadataService("local", NewMetadataService)
+	extension.SetMetadataService(local, NewMetadataService)
 }
 
-// version will be used by Version func
-const version = "1.0.0"
-
 // MetadataService is store and query the metadata info in memory when each service registry
 type MetadataService struct {
 	service.BaseMetadataService
diff --git a/metadata/service/remote/metadata_service_proxy_factory.go b/metadata/service/remote/metadata_service_proxy_factory.go
new file mode 100644
index 000000000..a1a859428
--- /dev/null
+++ b/metadata/service/remote/metadata_service_proxy_factory.go
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package remote
+
+import (
+	"github.com/apache/dubbo-go/common/extension"
+	"github.com/apache/dubbo-go/metadata/service"
+)
+
+func init() {
+	factory := service.NewBaseMetadataServiceProxyFactory(newMetadataServiceProxy)
+	extension.SetMetadataServiceProxyFactory(remote, func() service.MetadataServiceProxyFactory {
+		return factory
+	})
+}
diff --git a/metadata/service/remote/service.go b/metadata/service/remote/service.go
index 2e8f66444..19f0c021d 100644
--- a/metadata/service/remote/service.go
+++ b/metadata/service/remote/service.go
@@ -38,10 +38,13 @@ import (
 )
 
 // version will be used by Version func
-const version = "1.0.0"
+const (
+	version = "1.0.0"
+	remote  = "remote"
+)
 
 func init() {
-	extension.SetMetadataService("remote", newMetadataService)
+	extension.SetMetadataService(remote, newMetadataService)
 }
 
 // MetadataService is a implement of metadata service which will delegate the remote metadata report
diff --git a/metadata/service/remote/service_proxy.go b/metadata/service/remote/service_proxy.go
new file mode 100644
index 000000000..090e8edc3
--- /dev/null
+++ b/metadata/service/remote/service_proxy.go
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package remote
+
+import (
+	"strings"
+
+	"github.com/apache/dubbo-go/common"
+	"github.com/apache/dubbo-go/common/constant"
+	"github.com/apache/dubbo-go/common/logger"
+	"github.com/apache/dubbo-go/config/instance"
+	"github.com/apache/dubbo-go/metadata/identifier"
+	"github.com/apache/dubbo-go/metadata/report"
+	"github.com/apache/dubbo-go/metadata/service"
+	"github.com/apache/dubbo-go/registry"
+)
+
+type metadataServiceProxy struct {
+	serviceName string
+	revision    string
+	report      report.MetadataReport
+}
+
+func (m *metadataServiceProxy) Reference() string {
+	return constant.METADATA_SERVICE_NAME
+}
+
+func (m *metadataServiceProxy) ServiceName() (string, error) {
+	return m.serviceName, nil
+}
+
+func (m *metadataServiceProxy) ExportURL(url common.URL) (bool, error) {
+	logger.Errorf("you should never invoke this implementation")
+	return true, nil
+}
+
+func (m *metadataServiceProxy) UnexportURL(url common.URL) error {
+	logger.Errorf("you should never invoke this implementation")
+	return nil
+}
+
+func (m *metadataServiceProxy) SubscribeURL(url common.URL) (bool, error) {
+	logger.Errorf("you should never invoke this implementation")
+	return true, nil
+}
+
+func (m *metadataServiceProxy) UnsubscribeURL(url common.URL) error {
+	logger.Errorf("you should never invoke this implementation")
+	return nil
+}
+
+func (m *metadataServiceProxy) PublishServiceDefinition(url common.URL) error {
+	logger.Errorf("you should never invoke this implementation")
+	return nil
+}
+
+func (m *metadataServiceProxy) GetExportedURLs(serviceInterface string, group string, version string, protocol string) ([]common.URL, error) {
+	urls := m.report.GetExportedURLs(&identifier.ServiceMetadataIdentifier{
+		BaseMetadataIdentifier: identifier.BaseMetadataIdentifier{
+			ServiceInterface: serviceInterface,
+			Version:          version,
+			Group:            group,
+			Side:             constant.PROVIDER_PROTOCOL,
+		},
+		Revision: m.revision,
+		Protocol: protocol,
+	})
+	res := make([]common.URL, 0, len(urls))
+	for _, s := range urls {
+		u, err := common.NewURL(s)
+		if err != nil {
+			logger.Errorf("could not parse the url string to URL structure", err)
+			continue
+		}
+		res = append(res, u)
+	}
+	return res, nil
+}
+
+func (m *metadataServiceProxy) GetSubscribedURLs() ([]common.URL, error) {
+	logger.Errorf("you should never invoke this implementation")
+	return []common.URL{}, nil
+}
+
+func (m *metadataServiceProxy) GetServiceDefinition(interfaceName string, group string, version string) (string, error) {
+	return m.report.GetServiceDefinition(&identifier.MetadataIdentifier{
+		BaseMetadataIdentifier: identifier.BaseMetadataIdentifier{
+			ServiceInterface: interfaceName,
+			Group:            group,
+			Version:          version,
+			Side:             constant.PROVIDER_PROTOCOL,
+		},
+		Application: m.serviceName,
+	}), nil
+}
+
+func (m *metadataServiceProxy) GetServiceDefinitionByServiceKey(serviceKey string) (string, error) {
+	params := parse(serviceKey)
+	return m.GetServiceDefinition(params[0], params[1], params[2])
+}
+
+func (m *metadataServiceProxy) RefreshMetadata(exportedRevision string, subscribedRevision string) (bool, error) {
+	logger.Errorf("you should never invoke this implementation")
+	return true, nil
+}
+
+func (m metadataServiceProxy) Version() (string, error) {
+	return version, nil
+}
+
+func newMetadataServiceProxy(ins registry.ServiceInstance) service.MetadataService {
+	revision := ins.GetMetadata()[constant.EXPORTED_SERVICES_REVISION_PROPERTY_NAME]
+	if len(revision) == 0 {
+		revision = constant.DEFAULT_REVIESION
+	}
+
+	return &metadataServiceProxy{
+		serviceName: ins.GetServiceName(),
+		revision:    revision,
+		report:      instance.GetMetadataReportInstance(),
+	}
+}
+
+func parse(key string) []string {
+	arr := make([]string, 0, 3)
+	tmp := strings.SplitN(key, "/", 2)
+	if len(tmp) > 1 {
+		arr[0] = tmp[0]
+		key = tmp[1]
+	}
+	tmp = strings.SplitN(key, "/", 2)
+	if len(tmp) > 1 {
+		arr[2] = tmp[1]
+		key = tmp[0]
+	}
+	arr[1] = key
+	return arr
+}
diff --git a/metadata/service/service.go b/metadata/service/service.go
index e05b634f8..fc76eca68 100644
--- a/metadata/service/service.go
+++ b/metadata/service/service.go
@@ -18,8 +18,11 @@
 package service
 
 import (
+	"sync"
+
 	"github.com/apache/dubbo-go/common"
 	"github.com/apache/dubbo-go/common/constant"
+	"github.com/apache/dubbo-go/registry"
 )
 
 // MetadataService is used to define meta data related behaviors
@@ -74,3 +77,34 @@ func (mts *BaseMetadataService) ServiceName() (string, error) {
 func (mts *BaseMetadataService) Reference() string {
 	return constant.SIMPLE_METADATA_SERVICE_NAME
 }
+
+type MetadataServiceProxyFactory interface {
+	GetProxy(ins registry.ServiceInstance) MetadataService
+}
+
+type MetadataServiceProxyCreator func(ins registry.ServiceInstance) MetadataService
+
+type BaseMetadataServiceProxyFactory struct {
+	proxies sync.Map
+	creator MetadataServiceProxyCreator
+}
+
+func NewBaseMetadataServiceProxyFactory(creator MetadataServiceProxyCreator) *BaseMetadataServiceProxyFactory {
+	return &BaseMetadataServiceProxyFactory{
+		creator: creator,
+	}
+}
+
+func (b *BaseMetadataServiceProxyFactory) GetProxy(ins registry.ServiceInstance) MetadataService {
+	key := ins.GetServiceName() + "##" + getExportedServicesRevision(ins)
+	if proxy, ok := b.proxies.Load(key); ok {
+		return proxy.(MetadataService)
+	}
+	v, _ := b.proxies.LoadOrStore(key, b.creator(ins))
+	return v.(MetadataService)
+}
+
+func getExportedServicesRevision(serviceInstance registry.ServiceInstance) string {
+	metaData := serviceInstance.GetMetadata()
+	return metaData[constant.EXPORTED_SERVICES_REVISION_PROPERTY_NAME]
+}
diff --git a/registry/servicediscovery/proxy/metadata_service_proxy_factory.go b/registry/servicediscovery/proxy/metadata_service_proxy_factory.go
index 7e8d891bf..6851f4bb7 100644
--- a/registry/servicediscovery/proxy/metadata_service_proxy_factory.go
+++ b/registry/servicediscovery/proxy/metadata_service_proxy_factory.go
@@ -17,15 +17,7 @@
 
 package proxy
 
-var (
-	serviceProxy = make(map[string]func() BaseMetadataServiceProxy)
+import (
+	"github.com/apache/dubbo-go/metadata/service"
+	"github.com/apache/dubbo-go/registry"
 )
-
-func SetMetadataServiceProxy(name string, creator func() BaseMetadataServiceProxy) {
-	//TODO
-}
-
-func GetMetadataServiceProxy(name string) BaseMetadataServiceProxy {
-	//TODO
-	return nil
-}
diff --git a/registry/servicediscovery/proxy/service_proxy.go b/registry/servicediscovery/proxy/service_proxy.go
index 7a14201fd..6555874dd 100644
--- a/registry/servicediscovery/proxy/service_proxy.go
+++ b/registry/servicediscovery/proxy/service_proxy.go
@@ -16,14 +16,3 @@
  */
 
 package proxy
-
-import (
-	"github.com/apache/dubbo-go/metadata/service"
-	"github.com/apache/dubbo-go/registry"
-)
-
-type BaseMetadataServiceProxy interface {
-	GetProxy(serviceInstance registry.ServiceInstance) service.MetadataService
-
-	CreateProxy(serviceInstance registry.ServiceInstance) service.MetadataService
-}
diff --git a/registry/servicediscovery/service_discovery_registry.go b/registry/servicediscovery/service_discovery_registry.go
index aad4b2641..133827d5e 100644
--- a/registry/servicediscovery/service_discovery_registry.go
+++ b/registry/servicediscovery/service_discovery_registry.go
@@ -40,7 +40,6 @@ import (
 	"github.com/apache/dubbo-go/metadata/service/exporter/configurable"
 	"github.com/apache/dubbo-go/registry"
 	"github.com/apache/dubbo-go/registry/event"
-	"github.com/apache/dubbo-go/registry/servicediscovery/proxy"
 	"github.com/apache/dubbo-go/registry/servicediscovery/synthesizer"
 	"github.com/apache/dubbo-go/remoting"
 )
@@ -407,11 +406,11 @@ func (c comparator) Compare(comp cm.Comparator) int {
 func (s *serviceDiscoveryRegistry) getExportedUrlsByInst(serviceInstance registry.ServiceInstance) []common.URL {
 	var urls []common.URL
 	metadataStorageType := getExportedStoreType(serviceInstance)
-	metadataProxy := proxy.GetMetadataServiceProxy(metadataStorageType)
-	if metadataProxy == nil {
+	proxyFactory := extension.GetMetadataServiceProxyFactory(metadataStorageType)
+	if proxyFactory == nil {
 		return urls
 	}
-	metadataService := metadataProxy.GetProxy(serviceInstance)
+	metadataService := proxyFactory.GetProxy(serviceInstance)
 	if metadataService == nil {
 		return urls
 	}
@@ -665,7 +664,14 @@ func initMetadataService() {
 	if err != nil {
 		logger.Errorf("could not init metadata service", err)
 	}
+
+	// we don't need to expose the metadata service since this is a pure consumer application
+	if !config.IsProvider() {
+		return
+	}
+
 	expt := configurable.NewMetadataServiceExporter(ms)
+
 	err = expt.Export()
 	if err != nil {
 		logger.Errorf("could not export the metadata service", err)
-- 
GitLab