修改:代码包结构
This commit is contained in:
36
internal/zsub/ztopic.go
Normal file
36
internal/zsub/ztopic.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package zsub
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type ZTopic struct { //ZTopic
|
||||
sync.Mutex
|
||||
groups map[string]*ZGroup
|
||||
mcount int32
|
||||
topic string // 主题名称
|
||||
chMsg chan string // 主题消息投递
|
||||
}
|
||||
|
||||
// 主题消息发送
|
||||
func (t *ZTopic) init() {
|
||||
go func() {
|
||||
for {
|
||||
msg, ok := <-t.chMsg
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
|
||||
for groupName, group := range t.groups {
|
||||
// zgroup chan overload check
|
||||
if len(group.chMsg) == cap(group.chMsg) {
|
||||
log.Println(fmt.Sprintf("zgroup no cap: [%s.%s %s]", groupName, t.topic, msg))
|
||||
continue
|
||||
}
|
||||
group.chMsg <- msg
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
Reference in New Issue
Block a user