Skip to content
Snippets Groups Projects
Commit dc5e052f authored by Joe Zou's avatar Joe Zou Committed by GitHub
Browse files

Merge pull request #443 from hxmhlt/code_enhance_of_urlinit

Mod:enhance url init code
parents 47c8e289 6ecc67b5
No related branches found
No related tags found
No related merge requests found
......@@ -2,7 +2,6 @@ language: go
os:
- linux
- osx
go:
- "1.13"
......
......@@ -40,7 +40,8 @@ const (
TOKEN_KEY = "token"
LOCAL_ADDR = "local-addr"
REMOTE_ADDR = "remote-addr"
PATH_SEPARATOR = "/"
DUBBO_KEY = "dubbo"
ANYHOST_KEY = "anyhost"
)
const (
......
......@@ -185,6 +185,10 @@ 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.CATEGORY_KEY, (common.RoleType(common.CONSUMER)).String())
urlMap.Set(constant.DUBBO_KEY, "dubbo-consumer-golang-"+constant.Version)
urlMap.Set(constant.SIDE_KEY, (common.RoleType(common.CONSUMER)).Role())
if len(c.RequestTimeout) != 0 {
urlMap.Set(constant.TIMEOUT_KEY, c.RequestTimeout)
}
......
......@@ -193,6 +193,10 @@ func (c *ServiceConfig) getUrlMap() url.Values {
urlMap.Set(constant.GROUP_KEY, c.Group)
urlMap.Set(constant.VERSION_KEY, c.Version)
urlMap.Set(constant.ROLE_KEY, strconv.Itoa(common.PROVIDER))
urlMap.Set(constant.CATEGORY_KEY, (common.RoleType(common.PROVIDER)).String())
urlMap.Set(constant.DUBBO_KEY, "dubbo-provider-golang-"+constant.Version)
urlMap.Set(constant.SIDE_KEY, (common.RoleType(common.PROVIDER)).Role())
// application info
urlMap.Set(constant.APPLICATION_KEY, providerConfig.ApplicationConfig.Name)
urlMap.Set(constant.ORGANIZATION_KEY, providerConfig.ApplicationConfig.Organization)
......
......@@ -245,19 +245,13 @@ func (r *BaseRegistry) providerRegistry(c common.URL, params url.Values) (string
logger.Errorf("facadeBasedRegistry.CreatePath(path{%s}) = error{%#v}", dubboPath, perrors.WithStack(err))
return "", "", perrors.WithMessagef(err, "facadeBasedRegistry.CreatePath(path:%s)", dubboPath)
}
params.Add("anyhost", "true")
params.Add(constant.ANYHOST_KEY, "true")
// Dubbo java consumer to start looking for the provider url,because the category does not match,
// the provider will not find, causing the consumer can not start, so we use consumers.
// DubboRole = [...]string{"consumer", "", "", "provider"}
// params.Add("category", (RoleType(PROVIDER)).Role())
params.Add("category", (common.RoleType(common.PROVIDER)).String())
params.Add("dubbo", "dubbo-provider-golang-"+constant.Version)
params.Add("side", (common.RoleType(common.PROVIDER)).Role())
if len(c.Methods) == 0 {
params.Add("methods", strings.Join(c.Methods, ","))
params.Add(constant.METHODS_KEY, strings.Join(c.Methods, ","))
}
logger.Debugf("provider url params:%#v", params)
var host string
......@@ -308,9 +302,6 @@ func (r *BaseRegistry) consumerRegistry(c common.URL, params url.Values) (string
}
params.Add("protocol", c.Protocol)
params.Add("category", (common.RoleType(common.CONSUMER)).String())
params.Add("dubbo", "dubbogo-consumer-"+constant.Version)
rawURL = fmt.Sprintf("consumer://%s%s?%s", localIP, c.Path, params.Encode())
dubboPath = fmt.Sprintf("/dubbo/%s/%s", r.service(c), (common.RoleType(common.CONSUMER)).String())
......
......@@ -63,7 +63,7 @@ func (suite *RegistryTestSuite) TestRegister() {
if err != nil {
t.Fatal(err)
}
assert.Regexp(t, ".*dubbo%3A%2F%2F127.0.0.1%3A20000%2Fcom.ikurento.user.UserProvider%3Fanyhost%3Dtrue%26category%3Dproviders%26cluster%3Dmock%26dubbo%3Ddubbo-provider-golang-1.3.0%26.*provider", children)
assert.Regexp(t, ".*dubbo%3A%2F%2F127.0.0.1%3A20000%2Fcom.ikurento.user.UserProvider%3Fanyhost%3Dtrue%26cluster%3Dmock", children)
assert.NoError(t, err)
}
......
......@@ -41,7 +41,7 @@ func Test_Register(t *testing.T) {
defer ts.Stop()
err := reg.Register(url)
children, _ := reg.client.GetChildren("/dubbo/com.ikurento.user.UserProvider/providers")
assert.Regexp(t, ".*dubbo%3A%2F%2F127.0.0.1%3A20000%2Fcom.ikurento.user.UserProvider%3Fanyhost%3Dtrue%26category%3Dproviders%26cluster%3Dmock%26dubbo%3Ddubbo-provider-golang-1.3.0%26.*.serviceid%3Dsoa.mock%26.*provider", children)
assert.Regexp(t, ".*dubbo%3A%2F%2F127.0.0.1%3A20000%2Fcom.ikurento.user.UserProvider%3Fanyhost%3Dtrue%26cluster%3Dmock%26.*.serviceid%3Dsoa.mock", children)
assert.NoError(t, err)
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment