新增:1、topic 记录到DB 2、http 发布事件支持 3、修复延时事件并发异常崩溃

git-svn-id: svn://47.119.165.148/zhub@127 e63fbceb-bcc3-4977-ac22-735b83d8d0f4
This commit is contained in:
lxy
2021-09-02 17:10:21 +00:00
parent 15a73136cc
commit b5e55c9869
5 changed files with 148 additions and 43 deletions

View File

@@ -28,7 +28,7 @@ var (
func init() {
// conn health check: T=10s, close>29s
go func() {
ticker := time.NewTicker(time.Second * 10)
ticker := time.NewTicker(time.Second * 20)
defer ticker.Stop()
for range ticker.C {
@@ -60,17 +60,20 @@ func init() {
}
}
zsub.dataStorage()
}
}()
}
type ZSub struct {
sync.RWMutex
topics map[string]*ZTopic
timers map[string]*ZTimer
delays map[string]*ZDelay
locks map[string][]*Lock
conns []*ZConn
topics map[string]*ZTopic
timers map[string]*ZTimer
delays map[string]*ZDelay
locks map[string][]*Lock
conns []*ZConn
delayup bool
}
type ZConn struct { //ZConn
@@ -242,8 +245,9 @@ func (c *ZConn) removeTo(arr []*ZConn) []*ZConn {
// ServerStart ================== ZHub server =====================================
/*
1、初始化服务
2、启动服务监听
ServerStart
1、load history data
2、init server
*/
func ServerStart(addr string) {
conf.GetStr("data.dir", "data")
@@ -354,11 +358,11 @@ func (s *ZSub) acceptHandler(c *ZConn) {
}
/*
accept stop message
1、send message to stop's chan
2、feedback send success to sender, and sending message to stop's subscripts
Publish topic message
1、send message to topic's chan
2、feedback send success to sender, and sending message to topic's subscripts
*/
func (s *ZSub) publish(topic, msg string) {
func (s *ZSub) Publish(topic, msg string) {
s.RLock()
defer s.RUnlock()
ztopic := s.topics[topic] //ZTopic