Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
service-registry
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
Odysseus
service-registry
Commits
009e92dd
Commit
009e92dd
authored
Mar 04, 2024
by
luxq
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update registry
parent
8945889f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
6 deletions
+13
-6
registry.go
registry/registry.go
+13
-6
No files found.
registry/registry.go
View file @
009e92dd
...
@@ -12,6 +12,10 @@ import (
...
@@ -12,6 +12,10 @@ import (
"time"
"time"
)
)
const
(
REGISTRY_SERVICE_INSTANCE
=
"REGISTRY_SERVICE_INSTANCE"
)
type
RegistryInfo
struct
{
type
RegistryInfo
struct
{
Timestamp
int64
`redis:"timestamp" json:"timestamp"`
Timestamp
int64
`redis:"timestamp" json:"timestamp"`
Instance
string
`redis:"instance" json:"instance"`
// example: hostip + hostname
Instance
string
`redis:"instance" json:"instance"`
// example: hostip + hostname
...
@@ -30,7 +34,6 @@ func (g RegistryInfo) Message() json.RawMessage {
...
@@ -30,7 +34,6 @@ func (g RegistryInfo) Message() json.RawMessage {
type
Register
interface
{
type
Register
interface
{
ServiceType
()
common
.
ServiceType
ServiceType
()
common
.
ServiceType
Instance
()
string
Status
()
string
Status
()
string
DetailInfo
()
(
json
.
RawMessage
,
error
)
DetailInfo
()
(
json
.
RawMessage
,
error
)
}
}
...
@@ -39,16 +42,19 @@ type Registry struct {
...
@@ -39,16 +42,19 @@ type Registry struct {
rdb
*
redis
.
Client
rdb
*
redis
.
Client
rw
sync
.
RWMutex
rw
sync
.
RWMutex
register
Register
register
Register
opts
[]
InstanceOpt
quit
chan
struct
{}
quit
chan
struct
{}
}
}
type
InstanceOpt
func
()
string
type
RedisConnParam
struct
{
type
RedisConnParam
struct
{
Addr
string
Addr
string
Password
string
Password
string
DbIndex
int
DbIndex
int
}
}
func
NewRegistry
(
redisParam
RedisConnParam
,
register
Register
)
*
Registry
{
func
NewRegistry
(
redisParam
RedisConnParam
,
register
Register
,
opts
...
InstanceOpt
)
*
Registry
{
switch
register
.
ServiceType
()
{
switch
register
.
ServiceType
()
{
case
common
.
SERVICE_NODE_MANAGER
,
common
.
SERVICE_API_GATEWAY
,
common
.
SERVICE_BACKEND
,
common
.
SERVICE_SCHEDULER
,
common
.
SERVICE_WORKER
:
case
common
.
SERVICE_NODE_MANAGER
,
common
.
SERVICE_API_GATEWAY
,
common
.
SERVICE_BACKEND
,
common
.
SERVICE_SCHEDULER
,
common
.
SERVICE_WORKER
:
//nothing
//nothing
...
@@ -65,6 +71,7 @@ func NewRegistry(redisParam RedisConnParam, register Register) *Registry {
...
@@ -65,6 +71,7 @@ func NewRegistry(redisParam RedisConnParam, register Register) *Registry {
return
&
Registry
{
return
&
Registry
{
rdb
:
rdb
,
rdb
:
rdb
,
register
:
register
,
register
:
register
,
opts
:
opts
,
quit
:
make
(
chan
struct
{}),
quit
:
make
(
chan
struct
{}),
}
}
}
}
...
@@ -92,17 +99,17 @@ func (s *Registry) Stop() {
...
@@ -92,17 +99,17 @@ func (s *Registry) Stop() {
}
}
func
(
s
*
Registry
)
registry
(
rdb
*
redis
.
Client
)
error
{
func
(
s
*
Registry
)
registry
(
rdb
*
redis
.
Client
)
error
{
k
:=
fmt
.
Sprintf
(
"%s%s"
,
common
.
GetServiceKeyPrefix
(
s
.
register
.
ServiceType
()),
s
.
register
.
Instance
())
detail
,
err
:=
s
.
register
.
DetailInfo
()
detail
,
err
:=
s
.
register
.
DetailInfo
()
if
err
!=
nil
{
if
err
!=
nil
{
log
.
WithError
(
err
)
.
Error
(
"get detail info failed"
)
log
.
WithError
(
err
)
.
Error
(
"get detail info failed"
)
return
err
return
err
}
}
status
:=
s
.
register
.
Status
()
status
:=
s
.
register
.
Status
()
instance
:=
os
.
Getenv
(
"SERVICE_INSTANCE"
)
instance
:=
os
.
Getenv
(
REGISTRY_SERVICE_INSTANCE
)
if
len
(
instance
)
==
0
{
for
_
,
opt
:=
range
s
.
opts
{
instance
=
s
.
register
.
Instance
()
instance
=
opt
()
}
}
k
:=
fmt
.
Sprintf
(
"%s%s"
,
common
.
GetServiceKeyPrefix
(
s
.
register
.
ServiceType
()),
instance
)
err
=
rdb
.
HSet
(
context
.
Background
(),
k
,
RegistryInfo
{
err
=
rdb
.
HSet
(
context
.
Background
(),
k
,
RegistryInfo
{
Timestamp
:
time
.
Now
()
.
Unix
(),
Timestamp
:
time
.
Now
()
.
Unix
(),
...
...
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