add save message to mysql switch

This commit is contained in:
Gordon 2022-04-20 18:53:23 +08:00 committed by Xinwei Xiong(cubxxw-openim)
parent a525db7088
commit ece1dac81a
2 changed files with 10 additions and 10 deletions

View File

@ -2,8 +2,8 @@ package logic
import ( import (
"Open_IM/pkg/common/config" "Open_IM/pkg/common/config"
"Open_IM/pkg/common/kafka" "Open_IM/pkg/common/kafka"
"fmt"
) )
var ( var (
@ -20,6 +20,10 @@ func Init() {
} }
func Run() { func Run() {
//register mysqlConsumerHandler to //register mysqlConsumerHandler to
go persistentCH.persistentConsumerGroup.RegisterHandleAndConsumer(&persistentCH) if config.Config.ChatPersistenceMysql {
go persistentCH.persistentConsumerGroup.RegisterHandleAndConsumer(&persistentCH)
} else {
fmt.Println("not start mysql consumer")
}
go historyCH.historyConsumerGroup.RegisterHandleAndConsumer(&historyCH) go historyCH.historyConsumerGroup.RegisterHandleAndConsumer(&historyCH)
} }

View File

@ -56,14 +56,10 @@ func (pc *PersistentConsumerHandler) handleChatWs2Mysql(msg []byte, msgKey strin
} }
} }
if tag { if tag {
if config.Config.ChatPersistenceMysql == true { log.NewInfo(msgFromMQ.OperationID, "msg_transfer msg persisting", string(msg))
log.NewInfo(msgFromMQ.OperationID, "msg_transfer msg persisting", string(msg)) if err = im_mysql_msg_model.InsertMessageToChatLog(msgFromMQ); err != nil {
if err = im_mysql_msg_model.InsertMessageToChatLog(msgFromMQ); err != nil { log.NewError(msgFromMQ.OperationID, "Message insert failed", "err", err.Error(), "msg", msgFromMQ.String())
log.NewError(msgFromMQ.OperationID, "Message insert failed", "err", err.Error(), "msg", msgFromMQ.String()) return
return
}
} else {
log.Debug(msgFromMQ.OperationID, "don't insert to db", string(msg))
} }
} }