Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
7f87ea6f
Commit
7f87ea6f
authored
5 years ago
by
lzp0412
Browse files
Options
Downloads
Patches
Plain Diff
coding standard
parent
0c987d33
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
registry/nacos/listener.go
+12
-12
12 additions, 12 deletions
registry/nacos/listener.go
registry/nacos/registry_test.go
+1
-1
1 addition, 1 deletion
registry/nacos/registry_test.go
with
13 additions
and
13 deletions
registry/nacos/listener.go
+
12
−
12
View file @
7f87ea6f
...
...
@@ -24,21 +24,21 @@ import (
)
type
nacosListener
struct
{
namingClient
naming_client
.
INamingClient
listenUrl
common
.
URL
events
chan
*
remoting
.
ConfigChangeEvent
hostMapI
nstance
map
[
string
]
model
.
Instance
cacheLock
sync
.
Mutex
done
chan
struct
{}
subscribeParam
*
vo
.
SubscribeParam
namingClient
naming_client
.
INamingClient
listenUrl
common
.
URL
events
chan
*
remoting
.
ConfigChangeEvent
i
nstance
Map
map
[
string
]
model
.
Instance
cacheLock
sync
.
Mutex
done
chan
struct
{}
subscribeParam
*
vo
.
SubscribeParam
}
func
NewNacosListener
(
url
common
.
URL
,
namingClient
naming_client
.
INamingClient
)
(
*
nacosListener
,
error
)
{
listener
:=
&
nacosListener
{
namingClient
:
namingClient
,
listenUrl
:
url
,
events
:
make
(
chan
*
remoting
.
ConfigChangeEvent
,
32
),
hostMapI
nstance
:
map
[
string
]
model
.
Instance
{},
done
:
make
(
chan
struct
{}),
i
nstance
Map
:
map
[
string
]
model
.
Instance
{},
done
:
make
(
chan
struct
{}),
}
err
:=
listener
.
startListen
()
return
listener
,
err
...
...
@@ -111,7 +111,7 @@ func (nl *nacosListener) Callback(services []model.SubscribeService, err error)
host
:=
services
[
i
]
.
Ip
+
":"
+
strconv
.
Itoa
(
int
(
services
[
i
]
.
Port
))
instance
:=
generateInstance
(
services
[
i
])
newInstanceMap
[
host
]
=
instance
if
old
,
ok
:=
nl
.
hostMapI
nstance
[
host
];
!
ok
{
if
old
,
ok
:=
nl
.
i
nstance
Map
[
host
];
!
ok
{
//instance is not exsit in cache,add it to cache
addInstances
=
append
(
addInstances
,
instance
)
}
else
{
...
...
@@ -122,14 +122,14 @@ func (nl *nacosListener) Callback(services []model.SubscribeService, err error)
}
}
for
host
,
inst
:=
range
nl
.
hostMapI
nstance
{
for
host
,
inst
:=
range
nl
.
i
nstance
Map
{
if
_
,
ok
:=
newInstanceMap
[
host
];
!
ok
{
//cache instance is not exsit in new instance list, remove it from cache
delInstances
=
append
(
delInstances
,
inst
)
}
}
nl
.
hostMapI
nstance
=
newInstanceMap
nl
.
i
nstance
Map
=
newInstanceMap
for
i
:=
range
addInstances
{
newUrl
:=
generateUrl
(
addInstances
[
i
])
...
...
This diff is collapsed.
Click to expand it.
registry/nacos/registry_test.go
+
1
−
1
View file @
7f87ea6f
...
...
@@ -139,7 +139,7 @@ func TestNacosRegistry_Subscribe_del(t *testing.T) {
assert
.
Regexp
(
t
,
".*ServiceEvent{Action{add}.*"
,
serviceEvent2
.
String
())
nacosReg
:=
reg
.
(
*
nacosRegistry
)
//
手动注销实例
//
deregister instance to mock instance offline
nacosReg
.
namingClient
.
DeregisterInstance
(
vo
.
DeregisterInstanceParam
{
Ip
:
"127.0.0.2"
,
Port
:
20000
,
ServiceName
:
"providers:com.ikurento.user.UserProvider:1.0.0:guangzhou-idc"
})
serviceEvent3
,
_
:=
listener
.
Next
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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