diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 40ef43c8c125fdcad481f1436e64006149ca3611..a20fb8d48bb5e65e8ec1113c60dcb12e8f0393b5 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -71,7 +71,7 @@ jobs: - name: Integrate Test run: | - chmod +x integrate_test.sh && ./integrate_test.sh + chmod +x integrate_test.sh && ./integrate_test.sh ${{github.event.pull_request.head.repo.full_name}} ${{github.event.pull_request.head.sha}} - name: Post Coverage run: bash <(curl -s https://codecov.io/bash) diff --git a/README.md b/README.md index 8af021bb079f47939e5f3d69037906a0c0587d56..c77a0b47665db4d82064714426995834e6a778d0 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@  --- + Apache Dubbo Go Implementation. @@ -134,25 +135,17 @@ Finished List: * [Zookeeper](https://github.com/apache/dubbo-go/blob/9a5990d9a9c3d5e6633c0d7d926c156416bcb931/registry/zookeeper/service_discovery.go) * [Etcd](https://github.com/apache/dubbo-go/blob/9a5990d9a9c3d5e6633c0d7d926c156416bcb931/registry/etcdv3/service_discovery.go) -- Others: - * start check - * connecting certain provider - * multi-protocols - * multi-registries - * multi-versions - * service group - You can know more about dubbo-go by its [roadmap](https://github.com/apache/dubbo-go/wiki/Roadmap).  ## Document -https://dubbogo.github.io/dubbo-go-website (**Improving**) +[dubbo-doc](http://dubbo.apache.org/zh/blog/) or [dubbo-go-doc-list](http://alexstocks.github.io/html/dubbogo.html) ## Quick Start -[dubbo-go-samples](https://github.com/apache/dubbo-go-samples) shows how to use dubbo-go. Please read the [dubbo-samples/golang/README.md](https://github.com/apache/dubbo-go-samples/blob/master/README.md) carefully to learn how to dispose the configuration and compile the program. +[dubbo-go-samples](https://github.com/apache/dubbo-go-samples) gives many examples to tell u how to use dubbo-go. Please read the [dubbo-samples/golang/README.md](https://github.com/apache/dubbo-go-samples/blob/master/README.md) carefully to learn how to dispose the configuration and compile the program. ## Running unit tests @@ -182,6 +175,17 @@ Please move to [dubbo-samples/golang](https://github.com/dubbogo/dubbo-samples) If you are willing to do some code contributions and document contributions to [Apache/dubbo-go](https://github.com/apache/dubbo-go), please visit [contribution intro](https://github.com/apache/dubbo-go/blob/master/contributing.md). +## Community + +If u want to communicate with our community, pls scan the following [dubbobo Ding-Ding QR code](https://mmbiz.qpic.cn/mmbiz_jpg/yvBJb5IiafvnHVBdtia30dxA2hKotr9DEckWsZ7aOJcDWDaSVMGwLmYv8GRgIQtqb4C2svicp8nVkMmGy7yKC5tyA/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1) or search our commnity DingDing group code 31363295. + +<a href="http://alexstocks.github.io/html/dubbogo.html"> +<img src="./doc/pic/misc/dubbogo-dingding.png" height="80" width="80"></a> + +If u want to visit the wechat group, pls add my wechat AlexanderStocks. + +We welcome the friends who can give us constructing suggestions instead of known-nothing. + ## Benchmark Benchmark project [dubbo-go-benchmark](https://github.com/dubbogo/dubbo-go-benchmark). @@ -259,6 +263,11 @@ If you are using [apache/dubbo-go](github.com/apache/dubbo-go) and think that it <img width="222px" src="https://ugc.hitv.com/platform_oss/F6077F1AA82542CDBDD88FD518E6E727.png"> </a> </td> + <td align="center" valign="middle"> + <a href="http://www.dmall.com" target="_blank"> + <img width="222px" src="https://mosn.io/images/community/duodian.png"> + </a> + </td> </tr> <tr></tr> </tbody> diff --git a/README_CN.md b/README_CN.md index 079cfa57449734f291ab5252ed86b01ac59c542c..725db288180fd64e7a8a86b1b0154a36b1f1da5e 100644 --- a/README_CN.md +++ b/README_CN.md @@ -133,25 +133,17 @@ Apache License, Version 2.0 * [Zookeeper](https://github.com/apache/dubbo-go/blob/9a5990d9a9c3d5e6633c0d7d926c156416bcb931/registry/zookeeper/service_discovery.go) * [Etcd](https://github.com/apache/dubbo-go/blob/9a5990d9a9c3d5e6633c0d7d926c156416bcb931/registry/etcdv3/service_discovery.go) -- 鍏朵粬鍔熻兘鏀寔: - * 鍚姩鏃舵鏌� - * 鏈嶅姟鐩磋繛 - * 澶氭湇鍔″崗璁� - * 澶氭敞鍐屼腑蹇� - * 澶氭湇鍔$増鏈� - * 鏈嶅姟鍒嗙粍 - 浣犲彲浠ラ€氳繃璁块棶 [roadmap](https://github.com/apache/dubbo-go/wiki/Roadmap) 鐭ラ亾鏇村鍏充簬 dubbo-go 鐨勪俊鎭€�  ## 鏂囨。 -https://dubbogo.github.io/dubbo-go-website (**瀹屽杽涓�**) +璇疯闂� [dubbo瀹樻柟鏂囨。涓叧浜� dubbo-go 鐨勭郴鍒楁枃妗(http://dubbo.apache.org/zh/blog/) 鎴� [杩囧線dubbo-go鏂囨。鍒楄〃](http://alexstocks.github.io/html/dubbogo.html)銆� ## 蹇€熷紑濮� ## -[dubbo-samples/golang](https://github.com/dubbogo/dubbo-samples)杩欎釜椤圭洰鐨勪簨渚嬪睍绀轰簡濡備綍浣跨敤 dubbo-go 銆傝浠旂粏闃呰 [dubbo-samples/golang/README.md](https://github.com/dubbogo/dubbo-samples/blob/master/golang/README.md) 瀛︿範濡備綍澶勭悊閰嶇疆骞剁紪璇戠▼搴忋€� +[dubbo-samples/golang](https://github.com/apache/dubbo-go-samples)杩欎釜椤圭洰鐨勪簨渚嬪睍绀轰簡濡備綍浣跨敤 dubbo-go 銆傝浠旂粏闃呰 [dubbo-samples/golang/README.md](https://github.com/apache/dubbo-go-samples/blob/master/README.md) 瀛︿範濡備綍澶勭悊閰嶇疆骞剁紪璇戠▼搴忋€� ## 杩愯鍗曟祴 @@ -181,6 +173,17 @@ make test 濡傛灉鎮ㄦ効鎰忕粰 [Apache/dubbo-go](https://github.com/apache/dubbo-go) 璐$尞浠g爜鎴栬€呮枃妗o紝鎴戜滑閮界儹鐑堟杩庛€傚叿浣撹鍙傝€� [contribution intro](https://github.com/apache/dubbo-go/blob/master/contributing.md)銆� +## 绀惧尯 + +濡傛灉鎯宠闂畼鏂归拤閽夌兢锛岃鍦ㄩ拤閽変腑鎼滅储绀惧尯缇ゅ彿 31363295 鎴栬€� 鎵弿濡備笅[浜岀淮鐮乚(https://mmbiz.qpic.cn/mmbiz_jpg/yvBJb5IiafvnHVBdtia30dxA2hKotr9DEckWsZ7aOJcDWDaSVMGwLmYv8GRgIQtqb4C2svicp8nVkMmGy7yKC5tyA/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1)銆� + +<a href="http://alexstocks.github.io/html/dubbogo.html"> +<img src="./doc/pic/misc/dubbogo-dingding.png" height="80" width="80"></a> + +濡傛灉鎯冲姞鍏ュ埌绀惧尯寰俊缇わ紝鍙互鍏堟坊鍔犵ぞ鍖鸿礋璐d汉 浜庨洦 鐨勫井淇� AlexanderStocks 銆傛坊鍔犲井淇′箣鍓嶏紝璇峰厛缁� dubbo-go 鐐� star 浣滀负瀵归」鐩殑鏀寔锛屾坊鍔犲ソ鍙嬫椂璇锋姤涓� github ID 浠ヨ繘琛岄獙璇併€� + +浣滀负涓€涓淮鎶ゅ凡缁忓府鍔╂瀯寤轰簡缁忓彈澶氬澶у瀷寰湇鍔$郴缁熺殑绀惧尯锛屾垜浠冻浠ヤ负鐜版湁鐨勬垚缁╂劅鍒拌嚜璞€傜ぞ鍖烘杩庤兘鎻愬嚭寤鸿鎬ф剰瑙佽€咃紝鍙煡绱㈠彇鑰呭拰鍠峰瓙璇风粫琛屻€� + ## 鎬ц兘娴嬭瘯 ## 鎬ц兘娴嬭瘯椤圭洰鏄� [dubbo-go-benchmark](https://github.com/dubbogo/dubbo-go-benchmark)銆� @@ -256,6 +259,11 @@ make test <a href="http://www.mgtv.com" target="_blank"> <img width="222px" src="https://ugc.hitv.com/platform_oss/F6077F1AA82542CDBDD88FD518E6E727.png"> </a> + </td> + <td align="center" valign="middle"> + <a href="http://www.dmall.com" target="_blank"> + <img width="222px" src="https://mosn.io/images/community/duodian.png"> + </a> </td> </tr> <tr></tr> diff --git a/common/constant/key.go b/common/constant/key.go index 50aea81371bfc8b189e80f19a5c17c5d9de7ae51..0515094f285a4bf598b04e2ea1ef376325de7ac1 100644 --- a/common/constant/key.go +++ b/common/constant/key.go @@ -173,6 +173,7 @@ const ( NACOS_NAMESPACE_ID = "namespaceId" NACOS_PASSWORD = "password" NACOS_USERNAME = "username" + NACOS_NOT_LOAD_LOCAL_CACHE = "nacos.not.load.cache" ) const ( diff --git a/common/extension/metadata_service.go b/common/extension/metadata_service.go index e35677d148eee121c3a6c018a128b5d372c6f2c7..08ddbc333e85fbfc328bec15aa76d2a588b11afb 100644 --- a/common/extension/metadata_service.go +++ b/common/extension/metadata_service.go @@ -26,12 +26,15 @@ import ( ) import ( + "github.com/apache/dubbo-go/common/logger" "github.com/apache/dubbo-go/metadata/service" ) var ( // there will be two types: local or remote metadataServiceInsMap = make(map[string]func() (service.MetadataService, error), 2) + // remoteMetadataService + remoteMetadataService service.MetadataService ) // SetMetadataService will store the msType => creator pair @@ -48,3 +51,17 @@ func GetMetadataService(msType string) (service.MetadataService, error) { "local - github.com/apache/dubbo-go/metadata/service/inmemory, \n"+ "remote - github.com/apache/dubbo-go/metadata/service/remote", msType)) } + +// GetRemoteMetadataService will get a RemoteMetadataService instance +func GetRemoteMetadataService() (service.MetadataService, error) { + if remoteMetadataService != nil { + return remoteMetadataService, nil + } + if creator, ok := metadataServiceInsMap["remote"]; ok { + var err error + remoteMetadataService, err = creator() + return remoteMetadataService, err + } + 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")) +} diff --git a/config/reference_config.go b/config/reference_config.go index 431ec0e2eb3c03b27cca40acd7b721cf6b8f9755..895ab9df26399c1c9a1296e44fba8a284ba2fb6c 100644 --- a/config/reference_config.go +++ b/config/reference_config.go @@ -167,7 +167,8 @@ func (c *ReferenceConfig) Refer(_ interface{}) { // FailoverClusterInvoker(RegistryDirectory, routing happens here) -> Invoker c.invoker = cluster.Join(directory.NewStaticDirectory(invokers)) } - + // publish consumer metadata + publishConsumerDefinition(cfgURL) // create proxy if c.Async { callback := GetCallback(c.id) @@ -257,6 +258,12 @@ func (c *ReferenceConfig) GenericLoad(id string) { c.Implement(genericService) } +func publishConsumerDefinition(url *common.URL) { + if remoteMetadataService, err := extension.GetRemoteMetadataService(); err == nil && remoteMetadataService != nil { + remoteMetadataService.PublishServiceDefinition(url) + } +} + // postProcessConfig asks registered ConfigPostProcessor to post-process the current ReferenceConfig. func (c *ReferenceConfig) postProcessConfig(url *common.URL) { for _, p := range extension.GetConfigPostProcessors() { diff --git a/config/service_config.go b/config/service_config.go index fd49390aa2b15938a8a4aa321d47ceafef4d9be9..e8523bdea7aa014836580b7ce33fe215c145289d 100644 --- a/config/service_config.go +++ b/config/service_config.go @@ -234,6 +234,7 @@ func (c *ServiceConfig) Export() error { } c.exporters = append(c.exporters, exporter) } + publishServiceDefinition(ivkURL) } c.exported.Store(true) return nil @@ -347,6 +348,12 @@ func (c *ServiceConfig) GetExportedUrls() []*common.URL { return nil } +func publishServiceDefinition(url *common.URL) { + if remoteMetadataService, err := extension.GetRemoteMetadataService(); err == nil && remoteMetadataService != nil { + remoteMetadataService.PublishServiceDefinition(url) + } +} + // postProcessConfig asks registered ConfigPostProcessor to post-process the current ServiceConfig. func (c *ServiceConfig) postProcessConfig(url *common.URL) { for _, p := range extension.GetConfigPostProcessors() { diff --git a/config_center/file/impl.go b/config_center/file/impl.go index 9afe7c6524ab02d368f91283e39e3e4c1deacbac..6489a073deff643ad7eecc7f3c26ef0b8899ac53 100644 --- a/config_center/file/impl.go +++ b/config_center/file/impl.go @@ -24,7 +24,6 @@ import ( "os" "os/exec" "os/user" - "path" "path/filepath" "runtime" "strings" @@ -41,11 +40,19 @@ import ( "github.com/apache/dubbo-go/config_center/parser" ) +var ( + osType = runtime.GOOS +) + +const ( + windowsOS = "windows" +) + const ( - PARAM_NAME_PREFIX = "dubbo.config-center." - CONFIG_CENTER_DIR_PARAM_NAME = PARAM_NAME_PREFIX + "dir" - CONFIG_CENTER_ENCODING_PARAM_NAME = PARAM_NAME_PREFIX + "encoding" - DEFAULT_CONFIG_CENTER_ENCODING = "UTF-8" + ParamNamePrefix = "dubbo.config-center." + ConfigCenterDirParamName = ParamNamePrefix + "dir" + ConfigCenterEncodingParamName = ParamNamePrefix + "encoding" + defaultConfigCenterEncoding = "UTF-8" ) // FileSystemDynamicConfiguration @@ -59,24 +66,14 @@ type FileSystemDynamicConfiguration struct { } func newFileSystemDynamicConfiguration(url *common.URL) (*FileSystemDynamicConfiguration, error) { - encode := url.GetParam(CONFIG_CENTER_ENCODING_PARAM_NAME, DEFAULT_CONFIG_CENTER_ENCODING) + encode := url.GetParam(ConfigCenterEncodingParamName, defaultConfigCenterEncoding) - root := url.GetParam(CONFIG_CENTER_DIR_PARAM_NAME, "") + root := url.GetParam(ConfigCenterDirParamName, "") var c *FileSystemDynamicConfiguration - if _, err := os.Stat(root); err != nil { - // not exist, use default, /XXX/xx/.dubbo/config-center - if rp, err := Home(); err != nil { - return nil, perrors.WithStack(err) - } else { - root = path.Join(rp, ".dubbo", "config-center") - } - } - if _, err := os.Stat(root); err != nil { - // it must be dir, if not exist, will create - if err = createDir(root); err != nil { - return nil, perrors.WithStack(err) - } + root, err := mkdirIfNecessary(root) + if err != nil { + return nil, err } c = &FileSystemDynamicConfiguration{ @@ -195,18 +192,18 @@ func (fsdc *FileSystemDynamicConfiguration) Close() error { // GetPath get path func (fsdc *FileSystemDynamicConfiguration) GetPath(key string, group string) string { if len(key) == 0 { - return path.Join(fsdc.rootPath, group) + return filepath.Join(fsdc.rootPath, group) } if len(group) == 0 { group = config_center.DEFAULT_GROUP } - return path.Join(fsdc.rootPath, group, key) + return filepath.Join(fsdc.rootPath, group, adapterKey(key)) } func (fsdc *FileSystemDynamicConfiguration) deleteDelay(path string) (bool, error) { - if path == "" { + if len(path) == 0 { return false, nil } @@ -226,9 +223,7 @@ func (fsdc *FileSystemDynamicConfiguration) write2File(fp string, value string) } func forceMkdirParent(fp string) error { - pd := getParentDirectory(fp) - - return createDir(pd) + return createDir(getParentDirectory(fp)) } func createDir(path string) error { @@ -250,6 +245,7 @@ func substr(s string, pos, length int) string { if l > len(runes) { l = len(runes) } + return string(runes[pos:l]) } @@ -264,7 +260,7 @@ func Home() (string, error) { } // cross compile support - if "windows" == runtime.GOOS { + if windowsOS == osType { return homeWindows() } @@ -287,7 +283,7 @@ func homeUnix() (string, error) { } result := strings.TrimSpace(stdout.String()) - if result == "" { + if len(result) == 0 { return "", errors.New("blank output when reading home directory") } @@ -298,12 +294,66 @@ func homeWindows() (string, error) { drive := os.Getenv("HOMEDRIVE") homePath := os.Getenv("HOMEPATH") home := drive + homePath - if drive == "" || homePath == "" { + if len(drive) == 0 || len(homePath) == 0 { home = os.Getenv("USERPROFILE") } - if home == "" { + if len(home) == 0 { return "", errors.New("HOMEDRIVE, HOMEPATH, and USERPROFILE are blank") } return home, nil } + +func mkdirIfNecessary(urlRoot string) (string, error) { + if !legalPath(urlRoot) { + // not exist, use default, mac is: /XXX/xx/.dubbo/config-center + rp, err := Home() + if err != nil { + return "", perrors.WithStack(err) + } + + urlRoot = adapterUrl(rp) + } + + if _, err := os.Stat(urlRoot); err != nil { + // it must be dir, if not exist, will create + if err = createDir(urlRoot); err != nil { + return "", perrors.WithStack(err) + } + } + + return urlRoot, nil +} + +func legalPath(path string) bool { + if len(path) == 0 { + return false + } + if _, err := os.Stat(path); err != nil { + return false + } + + return true +} + +func adapterUrl(rp string) string { + if osType == windowsOS { + return filepath.Join(rp, "_dubbo", "config-center") + } + + return filepath.Join(rp, ".dubbo", "config-center") +} + +// used for GetPath. param key default is instance's id. +// e.g: (ip:port) 127.0.0.1:20081, in windows env, will change to 127_0_0_1_20081 +func adapterKey(key string) string { + if len(key) == 0 { + return "" + } + + if osType == windowsOS { + return strings.ReplaceAll(strings.ReplaceAll(key, ".", "_"), ":", "_") + } + + return key +} diff --git a/doc/pic/misc/dubbogo-dingding.png b/doc/pic/misc/dubbogo-dingding.png new file mode 100644 index 0000000000000000000000000000000000000000..dc27d4ecce94a095e2eb70f97446c76c5b8537da Binary files /dev/null and b/doc/pic/misc/dubbogo-dingding.png differ diff --git a/filter/filter_impl/sentinel_filter.go b/filter/filter_impl/sentinel_filter.go index f662db35637593f4ab92a2b12e50d5a9e4305730..1de27adbac1808dbbbf8017f0119077752191d6f 100644 --- a/filter/filter_impl/sentinel_filter.go +++ b/filter/filter_impl/sentinel_filter.go @@ -42,6 +42,7 @@ import ( // 1. Must initialize Sentinel Go run environment, // refer to https://github.com/alibaba/sentinel-golang/blob/master/api/init.go // 2. Register rules for resources user want to guard + func init() { extension.SetFilter(SentinelProviderFilterName, GetSentinelProviderFilter) extension.SetFilter(SentinelConsumerFilterName, GetSentinelConsumerFilter) diff --git a/go.mod b/go.mod index 0e5736c0a8afd6352f3b9f0e30d2fa368c767312..2dda6cffad082dac4986d318277913c980203d55 100644 --- a/go.mod +++ b/go.mod @@ -1,19 +1,19 @@ module github.com/apache/dubbo-go -go 1.15 +go 1.13 require ( github.com/NYTimes/gziphandler v1.1.1 // indirect github.com/RoaringBitmap/roaring v0.5.5 github.com/Workiva/go-datastructures v1.0.52 github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 - github.com/alibaba/sentinel-golang v1.0.1 + github.com/alibaba/sentinel-golang v1.0.2 github.com/apache/dubbo-getty v1.4.1 - github.com/apache/dubbo-go-hessian2 v1.8.0 + github.com/apache/dubbo-go-hessian2 v1.8.2 github.com/coreos/etcd v3.3.25+incompatible github.com/creasty/defaults v1.5.1 github.com/dubbogo/go-zookeeper v1.0.2 - github.com/dubbogo/gost v1.10.1 + github.com/dubbogo/gost v1.11.0 github.com/elazarl/go-bindata-assetfs v1.0.0 // indirect github.com/emicklei/go-restful/v3 v3.4.0 github.com/frankban/quicktest v1.4.1 // indirect @@ -30,16 +30,16 @@ require ( github.com/hashicorp/vault/sdk v0.1.14-0.20191112033314-390e96e22eb2 github.com/jinzhu/copier v0.0.0-20190625015134-976e0346caa8 github.com/magiconair/properties v1.8.4 - github.com/mitchellh/mapstructure v1.4.0 + github.com/mitchellh/mapstructure v1.4.1 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd - github.com/nacos-group/nacos-sdk-go v1.0.3 + github.com/nacos-group/nacos-sdk-go v1.0.5 github.com/opentracing/opentracing-go v1.2.0 github.com/pierrec/lz4 v2.2.6+incompatible // indirect github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.8.0 github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b github.com/stretchr/objx v0.2.0 // indirect - github.com/stretchr/testify v1.6.1 + github.com/stretchr/testify v1.7.0 github.com/zouyx/agollo/v3 v3.4.5 go.uber.org/atomic v1.7.0 go.uber.org/zap v1.16.0 diff --git a/go.sum b/go.sum index ad7ca827def4c152bcd578a0206dc3dddb59d9ea..6cc41e6b583077ffa0e48d70d7d840831d5561a6 100644 --- a/go.sum +++ b/go.sum @@ -62,7 +62,6 @@ github.com/RoaringBitmap/roaring v0.5.5 h1:naNqvO1mNnghk2UvcsqnzHDBn9DRbCIRy94Gm github.com/RoaringBitmap/roaring v0.5.5/go.mod h1:puNo5VdzwbaIQxSiDIwfXl4Hnc+fbovcX4IW/dSTtUk= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= -github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8= github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk= github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= @@ -78,14 +77,14 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= -github.com/alibaba/sentinel-golang v1.0.1 h1:WlhN0XUxRyfkiDc8TO6CcRrnakwFP9zFtvJTYxZRCgI= -github.com/alibaba/sentinel-golang v1.0.1/go.mod h1:QsB99f/z35D2AiMrAWwgWE85kDTkBUIkcmPrRt+61NI= +github.com/alibaba/sentinel-golang v1.0.2 h1:Acopq74hOtZN4MV1v811MQ6QcqPFLDSczTrRXv9zpIg= +github.com/alibaba/sentinel-golang v1.0.2/go.mod h1:QsB99f/z35D2AiMrAWwgWE85kDTkBUIkcmPrRt+61NI= github.com/aliyun/alibaba-cloud-sdk-go v1.61.18 h1:zOVTBdCKFd9JbCKz9/nt+FovbjPFmb7mUnp8nH9fQBA= github.com/aliyun/alibaba-cloud-sdk-go v1.61.18/go.mod h1:v8ESoHo4SyHmuB4b1tJqDHxfTGEciD+yhvOU/5s1Rfk= github.com/apache/dubbo-getty v1.4.1 h1:M9yaFhemThQSWtRwmJNrxNuv7FzydlFx5EY8oq1v+lw= github.com/apache/dubbo-getty v1.4.1/go.mod h1:ansXgKxxyhCOiQL29nO5ce1MDcEKmCyZuNR9oMs3hek= -github.com/apache/dubbo-go-hessian2 v1.8.0 h1:+GJQHxWd/WUw2p4hbfCal/zjKvGVb8yJZzOke8IEazc= -github.com/apache/dubbo-go-hessian2 v1.8.0/go.mod h1:7rEw9guWABQa6Aqb8HeZcsYPHsOS7XT1qtJvkmI6c5w= +github.com/apache/dubbo-go-hessian2 v1.8.2 h1:CQq2Mmlrk6Fqmudwl9Dqps8drTrBFnmXRlzgOjj0FqA= +github.com/apache/dubbo-go-hessian2 v1.8.2/go.mod h1:xQUjE7F8PX49nm80kChFvepA/AvqAZ0oh/UaB6+6pBE= github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e h1:QEF07wC0T1rKkctt1RINW/+RMTVmiwxETico2l3gxJA= @@ -177,6 +176,8 @@ github.com/dubbogo/go-zookeeper v1.0.2/go.mod h1:fn6n2CAEer3novYgk9ULLwAjuV8/g4D github.com/dubbogo/gost v1.9.0/go.mod h1:pPTjVyoJan3aPxBPNUX0ADkXjPibLo+/Ib0/fADXSG8= github.com/dubbogo/gost v1.10.1 h1:39kF9Cd5JOiMpmwG6dX1/aLWNFqFv9gHp8HrhzMmjLY= github.com/dubbogo/gost v1.10.1/go.mod h1:+mQGS51XQEUWZP2JeGZTxJwipjRKtJO7Tr+FOg+72rI= +github.com/dubbogo/gost v1.11.0 h1:9KtyWQz1gMlAfwzen5iyhMdoe08SPBBUVhco4rdgJ9I= +github.com/dubbogo/gost v1.11.0/go.mod h1:w8Yw29eDWtRVo3tx9nPpHkNZnOi4SRx1fZf7eVlAAU4= github.com/dubbogo/jsonparser v1.0.1/go.mod h1:tYAtpctvSP/tWw4MeelsowSPgXQRVHHWbqL6ynps8jU= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= @@ -475,7 +476,9 @@ github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7 github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= +github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 h1:uC1QfSlInpQF+M0ao65imhwqKnz3Q2z/d8PWZRMQvDM= github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k= +github.com/k0kubun/pp v3.0.1+incompatible h1:3tqvf7QgUnZ5tXO6pNAZlrvHgl6DvifjDrd9g2S9Z40= github.com/k0kubun/pp v3.0.1+incompatible/go.mod h1:GWse8YhT0p8pT4ir3ZgBbfZild3tgzSScAn6HmfYukg= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= @@ -547,8 +550,8 @@ github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0Qu github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.2.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/mitchellh/mapstructure v1.4.0 h1:7ks8ZkOP5/ujthUsT07rNv+nkLXCQWKNHuwzOAesEks= -github.com/mitchellh/mapstructure v1.4.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= +github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/pointerstructure v1.0.0 h1:ATSdz4NWrmWPOF1CeCBU4sMCno2hgqdbSrRPFWQSVZI= github.com/mitchellh/pointerstructure v1.0.0/go.mod h1:k4XwG94++jLVsSiTxo7qdIfXA9pj9EAeo0QsNNJOLZ8= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= @@ -567,8 +570,8 @@ github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8m github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= -github.com/nacos-group/nacos-sdk-go v1.0.3 h1:A2tCWcjuP6bSEjEfNwNnrY+9M0h13XRMDyLY+DPqHMI= -github.com/nacos-group/nacos-sdk-go v1.0.3/go.mod h1:hlAPn3UdzlxIlSILAyOXKxjFSvDJ9oLzTJ9hLAK1KzA= +github.com/nacos-group/nacos-sdk-go v1.0.5 h1:xwLS0Ao7fSB3HoDFR+JRZ1fh0HuvgHPOWBdals37Oxc= +github.com/nacos-group/nacos-sdk-go v1.0.5/go.mod h1:hlAPn3UdzlxIlSILAyOXKxjFSvDJ9oLzTJ9hLAK1KzA= github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k= @@ -748,6 +751,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tebeka/strftime v0.1.3 h1:5HQXOqWKYRFfNyBMNVc9z5+QzuBtIXy03psIhtdJYto= diff --git a/integrate_test.sh b/integrate_test.sh index deccda756a211821978e35b92a1f0865858ff59a..e1bbc8c11b0195f7cc4f08946d57464c88e74f19 100644 --- a/integrate_test.sh +++ b/integrate_test.sh @@ -26,12 +26,12 @@ ROOT_DIR=$(pwd) echo "integrate-test root work-space -> ${ROOT_DIR}" # show all travis-env -echo "travis current commit id -> ${TRAVIS_COMMIT}" -echo "travis pull request -> ${TRAVIS_PULL_REQUEST}" -echo "travis pull request branch -> ${TRAVIS_PULL_REQUEST_BRANCH}" -echo "travis pull request slug -> ${TRAVIS_PULL_REQUEST_SLUG}" -echo "travis pull request sha -> ${TRAVIS_PULL_REQUEST_SHA}" -echo "travis pull request repo slug -> ${TRAVIS_REPO_SLUG}" +echo "travis current commit id -> $2" +echo "travis pull request branch -> ${GITHUB_REF}" +echo "travis pull request slug -> ${GITHUB_REPOSITORY}" +echo "travis pull request repo slug -> ${GITHUB_REPOSITORY}" +echo "travis pull request actor -> ${GITHUB_ACTOR}" +echo "travis pull request repo param -> $1" # #start etcd registry insecure listen in [:]:2379 @@ -53,13 +53,13 @@ echo "zookeeper listen in [:]2181" # build go-server image cd ./test/integrate/dubbo/go-server -docker build . -t ci-provider --build-arg PR_ORIGIN_REPO=${TRAVIS_PULL_REQUEST_SLUG} --build-arg PR_ORIGIN_COMMITID=${TRAVIS_PULL_REQUEST_SHA} +docker build . -t ci-provider --build-arg PR_ORIGIN_REPO=$1 --build-arg PR_ORIGIN_COMMITID=$2 cd ${ROOT_DIR} docker run -d --network host ci-provider # build go-client image cd ./test/integrate/dubbo/go-client -docker build . -t ci-consumer --build-arg PR_ORIGIN_REPO=${TRAVIS_PULL_REQUEST_SLUG} --build-arg PR_ORIGIN_COMMITID=${TRAVIS_PULL_REQUEST_SHA} +docker build . -t ci-consumer --build-arg PR_ORIGIN_REPO=$1 --build-arg PR_ORIGIN_COMMITID=$2 cd ${ROOT_DIR} # run provider # check consumer status diff --git a/metadata/report/delegate/delegate_report.go b/metadata/report/delegate/delegate_report.go index f364087fdc8c2fb2a595190d7ca0d9564ac5d171..56a22de8f8e56c040260edf86859a4499f1b2f39 100644 --- a/metadata/report/delegate/delegate_report.go +++ b/metadata/report/delegate/delegate_report.go @@ -109,6 +109,10 @@ type MetadataReport struct { // NewMetadataReport will create a MetadataReport with initiation func NewMetadataReport() (*MetadataReport, error) { url := instance.GetMetadataReportUrl() + if url == nil { + logger.Warn("the metadataReport URL is not configured, you should configure it.") + return nil, perrors.New("the metadataReport URL is not configured, you should configure it.") + } bmr := &MetadataReport{ reportUrl: url, syncReport: url.GetParamBool(constant.SYNC_REPORT_KEY, false), diff --git a/metadata/service/remote/service.go b/metadata/service/remote/service.go index d21cc88a3d31ec2920a78c608ed13a491fd6c634..bb520d3df72c369eb4022246f20bb9e9aa1bd8b8 100644 --- a/metadata/service/remote/service.go +++ b/metadata/service/remote/service.go @@ -116,22 +116,40 @@ func (mts *MetadataService) UnsubscribeURL(url *common.URL) error { func (mts *MetadataService) PublishServiceDefinition(url *common.URL) error { interfaceName := url.GetParam(constant.INTERFACE_KEY, "") isGeneric := url.GetParamBool(constant.GENERIC_KEY, false) - if len(interfaceName) > 0 && !isGeneric { - sv := common.ServiceMap.GetServiceByServiceKey(url.Protocol, url.ServiceKey()) - sd := definition.BuildServiceDefinition(*sv, url) + if common.RoleType(common.PROVIDER).Role() == url.GetParam(constant.SIDE_KEY, "") { + if len(interfaceName) > 0 && !isGeneric { + sv := common.ServiceMap.GetServiceByServiceKey(url.Protocol, url.ServiceKey()) + sd := definition.BuildServiceDefinition(*sv, url) + id := &identifier.MetadataIdentifier{ + BaseMetadataIdentifier: identifier.BaseMetadataIdentifier{ + ServiceInterface: interfaceName, + Version: url.GetParam(constant.VERSION_KEY, ""), + Group: url.GetParam(constant.GROUP_KEY, constant.DUBBO), + Side: url.GetParam(constant.SIDE_KEY, constant.PROVIDER_PROTOCOL), + }, + } + mts.delegateReport.StoreProviderMetadata(id, sd) + return nil + } + logger.Errorf("publishProvider interfaceName is empty . providerUrl:%v ", url) + } else { + params := make(map[string]string, len(url.GetParams())) + url.RangeParams(func(key, value string) bool { + params[key] = value + return true + }) id := &identifier.MetadataIdentifier{ BaseMetadataIdentifier: identifier.BaseMetadataIdentifier{ ServiceInterface: interfaceName, Version: url.GetParam(constant.VERSION_KEY, ""), - // Group: url.GetParam(constant.GROUP_KEY, constant.SERVICE_DISCOVERY_DEFAULT_GROUP), - Group: url.GetParam(constant.GROUP_KEY, constant.DUBBO), - Side: url.GetParam(constant.SIDE_KEY, "provider"), + Group: url.GetParam(constant.GROUP_KEY, constant.DUBBO), + Side: url.GetParam(constant.SIDE_KEY, "consumer"), }, } - mts.delegateReport.StoreProviderMetadata(id, sd) + mts.delegateReport.StoreConsumerMetadata(id, params) return nil } - logger.Errorf("publishProvider interfaceName is empty . providerUrl:%v ", url) + return nil } diff --git a/protocol/protocolwrapper/protocol_filter_wrapper.go b/protocol/protocolwrapper/protocol_filter_wrapper.go index 79d2cf7f55ee81db39ea28448fc66a8a7494d8d1..679036f20e941866652bff3bf28bc75f690908c8 100644 --- a/protocol/protocolwrapper/protocol_filter_wrapper.go +++ b/protocol/protocolwrapper/protocol_filter_wrapper.go @@ -77,7 +77,7 @@ func buildInvokerChain(invoker protocol.Invoker, key string) protocol.Invoker { // The order of filters is from left to right, so loading from right to left next := invoker for i := len(filterNames) - 1; i >= 0; i-- { - flt := extension.GetFilter(filterNames[i]) + flt := extension.GetFilter(strings.TrimSpace(filterNames[i])) fi := &FilterInvoker{next: next, invoker: invoker, filter: flt} next = fi } diff --git a/protocol/protocolwrapper/protocol_filter_wrapper_test.go b/protocol/protocolwrapper/protocol_filter_wrapper_test.go index 8f063f85521bbdcd3fa3891e7d09754fc9b58ac7..b37d066f03c8084d2d529217567c1ede940a5491 100644 --- a/protocol/protocolwrapper/protocol_filter_wrapper_test.go +++ b/protocol/protocolwrapper/protocol_filter_wrapper_test.go @@ -42,7 +42,7 @@ func TestProtocolFilterWrapperExport(t *testing.T) { u := common.NewURLWithOptions( common.WithParams(url.Values{}), - common.WithParamsValue(constant.SERVICE_FILTER_KEY, "echo")) + common.WithParamsValue(constant.SERVICE_FILTER_KEY, "echo ")) exporter := filtProto.Export(protocol.NewBaseInvoker(u)) _, ok := exporter.GetInvoker().(*FilterInvoker) assert.True(t, ok) @@ -54,7 +54,7 @@ func TestProtocolFilterWrapperRefer(t *testing.T) { u := common.NewURLWithOptions( common.WithParams(url.Values{}), - common.WithParamsValue(constant.REFERENCE_FILTER_KEY, "echo")) + common.WithParamsValue(constant.REFERENCE_FILTER_KEY, " echo")) invoker := filtProto.Refer(u) _, ok := invoker.(*FilterInvoker) assert.True(t, ok) diff --git a/registry/etcdv3/listener.go b/registry/etcdv3/listener.go index 4bc387cafaa3c64539efb29a181a2198fbe8a30f..f900495f97d3acfd9a2ae232264910b791961bc8 100644 --- a/registry/etcdv3/listener.go +++ b/registry/etcdv3/listener.go @@ -19,6 +19,7 @@ package etcdv3 import ( "strings" + "sync" ) import ( @@ -79,8 +80,9 @@ func (l *dataListener) DataChange(eventType remoting.Event) bool { } type configurationListener struct { - registry *etcdV3Registry - events chan *config_center.ConfigChangeEvent + registry *etcdV3Registry + events chan *config_center.ConfigChangeEvent + closeOnce sync.Once } // NewConfigurationListener for listening the event of etcdv3. @@ -120,5 +122,7 @@ func (l *configurationListener) Next() (*registry.ServiceEvent, error) { // Close etcd registry center func (l *configurationListener) Close() { - l.registry.WaitGroup().Done() + l.closeOnce.Do(func() { + l.registry.WaitGroup().Done() + }) } diff --git a/registry/etcdv3/registry.go b/registry/etcdv3/registry.go index f3cc379bd8e94b15b678f0ac1d5ed5b6c917da6a..7ccf32661c75ed4cd27fddd1fc020ded56066f37 100644 --- a/registry/etcdv3/registry.go +++ b/registry/etcdv3/registry.go @@ -51,7 +51,7 @@ type etcdV3Registry struct { registry.BaseRegistry cltLock sync.Mutex client *etcdv3.Client - listenerLock sync.Mutex + listenerLock sync.RWMutex listener *etcdv3.EventListener dataListener *dataListener configListener *configurationListener @@ -150,14 +150,9 @@ func (r *etcdV3Registry) CreatePath(k string) error { // DoSubscribe actually subscribe the provider URL func (r *etcdV3Registry) DoSubscribe(svc *common.URL) (registry.Listener, error) { - - var ( - configListener *configurationListener - ) - - r.listenerLock.Lock() - configListener = r.configListener - r.listenerLock.Unlock() + r.listenerLock.RLock() + configListener := r.configListener + r.listenerLock.RUnlock() if r.listener == nil { r.cltLock.Lock() client := r.client @@ -165,12 +160,8 @@ func (r *etcdV3Registry) DoSubscribe(svc *common.URL) (registry.Listener, error) if client == nil { return nil, perrors.New("etcd client broken") } - - // new client & listener - listener := etcdv3.NewEventListener(r.client) - r.listenerLock.Lock() - r.listener = listener + r.listener = etcdv3.NewEventListener(r.client) // new client & listener r.listenerLock.Unlock() } diff --git a/registry/file/service_discovery.go b/registry/file/service_discovery.go index c3b77f6849c7566496d1b8e6f900dd48ac128b8a..768a1c2a3d8a208d637e374632da530a43465a4e 100644 --- a/registry/file/service_discovery.go +++ b/registry/file/service_discovery.go @@ -69,7 +69,7 @@ func newFileSystemServiceDiscovery(name string) (registry.ServiceDiscovery, erro fdcf := extension.GetConfigCenterFactory(constant.FILE_KEY) p := path.Join(rp, ".dubbo", constant.REGISTRY_KEY) url, _ := common.NewURL("") - url.AddParamAvoidNil(file.CONFIG_CENTER_DIR_PARAM_NAME, p) + url.AddParamAvoidNil(file.ConfigCenterDirParamName, p) c, err := fdcf.GetDynamicConfiguration(url) if err != nil { return nil, perrors.WithStack(err) diff --git a/registry/nacos/registry.go b/registry/nacos/registry.go index ae2345e6d5c90fcfc5c4dfb5b4da07bcf1b6f43e..de68e74906ecf14330d12bfb0ae42e86648ff9e3 100644 --- a/registry/nacos/registry.go +++ b/registry/nacos/registry.go @@ -274,7 +274,7 @@ func getNacosConfig(url *common.URL) (map[string]interface{}, error) { Port: uint64(port), }) } - configMap["serverConfigs"] = serverConfigs + configMap[nacosConstant.KEY_SERVER_CONFIGS] = serverConfigs var clientConfig nacosConstant.ClientConfig timeout, err := time.ParseDuration(url.GetParam(constant.REGISTRY_TIMEOUT_KEY, constant.DEFAULT_REG_TIMEOUT)) @@ -287,8 +287,16 @@ func getNacosConfig(url *common.URL) (map[string]interface{}, error) { clientConfig.LogDir = url.GetParam(constant.NACOS_LOG_DIR_KEY, "") clientConfig.Endpoint = url.GetParam(constant.NACOS_ENDPOINT, "") clientConfig.NamespaceId = url.GetParam(constant.NACOS_NAMESPACE_ID, "") - clientConfig.NotLoadCacheAtStart = true - configMap["clientConfig"] = clientConfig + + //enable local cache when nacos can not connect. + notLoadCache, err := strconv.ParseBool(url.GetParam(constant.NACOS_NOT_LOAD_LOCAL_CACHE, "false")) + if err != nil { + logger.Errorf("ParseBool - error: %v", err) + notLoadCache = false + } + clientConfig.NotLoadCacheAtStart = notLoadCache + + configMap[nacosConstant.KEY_CLIENT_CONFIG] = clientConfig return configMap, nil } diff --git a/registry/nacos/registry_test.go b/registry/nacos/registry_test.go index a852c00b14ac82ffc64206d6880c9f0e9af7aff6..b82820577144dfe98492165372a925500c20abfb 100644 --- a/registry/nacos/registry_test.go +++ b/registry/nacos/registry_test.go @@ -40,7 +40,11 @@ func TestNacosRegistry_Register(t *testing.T) { if !checkNacosServerAlive() { return } - regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))) + regurlMap := url.Values{} + regurlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)) + regurlMap.Set(constant.NACOS_NOT_LOAD_LOCAL_CACHE, "true") + regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParams(regurlMap)) + urlMap := url.Values{} urlMap.Set(constant.GROUP_KEY, "guangzhou-idc") urlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)) @@ -72,7 +76,11 @@ func TestNacosRegistry_Subscribe(t *testing.T) { if !checkNacosServerAlive() { return } - regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))) + regurlMap := url.Values{} + regurlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)) + regurlMap.Set(constant.NACOS_NOT_LOAD_LOCAL_CACHE, "true") + regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParams(regurlMap)) + urlMap := url.Values{} urlMap.Set(constant.GROUP_KEY, "guangzhou-idc") urlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)) @@ -113,7 +121,11 @@ func TestNacosRegistry_Subscribe_del(t *testing.T) { if !checkNacosServerAlive() { return } - regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))) + regurlMap := url.Values{} + regurlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)) + regurlMap.Set(constant.NACOS_NOT_LOAD_LOCAL_CACHE, "true") + regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParams(regurlMap)) + urlMap := url.Values{} urlMap.Set(constant.GROUP_KEY, "guangzhou-idc") urlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)) @@ -181,7 +193,11 @@ func TestNacosRegistry_Subscribe_del(t *testing.T) { } func TestNacosListener_Close(t *testing.T) { - regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParamsValue(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))) + regurlMap := url.Values{} + regurlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)) + regurlMap.Set(constant.NACOS_NOT_LOAD_LOCAL_CACHE, "true") + regurl, _ := common.NewURL("registry://console.nacos.io:80", common.WithParams(regurlMap)) + urlMap := url.Values{} urlMap.Set(constant.GROUP_KEY, "guangzhou-idc") urlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER)) diff --git a/registry/servicediscovery/service_discovery_registry.go b/registry/servicediscovery/service_discovery_registry.go index 2ca4b8015bc8dbc51a47a46c1bec0301ac961339..c97a7f7b51d2344f1a3fc0c59582e089f1e63b62 100644 --- a/registry/servicediscovery/service_discovery_registry.go +++ b/registry/servicediscovery/service_discovery_registry.go @@ -174,10 +174,6 @@ func (s *serviceDiscoveryRegistry) Register(url *common.URL) error { logger.Warnf("The URL[%s] has been registry!", url.String()) } - err = s.metaDataService.PublishServiceDefinition(url) - if err != nil { - return perrors.WithMessage(err, "publish the service definition failed. ") - } return s.serviceNameMapping.Map(url.GetParam(constant.INTERFACE_KEY, ""), url.GetParam(constant.GROUP_KEY, ""), url.GetParam(constant.Version, ""), diff --git a/remoting/etcdv3/listener.go b/remoting/etcdv3/listener.go index c66928a6367cb2449de79a51b59d122a74a79911..fd6f9585979fabeb86d7a74d5817b6992b6a0ad4 100644 --- a/remoting/etcdv3/listener.go +++ b/remoting/etcdv3/listener.go @@ -36,7 +36,7 @@ import ( // nolint type EventListener struct { client *Client - keyMapLock sync.Mutex + keyMapLock sync.RWMutex keyMap map[string]struct{} wg sync.WaitGroup } @@ -181,9 +181,9 @@ func timeSecondDuration(sec int) time.Duration { // --------> listenServiceNodeEvent func (l *EventListener) ListenServiceEvent(key string, listener remoting.DataListener) { - l.keyMapLock.Lock() + l.keyMapLock.RLock() _, ok := l.keyMap[key] - l.keyMapLock.Unlock() + l.keyMapLock.RUnlock() if ok { logger.Warnf("etcdv3 key %s has already been listened.", key) return