淇敼锛歵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:
10
zsub/zsub.go
10
zsub/zsub.go
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user