本文整理汇总了Golang中github.com/Terry-Mao/gopush-cluster/rpc.Message类的典型用法代码示例。如果您正苦于以下问题:Golang Message类的具体用法?Golang Message怎么用?Golang Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Message类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: writeMsg
// writeMsg write msg to conn.
func (c *SeqChannel) writeMsg(key string, m *myrpc.Message) (err error) {
var (
oldMsg, msg, sendMsg []byte
)
// push message
for e := c.conn.Front(); e != nil; e = e.Next() {
conn, _ := e.Value.(*Connection)
// if version empty then use old protocol
if conn.Version == "" {
if oldMsg == nil {
if oldMsg, err = m.OldBytes(); err != nil {
return
}
}
sendMsg = oldMsg
} else {
if msg == nil {
if msg, err = m.Bytes(); err != nil {
return
}
}
sendMsg = msg
}
// TODO use goroutine
conn.Write(key, sendMsg)
}
return
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:29,代码来源:seq_channel.go
示例2: PushMsg
// PushMsg implements the Channel PushMsg method.
func (c *SeqChannel) PushMsg(key string, m *myrpc.Message, expire uint) error {
var (
oldMsg, msg, sendMsg []byte
err error
)
client := myrpc.MessageRPC.Get()
if client == nil {
return ErrMessageRPC
}
c.mutex.Lock()
// private message need persistence
// if message expired no need persistence, only send online message
// rewrite message id
m.MsgId = c.timeID.ID()
if m.GroupId != myrpc.PublicGroupId && expire > 0 {
args := &myrpc.MessageSavePrivateArgs{Key: key, Msg: m.Msg, MsgId: m.MsgId, Expire: expire}
ret := 0
if err = client.Call(myrpc.MessageServiceSavePrivate, args, &ret); err != nil {
c.mutex.Unlock()
glog.Errorf("%s(\"%s\", \"%v\", &ret) error(%v)", myrpc.MessageServiceSavePrivate, key, args, err)
return err
}
}
// push message
for e := c.conn.Front(); e != nil; e = e.Next() {
conn, _ := e.Value.(*Connection)
// if version empty then use old protocol
if conn.Version == "" {
if oldMsg == nil {
oldMsg, err = m.OldBytes()
if err != nil {
c.mutex.Unlock()
return err
}
}
sendMsg = oldMsg
} else {
if msg == nil {
msg, err = m.Bytes()
if err != nil {
c.mutex.Unlock()
return err
}
}
sendMsg = msg
}
conn.Write(key, sendMsg)
}
c.mutex.Unlock()
return nil
}
开发者ID:rogerwei,项目名称:gopush-cluster,代码行数:52,代码来源:seq_channel.go
示例3: PushMsg
// PushMsg implements the Channel PushMsg method.
func (c *SeqChannel) PushMsg(key string, m *myrpc.Message, expire uint) (err error) {
client := myrpc.MessageRPC.Get()
if client == nil {
return ErrMessageRPC
}
c.mutex.Lock()
// private message need persistence
// if message expired no need persistence, only send online message
// rewrite message id
//m.MsgId = c.timeID.ID()
m.MsgId = id.Get()
if m.GroupId != myrpc.PublicGroupId && expire > 0 {
args := &myrpc.MessageSavePrivateArgs{Key: key, Msg: m.Msg, MsgId: m.MsgId, Expire: expire}
ret := 0
if err = client.Call(myrpc.MessageServiceSavePrivate, args, &ret); err != nil {
c.mutex.Unlock()
log.Error("%s(\"%s\", \"%v\", &ret) error(%v)", myrpc.MessageServiceSavePrivate, key, args, err)
return
}
}
// push message
if err = c.writeMsg(key, m); err != nil {
c.mutex.Unlock()
log.Error("c.WriteMsg(\"%s\", m) error(%v)", key, err)
return
}
c.mutex.Unlock()
return
}
开发者ID:kirk91,项目名称:gopush-cluster,代码行数:30,代码来源:seq_channel.go
注:本文中的github.com/Terry-Mao/gopush-cluster/rpc.Message类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论