Skip to content

Commit

Permalink
Merge pull request #1161 from Patrick0308/feature/3.0-service-discovery
Browse files Browse the repository at this point in the history
Imp: remote service discovery
  • Loading branch information
AlexStocks committed Apr 19, 2021
2 parents 0bd7945 + 4acc46f commit cb51074
Show file tree
Hide file tree
Showing 83 changed files with 2,252 additions and 1,951 deletions.
10 changes: 5 additions & 5 deletions .asf.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
notifications:
commits: commits@dubbo.apache.org
issues: notifications@dubbo.apache.org
pullrequests: notifications@dubbo.apache.org
jira_options: link label link label
notifications:
commits: commits@dubbo.apache.org
issues: notifications@dubbo.apache.org
pullrequests: notifications@dubbo.apache.org
jira_options: link label link label
38 changes: 19 additions & 19 deletions .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
name: Bug Report
about: Report a bug
labels: kind/bug

---

<!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks!
-->


**What happened**:

**What you expected to happen**:

**How to reproduce it (as minimally and precisely as possible)**:

**Anything else we need to know?**:
---
name: Bug Report
about: Report a bug
labels: kind/bug

---

<!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks!
-->


**What happened**:

**What you expected to happen**:

**How to reproduce it (as minimally and precisely as possible)**:

**Anything else we need to know?**:
20 changes: 10 additions & 10 deletions .github/ISSUE_TEMPLATE/enhancement.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
name: Enhancement Request
about: Suggest an enhancement
labels: kind/feature

---
<!-- Please only use this template for submitting enhancement requests -->

**What would you like to be added**:

---
name: Enhancement Request
about: Suggest an enhancement
labels: kind/feature

---
<!-- Please only use this template for submitting enhancement requests -->

**What would you like to be added**:

**Why is this needed**:
3 changes: 2 additions & 1 deletion common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,12 @@ const (
const (
SUBSCRIBED_SERVICE_NAMES_KEY = "subscribed-services"
PROVIDER_BY = "provided-by"
EXPORTED_SERVICES_REVISION_PROPERTY_NAME = "dubbo.exported-services.revision"
EXPORTED_SERVICES_REVISION_PROPERTY_NAME = "dubbo.metadata.revision"
SUBSCRIBED_SERVICES_REVISION_PROPERTY_NAME = "dubbo.subscribed-services.revision"
SERVICE_INSTANCE_SELECTOR = "service-instance-selector"
METADATA_STORAGE_TYPE_PROPERTY_NAME = "dubbo.metadata.storage-type"
DEFAULT_METADATA_STORAGE_TYPE = "local"
REMOTE_METADATA_STORAGE_TYPE = "remote"
SERVICE_INSTANCE_ENDPOINTS = "dubbo.endpoints"
METADATA_SERVICE_PREFIX = "dubbo.metadata-service."
METADATA_SERVICE_URL_PARAMS_PROPERTY_NAME = METADATA_SERVICE_PREFIX + "url-params"
Expand Down
33 changes: 33 additions & 0 deletions common/extension/metadata_remote.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package extension

import (
"fmt"
)

import (
perrors "github.com/pkg/errors"
)

import (
"github.com/apache/dubbo-go/metadata/service/remote"
)

type remoteMetadataServiceCreator func() (remote.RemoteMetadataService, error)

var (
creator remoteMetadataServiceCreator
)

// SetRemoteMetadataService will store the remote metadata service
func SetRemoteMetadataService(creatorFunc remoteMetadataServiceCreator) {
creator = creatorFunc
}

// GetRemoteMetadataServiceFactory will create a MetadataService instance
func GetRemoteMetadataService() (remote.RemoteMetadataService, error) {
if creator != nil {
return creator()
}
return nil, perrors.New(fmt.Sprintf("could not find the metadata service creator for metadataType: remote, please check whether you have imported relative packages, \n" +
"remote - github.com/apache/dubbo-go/metadata/remote/impl"))
}
43 changes: 15 additions & 28 deletions common/extension/metadata_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,29 @@ import (
)

import (
"github.com/apache/dubbo-go/common/logger"
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/metadata/service"
)

type localMetadataServiceCreator func() (service.MetadataService, error)

var (
// there will be two types: local or remote
metadataServiceInsMap = make(map[string]func() (service.MetadataService, error), 2)
// remoteMetadataService
remoteMetadataService service.MetadataService
localMetadataServiceInsMap = make(map[string]localMetadataServiceCreator, 2)
)

// SetMetadataService will store the msType => creator pair
func SetMetadataService(msType string, creator func() (service.MetadataService, error)) {
metadataServiceInsMap[msType] = creator
}

// GetMetadataService will create a MetadataService instance
func GetMetadataService(msType string) (service.MetadataService, error) {
if creator, ok := metadataServiceInsMap[msType]; ok {
return creator()
}
return nil, perrors.New(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))
// SetLocalMetadataService will store the msType => creator pair
func SetLocalMetadataService(key string, creator localMetadataServiceCreator) {
localMetadataServiceInsMap[key] = creator
}

// GetRemoteMetadataService will get a RemoteMetadataService instance
func GetRemoteMetadataService() (service.MetadataService, error) {
if remoteMetadataService != nil {
return remoteMetadataService, nil
// GetMetadataService will create a inmemory MetadataService instance
func GetLocalMetadataService(key string) (service.MetadataService, error) {
if key == "" {
key = constant.DEFAULT_KEY
}
if creator, ok := metadataServiceInsMap["remote"]; ok {
var err error
remoteMetadataService, err = creator()
return remoteMetadataService, err
if creator, ok := localMetadataServiceInsMap[key]; ok {
return creator()
}
logger.Warn("could not find the metadata service creator for metadataType: remote")
return nil, perrors.New(fmt.Sprintf("could not find the metadata service creator for metadataType: remote"))
return nil, perrors.New(fmt.Sprintf("could not find the metadata service creator for metadataType: local, please check whether you have imported relative packages, \n" +
"local - github.com/apache/dubbo-go/metadata/service/inmemory, "))
}
7 changes: 5 additions & 2 deletions common/extension/metadata_service_proxy_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
)

import (
"github.com/apache/dubbo-go/common/constant"
"github.com/apache/dubbo-go/metadata/service"
)

Expand All @@ -37,10 +38,12 @@ func SetMetadataServiceProxyFactory(name string, creator MetadataServiceProxyFac
// GetMetadataServiceProxyFactory will create an instance.
// it will panic if the factory with name not found
func GetMetadataServiceProxyFactory(name string) service.MetadataServiceProxyFactory {
if name == "" {
name = constant.DEFAULT_KEY
}
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))
"local - github.com/apache/dubbo-go/metadata/service/inmemory, \n", name))
}
Loading

0 comments on commit cb51074

Please sign in to comment.