From 082de2b6b7339e4b3ed2c5265ac952050faf90bd Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Mon, 1 Nov 2021 17:16:47 +0800 Subject: [PATCH] group message fix bug --- src/msg_transfer/logic/history_msg_handler.go | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/msg_transfer/logic/history_msg_handler.go b/src/msg_transfer/logic/history_msg_handler.go index cda111998..e6b7befdd 100644 --- a/src/msg_transfer/logic/history_msg_handler.go +++ b/src/msg_transfer/logic/history_msg_handler.go @@ -33,7 +33,7 @@ func (mc *HistoryConsumerHandler) Init() { func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string) { log.InfoByKv("chat come mongo!!!", "", "chat", string(msg)) - time := utils.GetCurrentTimestampBySecond() + time := utils.GetCurrentTimestampByNano() pbData := pbMsg.WSToMsgSvrChatMsg{} err := proto.Unmarshal(msg, &pbData) if err != nil { @@ -59,47 +59,53 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string) isHistory := utils.GetSwitchFromOptions(Options, "history") //Control whether to store history messages (mysql) isPersist := utils.GetSwitchFromOptions(Options, "persistent") - if pbData.SessionType == constant.SingleChatType { - log.Info("", "", "msg_transfer chat type = SingleChatType", isHistory, isPersist) + switch pbData.SessionType { + case constant.SingleChatType: + log.NewDebug(pbSaveData.OperationID, "msg_transfer chat type = SingleChatType", isHistory, isPersist) if isHistory { if msgKey == pbSaveData.RecvID { err := saveUserChat(pbData.RecvID, &pbSaveData) if err != nil { - log.ErrorByKv("data insert to mongo err", pbSaveData.OperationID, "data", pbSaveData.String(), "err", err.Error()) + log.NewError(pbSaveData.OperationID, "single data insert to mongo err", err.Error(), pbSaveData.String()) + return } } else if msgKey == pbSaveData.SendID { err := saveUserChat(pbData.SendID, &pbSaveData) if err != nil { - log.ErrorByKv("data insert to mongo err", pbSaveData.OperationID, "data", pbSaveData.String(), "err", err.Error()) + log.NewError(pbSaveData.OperationID, "single data insert to mongo err", err.Error(), pbSaveData.String()) + return } } - log.NewInfo(pbSaveData.OperationID, "saveUserChat cost time ", utils.GetCurrentTimestampBySecond()-time) + log.NewDebug(pbSaveData.OperationID, "saveUserChat cost time ", utils.GetCurrentTimestampByNano()-time) } if msgKey == pbSaveData.RecvID { pbSaveData.Options = pbData.Options pbSaveData.OfflineInfo = pbData.OfflineInfo go sendMessageToPush(&pbSaveData) - log.NewInfo(pbSaveData.OperationID, "sendMessageToPush cost time ", utils.GetCurrentTimestampBySecond()-time) + log.NewDebug(pbSaveData.OperationID, "sendMessageToPush cost time ", utils.GetCurrentTimestampByNano()-time) } - log.InfoByKv("msg_transfer handle topic success...", "", "") - } else if pbData.SessionType == constant.GroupChatType { - log.Info("", "", "msg_transfer chat type = GroupChatType") + case constant.GroupChatType: + log.NewDebug(pbSaveData.OperationID, "msg_transfer chat type = GroupChatType", isHistory, isPersist) if isHistory { uidAndGroupID := strings.Split(pbData.RecvID, " ") - saveUserChat(uidAndGroupID[0], &pbSaveData) + err := saveUserChat(uidAndGroupID[0], &pbSaveData) + if err != nil { + log.NewError(pbSaveData.OperationID, "group data insert to mongo err", pbSaveData.String(), uidAndGroupID[0], err.Error()) + return + } } pbSaveData.Options = pbData.Options pbSaveData.OfflineInfo = pbData.OfflineInfo - sendMessageToPush(&pbSaveData) - log.InfoByKv("msg_transfer handle topic success...", "", "") - } else { - log.Error("", "", "msg_transfer recv chat err, chat.MsgFrom = %d", pbData.SessionType) + go sendMessageToPush(&pbSaveData) + default: + log.NewError(pbSaveData.OperationID, "SessionType error", pbSaveData.String()) + return } - + log.NewDebug(pbSaveData.OperationID, "msg_transfer handle topic data to database success...", pbSaveData.String()) } func (HistoryConsumerHandler) Setup(_ sarama.ConsumerGroupSession) error { return nil }