From ece1dac81a4880cfa056573fc7c8def49fbd413a Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Wed, 20 Apr 2022 18:53:23 +0800 Subject: [PATCH] add save message to mysql switch --- internal/msg_transfer/logic/init.go | 8 ++++++-- .../msg_transfer/logic/persistent_msg_handler.go | 12 ++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/msg_transfer/logic/init.go b/internal/msg_transfer/logic/init.go index 20326bbfc..a67b9cff4 100644 --- a/internal/msg_transfer/logic/init.go +++ b/internal/msg_transfer/logic/init.go @@ -2,8 +2,8 @@ package logic import ( "Open_IM/pkg/common/config" - "Open_IM/pkg/common/kafka" + "fmt" ) var ( @@ -20,6 +20,10 @@ func Init() { } func Run() { //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) } diff --git a/internal/msg_transfer/logic/persistent_msg_handler.go b/internal/msg_transfer/logic/persistent_msg_handler.go index 0a815ca1a..5400d54d6 100644 --- a/internal/msg_transfer/logic/persistent_msg_handler.go +++ b/internal/msg_transfer/logic/persistent_msg_handler.go @@ -56,14 +56,10 @@ func (pc *PersistentConsumerHandler) handleChatWs2Mysql(msg []byte, msgKey strin } } if tag { - if config.Config.ChatPersistenceMysql == true { - log.NewInfo(msgFromMQ.OperationID, "msg_transfer msg persisting", string(msg)) - if err = im_mysql_msg_model.InsertMessageToChatLog(msgFromMQ); err != nil { - log.NewError(msgFromMQ.OperationID, "Message insert failed", "err", err.Error(), "msg", msgFromMQ.String()) - return - } - } else { - log.Debug(msgFromMQ.OperationID, "don't insert to db", string(msg)) + log.NewInfo(msgFromMQ.OperationID, "msg_transfer msg persisting", string(msg)) + if err = im_mysql_msg_model.InsertMessageToChatLog(msgFromMQ); err != nil { + log.NewError(msgFromMQ.OperationID, "Message insert failed", "err", err.Error(), "msg", msgFromMQ.String()) + return } }