修改:zgroup 订阅组 共同消费组消息

git-svn-id: svn://47.119.165.148/zhub@92 e63fbceb-bcc3-4977-ac22-735b83d8d0f4
This commit is contained in:
lxy
2021-01-28 12:11:35 +00:00
parent c62e031076
commit 7746b768bd
3 changed files with 48 additions and 15 deletions

View File

@@ -1,28 +1,33 @@
package zsub
import "sync"
import (
"sync"
"sync/atomic"
)
type ZGroup struct { // ZGroup
sync.Mutex
conns []*ZConn
offset int
offset int32
chMsg chan string // 组消息即时投递
ztopic *ZTopic // 所属topic
}
func (g *ZGroup) init() {
go func() {
func (g *ZGroup) appendTo(c *ZConn) {
c.appendTo(g.conns)
go func() { // 每个连接开启一个携程发送数据
for {
msg, ok := <-g.chMsg
if !ok {
break
}
if len(g.conns) == 0 {
continue
err := c.send("message", g.ztopic.topic, msg)
if err != nil { // 失败处理
g.chMsg <- msg
break
}
g.conns[0].send("message", g.ztopic.topic, msg)
g.offset++
atomic.AddInt32(&g.offset, 1)
}
}()
}