Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
c0839f0a
Commit
c0839f0a
authored
Dec 17, 2019
by
xujianhai666
Browse files
Options
Downloads
Patches
Plain Diff
support zkpath urlencoder
parent
d65659ff
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
registry/zookeeper/registry.go
+10
-6
10 additions, 6 deletions
registry/zookeeper/registry.go
remoting/zookeeper/listener_test.go
+7
-0
7 additions, 0 deletions
remoting/zookeeper/listener_test.go
with
17 additions
and
6 deletions
registry/zookeeper/registry.go
+
10
−
6
View file @
c0839f0a
...
@@ -261,6 +261,10 @@ func (r *zkRegistry) Register(conf common.URL) error {
...
@@ -261,6 +261,10 @@ func (r *zkRegistry) Register(conf common.URL) error {
return
nil
return
nil
}
}
func
(
r
*
zkRegistry
)
service
(
c
common
.
URL
)
string
{
return
url
.
QueryEscape
(
c
.
Service
())
}
func
(
r
*
zkRegistry
)
register
(
c
common
.
URL
)
error
{
func
(
r
*
zkRegistry
)
register
(
c
common
.
URL
)
error
{
var
(
var
(
err
error
err
error
...
@@ -296,7 +300,7 @@ func (r *zkRegistry) register(c common.URL) error {
...
@@ -296,7 +300,7 @@ func (r *zkRegistry) register(c common.URL) error {
return
perrors
.
Errorf
(
"conf{Path:%s, Methods:%s}"
,
c
.
Path
,
c
.
Methods
)
return
perrors
.
Errorf
(
"conf{Path:%s, Methods:%s}"
,
c
.
Path
,
c
.
Methods
)
}
}
// 先创建服务下面的provider node
// 先创建服务下面的provider node
dubboPath
=
fmt
.
Sprintf
(
"/dubbo/%s/%s"
,
c
.
S
ervice
(),
common
.
DubboNodes
[
common
.
PROVIDER
])
dubboPath
=
fmt
.
Sprintf
(
"/dubbo/%s/%s"
,
r
.
s
ervice
(
c
),
common
.
DubboNodes
[
common
.
PROVIDER
])
r
.
cltLock
.
Lock
()
r
.
cltLock
.
Lock
()
err
=
r
.
client
.
Create
(
dubboPath
)
err
=
r
.
client
.
Create
(
dubboPath
)
r
.
cltLock
.
Unlock
()
r
.
cltLock
.
Unlock
()
...
@@ -330,11 +334,11 @@ func (r *zkRegistry) register(c common.URL) error {
...
@@ -330,11 +334,11 @@ func (r *zkRegistry) register(c common.URL) error {
encodedURL
=
url
.
QueryEscape
(
rawURL
)
encodedURL
=
url
.
QueryEscape
(
rawURL
)
// Print your own registration service providers.
// Print your own registration service providers.
dubboPath
=
fmt
.
Sprintf
(
"/dubbo/%s/%s"
,
c
.
S
ervice
(),
(
common
.
RoleType
(
common
.
PROVIDER
))
.
String
())
dubboPath
=
fmt
.
Sprintf
(
"/dubbo/%s/%s"
,
r
.
s
ervice
(
c
),
(
common
.
RoleType
(
common
.
PROVIDER
))
.
String
())
logger
.
Debugf
(
"provider path:%s, url:%s"
,
dubboPath
,
rawURL
)
logger
.
Debugf
(
"provider path:%s, url:%s"
,
dubboPath
,
rawURL
)
case
common
.
CONSUMER
:
case
common
.
CONSUMER
:
dubboPath
=
fmt
.
Sprintf
(
"/dubbo/%s/%s"
,
c
.
S
ervice
(),
common
.
DubboNodes
[
common
.
CONSUMER
])
dubboPath
=
fmt
.
Sprintf
(
"/dubbo/%s/%s"
,
r
.
s
ervice
(
c
),
common
.
DubboNodes
[
common
.
CONSUMER
])
r
.
cltLock
.
Lock
()
r
.
cltLock
.
Lock
()
err
=
r
.
client
.
Create
(
dubboPath
)
err
=
r
.
client
.
Create
(
dubboPath
)
r
.
cltLock
.
Unlock
()
r
.
cltLock
.
Unlock
()
...
@@ -342,7 +346,7 @@ func (r *zkRegistry) register(c common.URL) error {
...
@@ -342,7 +346,7 @@ func (r *zkRegistry) register(c common.URL) error {
logger
.
Errorf
(
"zkClient.create(path{%s}) = error{%v}"
,
dubboPath
,
perrors
.
WithStack
(
err
))
logger
.
Errorf
(
"zkClient.create(path{%s}) = error{%v}"
,
dubboPath
,
perrors
.
WithStack
(
err
))
return
perrors
.
WithStack
(
err
)
return
perrors
.
WithStack
(
err
)
}
}
dubboPath
=
fmt
.
Sprintf
(
"/dubbo/%s/%s"
,
c
.
S
ervice
(),
common
.
DubboNodes
[
common
.
PROVIDER
])
dubboPath
=
fmt
.
Sprintf
(
"/dubbo/%s/%s"
,
r
.
s
ervice
(
c
),
common
.
DubboNodes
[
common
.
PROVIDER
])
r
.
cltLock
.
Lock
()
r
.
cltLock
.
Lock
()
err
=
r
.
client
.
Create
(
dubboPath
)
err
=
r
.
client
.
Create
(
dubboPath
)
r
.
cltLock
.
Unlock
()
r
.
cltLock
.
Unlock
()
...
@@ -359,7 +363,7 @@ func (r *zkRegistry) register(c common.URL) error {
...
@@ -359,7 +363,7 @@ func (r *zkRegistry) register(c common.URL) error {
rawURL
=
fmt
.
Sprintf
(
"consumer://%s%s?%s"
,
localIP
,
c
.
Path
,
params
.
Encode
())
rawURL
=
fmt
.
Sprintf
(
"consumer://%s%s?%s"
,
localIP
,
c
.
Path
,
params
.
Encode
())
encodedURL
=
url
.
QueryEscape
(
rawURL
)
encodedURL
=
url
.
QueryEscape
(
rawURL
)
dubboPath
=
fmt
.
Sprintf
(
"/dubbo/%s/%s"
,
c
.
S
ervice
(),
(
common
.
RoleType
(
common
.
CONSUMER
))
.
String
())
dubboPath
=
fmt
.
Sprintf
(
"/dubbo/%s/%s"
,
r
.
s
ervice
(
c
),
(
common
.
RoleType
(
common
.
CONSUMER
))
.
String
())
logger
.
Debugf
(
"consumer path:%s, url:%s"
,
dubboPath
,
rawURL
)
logger
.
Debugf
(
"consumer path:%s, url:%s"
,
dubboPath
,
rawURL
)
default
:
default
:
...
@@ -479,7 +483,7 @@ func (r *zkRegistry) getListener(conf *common.URL) (*RegistryConfigurationListen
...
@@ -479,7 +483,7 @@ func (r *zkRegistry) getListener(conf *common.URL) (*RegistryConfigurationListen
//Interested register to dataconfig.
//Interested register to dataconfig.
r
.
dataListener
.
AddInterestedURL
(
conf
)
r
.
dataListener
.
AddInterestedURL
(
conf
)
for
_
,
v
:=
range
strings
.
Split
(
conf
.
GetParam
(
constant
.
CATEGORY_KEY
,
constant
.
DEFAULT_CATEGORY
),
","
)
{
for
_
,
v
:=
range
strings
.
Split
(
conf
.
GetParam
(
constant
.
CATEGORY_KEY
,
constant
.
DEFAULT_CATEGORY
),
","
)
{
go
r
.
listener
.
ListenServiceEvent
(
fmt
.
Sprintf
(
"/dubbo/%s/"
+
v
,
conf
.
Service
()),
r
.
dataListener
)
go
r
.
listener
.
ListenServiceEvent
(
fmt
.
Sprintf
(
"/dubbo/%s/"
+
v
,
url
.
QueryEscape
(
conf
.
Service
())
)
,
r
.
dataListener
)
}
}
return
zkListener
,
nil
return
zkListener
,
nil
...
...
This diff is collapsed.
Click to expand it.
remoting/zookeeper/listener_test.go
+
7
−
0
View file @
c0839f0a
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
package
zookeeper
package
zookeeper
import
(
import
(
"net/url"
"sync"
"sync"
"testing"
"testing"
"time"
"time"
...
@@ -122,3 +123,9 @@ func (m *mockDataListener) DataChange(eventType remoting.Event) bool {
...
@@ -122,3 +123,9 @@ func (m *mockDataListener) DataChange(eventType remoting.Event) bool {
}
}
return
true
return
true
}
}
func
TestZkPath
(
t
*
testing
.
T
)
{
zkPath
:=
"io.grpc.examples.helloworld.GreeterGrpc$IGreeter"
zkPath
=
url
.
QueryEscape
(
zkPath
)
assert
.
Equal
(
t
,
zkPath
,
"io.grpc.examples.helloworld.GreeterGrpc%24IGreeter"
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment