Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-common
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujiebin
hilo-common
Commits
fe793910
Commit
fe793910
authored
Mar 21, 2023
by
hujiebin
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:连上consul,才做服务发现
parent
8e3bcea7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
24 deletions
+24
-24
user_center.go
rpc/user_center.go
+24
-24
No files found.
rpc/user_center.go
View file @
fe793910
...
...
@@ -102,33 +102,33 @@ func init() {
}
mylogrus
.
MyLog
.
Infof
(
"userCenterAddr:%v,addr:%v"
,
userCenterAddr
,
addrs
)
}
}
mylogrus
.
MyLog
.
Infof
(
"connect userCenterAddr:%v"
,
userCenterAddr
)
resolver
.
Register
(
bd
)
go
func
(
)
{
address
:=
consulapi
.
DefaultConfig
()
.
Address
// 用consul api的default config
if
err
:=
consul
.
RegisterWatcher
(
"services"
,
nil
,
address
,
func
(
serviceStatus
map
[
string
]
map
[
string
][]
string
)
{
if
statusAddrs
,
ok
:=
serviceStatus
[
userCenterConsulName
];
ok
{
healthAddrs
,
_
:=
statusAddrs
[
consulapi
.
HealthPassing
]
l
:=
len
(
healthAddrs
)
if
l
>
0
{
mylogrus
.
MyLog
.
Infof
(
"consul service update state:%v-%v"
,
userCenterConsulName
,
healthAddrs
)
bd
.
UpdateState
(
healthAddrs
)
// 更新新的注册名
}
else
{
mylogrus
.
MyLog
.
Warnf
(
"consul service update local state:%v-%v"
,
userCenterConsulName
,
defaultUserCenterAddr
)
bd
.
UpdateState
([]
string
{
defaultUserCenterAddr
})
// 都没有健康的,使用默认本地回环的
}
for
status
:=
range
statusAddrs
{
if
status
==
consulapi
.
HealthPassing
{
continue
resolver
.
Register
(
bd
)
// 服务注册
go
func
()
{
address
:=
consulapi
.
DefaultConfig
()
.
Address
// 用consul api的default config
if
err
:=
consul
.
RegisterWatcher
(
"services"
,
nil
,
address
,
func
(
serviceStatus
map
[
string
]
map
[
string
][]
string
)
{
if
statusAddrs
,
ok
:=
serviceStatus
[
userCenterConsulName
];
ok
{
healthAddrs
,
_
:=
statusAddrs
[
consulapi
.
HealthPassing
]
l
:=
len
(
healthAddrs
)
if
l
>
0
{
mylogrus
.
MyLog
.
Infof
(
"consul service update state:%v-%v"
,
userCenterConsulName
,
healthAddrs
)
bd
.
UpdateState
(
healthAddrs
)
// 更新新的注册名
}
else
{
mylogrus
.
MyLog
.
Warnf
(
"consul service update local state:%v-%v"
,
userCenterConsulName
,
defaultUserCenterAddr
)
bd
.
UpdateState
([]
string
{
defaultUserCenterAddr
})
// 都没有健康的,使用默认本地回环的
}
for
status
:=
range
statusAddrs
{
if
status
==
consulapi
.
HealthPassing
{
continue
}
mylogrus
.
MyLog
.
Warnf
(
"consul service wrong state:%v-%v-%v"
,
userCenterConsulName
,
status
,
statusAddrs
[
status
])
}
mylogrus
.
MyLog
.
Warnf
(
"consul service wrong state:%v-%v-%v"
,
userCenterConsulName
,
status
,
statusAddrs
[
status
])
}
});
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"启动 consul 的watch监控失败"
)
}
});
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"启动 consul 的watch监控失败"
)
}
}()
}()
}
mylogrus
.
MyLog
.
Infof
(
"connect userCenterAddr:%v"
,
userCenterAddr
)
//userCenterAddr := services[0].Address + ":" + strconv.Itoa(services[0].ServicePort)
//mylogrus.MyLog.Printf("Choose userCenter %s, %s, weights: %v\n", services[0].ID, userCenterAddr, services[0].ServiceWeights)
...
...
hujiebin
@hujiebin
mentioned in commit
ad6f7ca0
·
Mar 21, 2023
mentioned in commit
ad6f7ca0
mentioned in commit ad6f7ca0f4e395b612a9f22472c46ef8280663cb
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment