diff --git a/core/constants.go b/core/constants.go index 8f9e4f3c..5815bc9e 100644 --- a/core/constants.go +++ b/core/constants.go @@ -154,7 +154,7 @@ const ( DefaultMetaPrefix = "META_" EnvMetaPrefixKey = "envMetaPrefix" URLRegisterMeta = "registerMeta" - DefaultRegisterMeta = true + DefaultRegisterMeta = false MetaCacheExpireSecondKey = "metaCacheExpireSecond" DynamicMetaKey = "dynamicMeta" DefaultDynamicMeta = true @@ -163,7 +163,6 @@ const ( ServiceNotSupport = "service not support" ) - //----------- runtime ------------- const ( diff --git a/core/url.go b/core/url.go index 1a3b4e27..c1456f2e 100644 --- a/core/url.go +++ b/core/url.go @@ -328,7 +328,7 @@ func (u *URL) MergeParams(params map[string]string) { } func (u *URL) CanServe(other *URL) bool { - if u.Protocol != other.Protocol && u.Protocol != ProtocolLocal { + if !u.CanServeProtocol(other) { vlog.Errorf("can not serve protocol, err : p1:%s, p2:%s", u.Protocol, other.Protocol) return false } @@ -350,6 +350,14 @@ func (u *URL) CanServe(other *URL) bool { return true } +func (u *URL) CanServeProtocol(other *URL) bool { + // motanV1Compatible should compatible with motan2, motan and motanV1Compatible + if other.Protocol == "motanV1Compatible" && (u.Protocol == "motan2" || u.Protocol == "motan" || u.Protocol == "motanV1Compatible") { + return true + } + return u.Protocol == other.Protocol || u.Protocol == ProtocolLocal +} + func IsSame(m1 map[string]string, m2 map[string]string, key string, defaultValue string) bool { if m1 == nil && m2 == nil { return true diff --git a/core/url_test.go b/core/url_test.go index 73ca3a73..7ecda7fd 100644 --- a/core/url_test.go +++ b/core/url_test.go @@ -103,7 +103,7 @@ func TestCopyAndMerge(t *testing.T) { } } -func TestCanServer(t *testing.T) { +func TestCanServe(t *testing.T) { params1 := make(map[string]string) params2 := make(map[string]string) url1 := &URL{Protocol: "motan", Path: "test/path", Parameters: params1} @@ -146,6 +146,33 @@ func TestCanServer(t *testing.T) { t.Fatalf("url CanServe testFail url1: %+v, url2: %+v\n", url1, url2) } fmt.Printf("url1:%+v, url2:%+v\n", url1, url2) + url1.Path = "" + url2.Path = "" + url1.Protocol = "motan2" + url2.Protocol = "motanV1Compatible" + if !url1.CanServe(url2) { + t.Fatalf("url CanServe testFail url1: %+v, url2: %+v\n", url1, url2) + } + url1.Protocol = "motan" + url2.Protocol = "motanV1Compatible" + if !url1.CanServe(url2) { + t.Fatalf("url CanServe testFail url1: %+v, url2: %+v\n", url1, url2) + } + url1.Protocol = "local" + url2.Protocol = "motanV1Compatible" + if !url1.CanServe(url2) { + t.Fatalf("url CanServe testFail url1: %+v, url2: %+v\n", url1, url2) + } + url1.Protocol = "abc" + url2.Protocol = "motanV1Compatible" + if url1.CanServe(url2) { + t.Fatalf("url CanServe testFail url1: %+v, url2: %+v\n", url1, url2) + } + url1.Protocol = "motan" + url2.Protocol = "motan2" + if url1.CanServe(url2) { + t.Fatalf("url CanServe testFail url1: %+v, url2: %+v\n", url1, url2) + } } func TestGetPositiveIntValue(t *testing.T) { diff --git a/dynamicConfig.go b/dynamicConfig.go index 47c5efac..52be20c2 100644 --- a/dynamicConfig.go +++ b/dynamicConfig.go @@ -128,6 +128,10 @@ func (c *DynamicConfigurer) doUnregister(url *core.URL) error { } func (c *DynamicConfigurer) Subscribe(url *core.URL) error { + // use motanV1Compatible to compatible with protocol: motan + if url.Protocol == "motan" { + url.Protocol = "motanV1Compatible" + } err := c.doSubscribe(url) if err != nil { return err