diff --git a/README_CN.md b/README_CN.md index 92df996d1c4e1922315df2e2d73790bab78225ce..4112c6b208ef1b5911992999223e5782c2a5ef36 100644 --- a/README_CN.md +++ b/README_CN.md @@ -194,7 +194,22 @@ make test </table> </div> -濡傛灉鎯冲姞鍏ュ埌绀惧尯寰俊缇わ紝鍙互鍏堟坊鍔犵ぞ鍖鸿礋璐d汉 浜庨洦 鐨勫井淇� AlexanderStocks 銆傛坊鍔犲井淇′箣鍓嶏紝璇峰厛缁� dubbo-go 鐐� star 浣滀负瀵归」鐩殑鏀寔锛屾坊鍔犲ソ鍙嬫椂璇锋姤涓� github ID 浠ヨ繘琛岄獙璇併€� +dubbogo 绀惧尯宸茬粡寮€閫氬井淇″叕浼楀彿 "dubbogo澶у尯"锛屽彲鍦ㄥ井淇℃悳绱� "dubbogo澶у尯" 鎴栬€呮壂鎻忓涓嬩簩缁寸爜鍏虫敞锛屽彲閫氳繃鍏紬鍙风淇$暀瑷€鍔犲叆 dubbogo 寰俊绀惧尯銆� + +<div> +<table> + <tbody> + <tr></tr> + <tr> + <td align="center" valign="middle"> + <img width="80px" height="115px" src="./doc/pic/misc/dubbogo-wechat.png"> + </a> + </td> + </tr> + <tr></tr> + </tbody> +</table> +</div> 浣滀负涓€涓淮鎶ゅ凡缁忓府鍔╂瀯寤轰簡缁忓彈澶氬澶у瀷寰湇鍔$郴缁熺殑绀惧尯锛屾垜浠冻浠ヤ负鐜版湁鐨勬垚缁╂劅鍒拌嚜璞€傜ぞ鍖烘杩庤兘鎻愬嚭寤鸿鎬ф剰瑙佽€咃紝鍙煡绱㈠彇鑰呭拰鍠峰瓙璇风粫琛屻€� diff --git a/config_center/zookeeper/listener.go b/config_center/zookeeper/listener.go index bc6eb6d6eec4413515228a712cd11810e11f08cc..244451a2d0af2b2e743f1d0889cb926df89b3c3b 100644 --- a/config_center/zookeeper/listener.go +++ b/config_center/zookeeper/listener.go @@ -23,6 +23,7 @@ import ( ) import ( + "github.com/apache/dubbo-go/common/constant" "github.com/apache/dubbo-go/config_center" "github.com/apache/dubbo-go/remoting" ) @@ -77,5 +78,12 @@ func (l *CacheListener) DataChange(event remoting.Event) bool { } func (l *CacheListener) pathToKey(path string) string { - return strings.Replace(strings.Replace(path, l.rootPath+"/", "", -1), "/", ".", -1) + key := strings.Replace(strings.Replace(path, l.rootPath+"/", "", -1), "/", ".", -1) + if strings.HasSuffix(key, constant.CONFIGURATORS_SUFFIX) || + strings.HasSuffix(key, constant.TagRouterRuleSuffix) || + strings.HasSuffix(key, constant.ConditionRouterRuleSuffix) { + //governance config, so we remove the "dubbo." prefix + return key[strings.Index(key, ".")+1:] + } + return key } diff --git a/config_center/zookeeper/listener_test.go b/config_center/zookeeper/listener_test.go new file mode 100644 index 0000000000000000000000000000000000000000..a8c07549381ed3be0bac5a65fbc1036078e7cee7 --- /dev/null +++ b/config_center/zookeeper/listener_test.go @@ -0,0 +1,101 @@ +/* + * 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 zookeeper + +import ( + "path" + "strconv" + "testing" +) + +import ( + "github.com/dubbogo/go-zookeeper/zk" + "github.com/stretchr/testify/assert" +) + +import ( + "github.com/apache/dubbo-go/common" + "github.com/apache/dubbo-go/common/constant" + "github.com/apache/dubbo-go/config_center/parser" +) + +func initZkDynamicConfiguration(t *testing.T) (*zk.TestCluster, *zookeeperDynamicConfiguration) { + ts, err := zk.StartTestCluster(1, nil, nil) + assert.NoError(t, err) + assert.NotNil(t, ts.Servers[0]) + urlString := "registry://127.0.0.1:" + strconv.Itoa(ts.Servers[0].Port) + regurl, err := common.NewURL(urlString) + assert.NoError(t, err) + regurl.AddParam(constant.REGISTRY_TIMEOUT_KEY, "15s") + zkFactory := &zookeeperDynamicConfigurationFactory{} + reg, err := zkFactory.GetDynamicConfiguration(regurl) + zreg, ok := reg.(*zookeeperDynamicConfiguration) + assert.True(t, ok) + assert.NoError(t, err) + assert.True(t, zreg.IsAvailable()) + assert.Equal(t, zreg.GetUrl(), regurl) + assert.True(t, zreg.RestartCallBack()) + zreg.SetParser(&parser.DefaultConfigurationParser{}) + + data := ` + dubbo.application.name=dubbogo +` + err = zreg.client.Create(path.Join(zreg.rootPath, dubboPropertyFileName)) + assert.NoError(t, err) + _, err = zreg.client.Conn.Set(path.Join(zreg.rootPath, dubboPropertyFileName), []byte(data), 0) + assert.NoError(t, err) + + return ts, zreg +} + +func TestZookeeperDynamicConfigurationPathToKey(t *testing.T) { + ts, reg := initZkDynamicConfiguration(t) + defer func() { + err := ts.Stop() + assert.NoError(t, err) + }() + listener := &mockDataListener{} + key := path.Join("dubbogoDemo" + constant.CONFIGURATORS_SUFFIX) + reg.AddListener(key, listener) + listener.wg.Add(1) + + data := ` +scope: application +key: dubbogoDemo +enabled: true +configs: + - addresses: [0.0.0.0:20880] + side: provider + parameters: + weight: 60 + - addresses: [0.0.0.0:20881] + side: provider + parameters: + weight: 40 +` + zkPath := path.Join(reg.rootPath, "dubbo", key) + exists, _, err := reg.client.Conn.Exists(zkPath) + assert.NoError(t, err) + if !exists { + err = reg.client.Create(zkPath) + assert.NoError(t, err) + } + _, err = reg.client.SetContent(zkPath, []byte(data), 0) + assert.NoError(t, err) + listener.wg.Wait() + assert.Equal(t, key, listener.event) +} diff --git a/doc/pic/misc/dubbogo-wechat.png b/doc/pic/misc/dubbogo-wechat.png new file mode 100644 index 0000000000000000000000000000000000000000..dd34357199271dbb2bd977547d5bf1b90b3f6c70 Binary files /dev/null and b/doc/pic/misc/dubbogo-wechat.png differ