淇敼锛歵opic & message chan overload check

git-svn-id: svn://47.119.165.148/zhub@129 e63fbceb-bcc3-4977-ac22-735b83d8d0f4
This commit is contained in:
lxy
2021-09-25 17:38:31 +00:00
parent b5e55c9869
commit df84efffce
2 changed files with 20 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ package zsub
import ( import (
"bufio" "bufio"
"fmt"
"log" "log"
"net" "net"
"os" "os"
@@ -369,8 +370,15 @@ func (s *ZSub) Publish(topic, msg string) {
if ztopic == nil { if ztopic == nil {
return return
} }
ztopic.chMsg <- msg
ztopic.mcount++ ztopic.mcount++
// topic chan overload check
if len(ztopic.chMsg) == cap(ztopic.chMsg) {
log.Println(fmt.Sprintf("ztopic no cap: [%s %s]", topic, msg))
return
}
ztopic.chMsg <- msg
} }
/* /*

View File

@@ -1,6 +1,10 @@
package zsub package zsub
import "sync" import (
"fmt"
"log"
"sync"
)
type ZTopic struct { //ZTopic type ZTopic struct { //ZTopic
sync.Mutex sync.Mutex
@@ -19,7 +23,12 @@ func (t *ZTopic) init() {
break break
} }
for _, group := range t.groups { for name, 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]", name, t.topic, msg))
continue
}
group.chMsg <- msg group.chMsg <- msg
} }
} }