Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-userCenter
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-userCenter
Commits
ef02152e
Commit
ef02152e
authored
Mar 25, 2024
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:broadcast 有话
parent
71bff772
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
2 deletions
+32
-2
main.go
main.go
+32
-2
No files found.
main.go
View file @
ef02152e
...
...
@@ -2,8 +2,10 @@ package main
import
(
"context"
"errors"
"flag"
"fmt"
"github.com/golang/protobuf/proto"
"gorm.io/gorm/schema"
"net"
"net/url"
...
...
@@ -196,7 +198,7 @@ func (s *server) Multicast(ctx context.Context, in *userCenter.MulticastMessage)
return
&
userCenter
.
MulticastMessageRsp
{
FailedUids
:
failed
},
nil
}
func
(
s
*
server
)
Broadcast
(
ctx
context
.
Context
,
in
*
userCenter
.
BroadcastMessage
)
(
*
userCenter
.
BroadcastMessageRsp
,
error
)
{
func
(
s
*
server
)
Broadcast
Old
(
ctx
context
.
Context
,
in
*
userCenter
.
BroadcastMessage
)
(
*
userCenter
.
BroadcastMessageRsp
,
error
)
{
//mylogrus.MyLog.Infof("Broadcasting msgType = %d, size = %d\n", in.MsgType, len(in.PayLoad))
failed
:=
[]
uint64
{}
...
...
@@ -249,6 +251,32 @@ func (s *server) Broadcast(ctx context.Context, in *userCenter.BroadcastMessage)
return
&
userCenter
.
BroadcastMessageRsp
{
FailedUids
:
failed
},
nil
}
func
(
s
*
server
)
Broadcast
(
ctx
context
.
Context
,
in
*
userCenter
.
BroadcastMessage
)
(
*
userCenter
.
BroadcastMessageRsp
,
error
)
{
redisKey
:=
"service:userSocket"
ipPorts
,
err
:=
rdbCluster
.
ZRangeByScore
(
context
.
Background
(),
redisKey
,
&
redis
.
ZRangeBy
{
Min
:
fmt
.
Sprintf
(
"%d"
,
time
.
Now
()
.
Add
(
-
time
.
Second
*
15
)
.
Unix
()),
// 3倍心跳
Max
:
"+inf"
,
})
.
Result
()
if
err
!=
nil
{
failMsg
:=
fmt
.
Sprintf
(
"get service fail,svc:%v,err:%v"
,
"userSocket"
,
err
)
mylogrus
.
MyLog
.
Errorf
(
failMsg
)
_
=
dingding
.
SendDingRobot
(
dingding
.
ROBOTWEBHOOK
,
failMsg
,
true
)
return
nil
,
err
}
if
len
(
ipPorts
)
<=
0
{
failMsg
:=
fmt
.
Sprintf
(
"get service empty,svc:%v,err:%v"
,
"userSocket"
,
err
)
mylogrus
.
MyLog
.
Errorf
(
failMsg
)
_
=
dingding
.
SendDingRobot
(
dingding
.
ROBOTWEBHOOK
,
failMsg
,
true
)
return
nil
,
errors
.
New
(
failMsg
)
}
data
,
_
:=
proto
.
Marshal
(
in
)
for
_
,
ip
:=
range
ipPorts
{
queue
:=
"broadcast:"
+
ip
rdbCluster
.
RPush
(
context
.
Background
(),
queue
,
data
)
}
return
&
userCenter
.
BroadcastMessageRsp
{
FailedUids
:
nil
},
nil
}
func
(
s
*
server
)
Areacast
(
ctx
context
.
Context
,
in
*
userCenter
.
AreaMessage
)
(
*
userCenter
.
AreaMessageRsp
,
error
)
{
var
failed
[]
uint64
terminals
:=
termManager
.
GetAll
()
...
...
@@ -558,11 +586,13 @@ type HiloConfigs struct {
Value
string
}
var
rdbCluster
*
redis
.
Client
func
main
()
{
flag
.
Parse
()
// init redis cluster
rdbCluster
:
=
redis
.
NewClient
(
&
redis
.
Options
{
rdbCluster
=
redis
.
NewClient
(
&
redis
.
Options
{
Addr
:
appConfig
.
GetConfigRedis
()
.
REDIS_CLUSTER_HOST
,
Password
:
appConfig
.
GetConfigRedis
()
.
REDIS_CLUSTER_PASSWORD
,
})
...
...
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