push msg specify receiver

This commit is contained in:
Gordon
2022-02-08 17:12:02 +08:00
parent ba5d178ba0
commit dc1ad8fb2d
5 changed files with 115 additions and 103 deletions
+1 -7
View File
@@ -71,7 +71,7 @@ func (r *RPCServer) OnlinePushMsg(_ context.Context, in *pbRelay.OnlinePushMsgRe
log.NewError(in.OperationID, "data encode err", err.Error())
}
var tag bool
recvID := in.MsgData.RecvID
recvID := in.PushToUserID
platformList := genPlatformArray()
for _, v := range platformList {
if conn := ws.getUserConn(recvID, v); conn != nil {
@@ -92,12 +92,6 @@ func (r *RPCServer) OnlinePushMsg(_ context.Context, in *pbRelay.OnlinePushMsgRe
resp = append(resp, temp)
}
}
//Single chat sender synchronization message
if in.MsgData.GetSessionType() == constant.SingleChatType {
for k, v := range ws.getSingleUserAllConn(in.MsgData.SendID) {
_ = sendMsgToUser(v, replyBytes.Bytes(), in, k, in.MsgData.SendID)
}
}
if !tag {
log.NewError(in.OperationID, "push err ,no matched ws conn not in map", in.String())
}
@@ -45,6 +45,7 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string)
isHistory := utils.GetSwitchFromOptions(msgFromMQ.MsgData.Options, constant.IsHistory)
//Control whether to store history messages (mysql)
isPersist := utils.GetSwitchFromOptions(msgFromMQ.MsgData.Options, constant.IsPersistent)
isSenderSync := utils.GetSwitchFromOptions(msgFromMQ.MsgData.Options, constant.IsSenderSync)
switch msgFromMQ.MsgData.SessionType {
case constant.SingleChatType:
log.NewDebug(msgFromMQ.OperationID, "msg_transfer msg type = SingleChatType", isHistory, isPersist)
@@ -55,6 +56,8 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string)
log.NewError(operationID, "single data insert to mongo err", err.Error(), msgFromMQ.String())
return
}
go sendMessageToPush(&msgFromMQ, msgFromMQ.MsgData.RecvID)
log.NewDebug(msgFromMQ.OperationID, "sendMessageToPush cost time ", utils.GetCurrentTimestampByNano()-time)
} else if msgKey == msgFromMQ.MsgData.SendID {
err := saveUserChat(msgFromMQ.MsgData.SendID, &msgFromMQ)
@@ -62,15 +65,12 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string)
log.NewError(operationID, "single data insert to mongo err", err.Error(), msgFromMQ.String())
return
}
if isSenderSync {
go sendMessageToPush(&msgFromMQ, msgFromMQ.MsgData.SendID)
}
}
log.NewDebug(operationID, "saveUserChat cost time ", utils.GetCurrentTimestampByNano()-time)
}
if msgKey == msgFromMQ.MsgData.RecvID {
go sendMessageToPush(&msgFromMQ)
log.NewDebug(msgFromMQ.OperationID, "sendMessageToPush cost time ", utils.GetCurrentTimestampByNano()-time)
}
case constant.GroupChatType:
log.NewDebug(msgFromMQ.OperationID, "msg_transfer msg type = GroupChatType", isHistory, isPersist)
if isHistory {
@@ -80,7 +80,7 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string)
return
}
}
go sendMessageToPush(&msgFromMQ)
go sendMessageToPush(&msgFromMQ, msgFromMQ.MsgData.RecvID)
default:
log.NewError(msgFromMQ.OperationID, "SessionType error", msgFromMQ.String())
return
@@ -99,10 +99,10 @@ func (mc *HistoryConsumerHandler) ConsumeClaim(sess sarama.ConsumerGroupSession,
}
return nil
}
func sendMessageToPush(message *pbMsg.MsgDataToMQ) {
func sendMessageToPush(message *pbMsg.MsgDataToMQ, pushToUserID string) {
log.InfoByKv("msg_transfer send message to push", message.OperationID, "message", message.String())
rpcPushMsg := pbPush.PushMsgReq{OperationID: message.OperationID, MsgData: message.MsgData}
mqPushMsg := pbMsg.PushMsgDataToMQ{OperationID: message.OperationID, MsgData: message.MsgData}
rpcPushMsg := pbPush.PushMsgReq{OperationID: message.OperationID, MsgData: message.MsgData, PushToUserID: pushToUserID}
mqPushMsg := pbMsg.PushMsgDataToMQ{OperationID: message.OperationID, MsgData: message.MsgData, PushToUserID: pushToUserID}
grpcConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImPushName)
if grpcConn == nil {
log.ErrorByKv("rpc dial failed", rpcPushMsg.OperationID, "push data", rpcPushMsg.String())
+2 -2
View File
@@ -41,7 +41,7 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) {
log.InfoByKv("test", pushMsg.OperationID, "len grpc", len(grpcCons), "data", pushMsg.String())
for _, v := range grpcCons {
msgClient := pbRelay.NewOnlineMessageRelayServiceClient(v)
reply, err := msgClient.OnlinePushMsg(context.Background(), &pbRelay.OnlinePushMsgReq{OperationID: pushMsg.OperationID, MsgData: pushMsg.MsgData})
reply, err := msgClient.OnlinePushMsg(context.Background(), &pbRelay.OnlinePushMsgReq{OperationID: pushMsg.OperationID, MsgData: pushMsg.MsgData, PushToUserID: pushMsg.PushToUserID})
if err != nil {
log.InfoByKv("push data to client rpc err", pushMsg.OperationID, "err", err)
continue
@@ -51,7 +51,7 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) {
}
}
log.InfoByKv("push_result", pushMsg.OperationID, "result", wsResult, "sendData", pushMsg.MsgData)
if isOfflinePush {
if isOfflinePush && pushMsg.PushToUserID != pushMsg.MsgData.SendID {
for _, v := range wsResult {
if v.ResultCode == 0 {
continue