Skip to content

【bug】consumer order problem #48

Description

@goldencolor
  1. I inserted 1, 2, 3, 4, 5, 6 messages
  2. The maximum number of jobs for consumers is 1
  3. Out-of-order consumption results 2, 3, 1, 4, 5, 6
async brachMsg(conversationId: string, messages: any | Array<Message>, min: number = 0, max: number = 0, sendTopic: boolean = false,msgType?: 'task') {
    const msgCount = messages.length;
    let sendCount = 0;
    const isRoom = conversationId.indexOf('R:') >= -1 ? 1 : 0;
    let noticeMessage = null;
    let noticeIndex = 0;
    // IS ROOM
    if (isRoom === 1) {
      let isText = 0;
      const msgNotice = messages.filter((msg: Message, index: number) => {
        if (isText >= 1) {
          return;
        }
        if (msg.type == 'text' && msg.content && msg?.isNotice == 1) {
          noticeMessage = msg;
          noticeIndex = index;
          isText++;
        }
      });
      if (noticeMessage) {
        await this.messageQueue.createJob({
          type: QueueEunm.SEND_MESSAGE, 'priority': msgType =='task' ? Priority.LOW : Priority.CRITICAL, data: {
            conversationId,
            message: noticeMessage,
            min,
            max,
            sendTopic,
            msgCount
          }
        });
      }
    }

    for (let index = 0; index < messages.length; index++) {
      const message: Message = messages[index];
      if (index !== noticeIndex && !noticeMessage) {
        await this.messageQueue.createJob({
            type: QueueEunm.SEND_MESSAGE, 'priority': msgType =='task' ? Priority.LOW : Priority.CRITICAL, data: {
              conversationId,
              message,
              min,
              max,
              sendTopic,
              msgCount
            }
          });
          sendCount++;
      }
    }

    return sendCount;
  }

How to solve the sorting of a large number of concurrent insert jobs?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions