1 Star 0 Fork 0

jmesyan/kudos

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
channelService.go 2.08 KB
一键复制 编辑 原始数据 按行查看 历史
jmesyan 提交于 2020-12-07 23:29 +08:00 . v3 init
package channelService
import (
"sync"
"gitee.com/jmesyan/kudos/v3/log"
"gitee.com/jmesyan/kudos/v3/rpc"
"gitee.com/jmesyan/kudos/v3/service/codecService"
"gitee.com/jmesyan/kudos/v3/service/rpcClientService"
)
var _channelService *ChannelService
var once sync.Once
type ChannelService struct {
channels sync.Map
}
func GetChannelService() *ChannelService {
once.Do(func() {
_channelService = &ChannelService{
}
})
return _channelService
}
func (c *ChannelService) CreateChannel(name string) *Channel {
channel := NewChannel(name)
c.channels.Store(name, channel)
return channel
}
func (c *ChannelService) DestroyChannel(name string) {
c.channels.Delete(name)
}
func (c *ChannelService) GetChannel(name string) *Channel {
channel, ok := c.channels.Load(name)
if ok {
return channel.(*Channel)
}
return nil
}
func (c *ChannelService) PushMessageBySid(nodeId string, route string, msg interface{}, sids []int64) {
data, err := codecService.GetCodecService().Marshal(msg)
if err != nil {
log.Error("marshal error: %v", err)
}
args := &rpc.ArgsGroup{
Sids: sids,
Route: route,
Payload: data,
}
reply := &rpc.ReplyGroup{}
rpcClientService.GetRpcClientService().Call(nodeId+"@ChannelRemote","PushMessageByGroup", args, reply)
}
func (c *ChannelService) AsyncPushMessageBySid(nodeId string, route string, msg interface{}, sids []int64) {
data, err := codecService.GetCodecService().Marshal(msg)
if err != nil {
log.Error("marshal error: %v", err)
}
args := &rpc.ArgsGroup{
Sids: sids,
Route: route,
Payload: data,
}
reply := &rpc.ReplyGroup{}
rpcClientService.GetRpcClientService().Go(nodeId+"@ChannelRemote","PushMessageByGroup", args, reply, nil)
}
func (c *ChannelService) Broadcast(nodeId string, route string, msg interface{}) {
data, err := codecService.GetCodecService().Marshal(msg)
if err != nil {
log.Error("marshal error: %v", err)
}
args := &rpc.ArgsGroup{
Sids: []int64{},
Route: route,
Payload: data,
}
reply := &rpc.ReplyGroup{}
rpcClientService.GetRpcClientService().Go(nodeId+"@ChannelRemote","Broadcast", args, reply, nil)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jmesyan/kudos.git
git@gitee.com:jmesyan/kudos.git
jmesyan
kudos
kudos
v3.0.1

搜索帮助