pull/232/head
skiffer-git 3 years ago
parent 3bf04802e4
commit 06aae24dad

@ -205,19 +205,23 @@ func (och *OnlineHistoryConsumerHandler) Run(channelID int) {
func (och *OnlineHistoryConsumerHandler) MessagesDistributionHandle() { func (och *OnlineHistoryConsumerHandler) MessagesDistributionHandle() {
for { for {
operationID := utils.OperationIDGenerator()
select { select {
case cmd := <-och.msgDistributionCh: case cmd := <-och.msgDistributionCh:
switch cmd.Cmd { switch cmd.Cmd {
case ConsumerMsgs: case ConsumerMsgs:
consumerMessages := cmd.Value.([]*sarama.ConsumerMessage) consumerMessages := cmd.Value.([]*sarama.ConsumerMessage)
//Aggregation map[userid]message list //Aggregation map[userid]message list
for i := 0; i < len(consumerMessages); i++ { for i := 0; i < len(consumerMessages); i++ {
msgFromMQ := pbMsg.MsgDataToMQ{} msgFromMQ := pbMsg.MsgDataToMQ{}
err := proto.Unmarshal(consumerMessages[i].Value, &msgFromMQ) err := proto.Unmarshal(consumerMessages[i].Value, &msgFromMQ)
if err != nil { if err != nil {
log.Error("msg_transfer Unmarshal msg err", "", "msg", string(consumerMessages[i].Value), "err", err.Error()) log.Error(operationID, "msg_transfer Unmarshal msg err", "", "msg", string(consumerMessages[i].Value), "err", err.Error())
return return
} }
log.Debug(operationID, "MessagesDistributionHandle ", msgFromMQ.String())
if oldM, ok := och.UserAggregationMsgs[string(consumerMessages[i].Key)]; ok { if oldM, ok := och.UserAggregationMsgs[string(consumerMessages[i].Key)]; ok {
oldM = append(oldM, &msgFromMQ) oldM = append(oldM, &msgFromMQ)
och.UserAggregationMsgs[string(consumerMessages[i].Key)] = oldM och.UserAggregationMsgs[string(consumerMessages[i].Key)] = oldM
@ -230,6 +234,7 @@ func (och *OnlineHistoryConsumerHandler) MessagesDistributionHandle() {
for userID, v := range och.UserAggregationMsgs { for userID, v := range och.UserAggregationMsgs {
if len(v) >= 0 { if len(v) >= 0 {
channelID := getHashCode(userID) % ChannelNum channelID := getHashCode(userID) % ChannelNum
log.Debug(operationID, "UserAggregationMsgs ", len(v), channelID, userID)
go func(cID uint32, userID string, messages []*pbMsg.MsgDataToMQ) { go func(cID uint32, userID string, messages []*pbMsg.MsgDataToMQ) {
och.chArrays[cID] <- Cmd2Value{Cmd: UserMessages, Value: MsgChannelValue{userID: userID, msgList: messages}} och.chArrays[cID] <- Cmd2Value{Cmd: UserMessages, Value: MsgChannelValue{userID: userID, msgList: messages}}
}(channelID, userID, v) }(channelID, userID, v)

Loading…
Cancel
Save