代码拉取完成,页面将自动刷新
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)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。