A message scheduling method, system and related components

Through logical sequence numbering and serial number management of messages in the message queue, the order disorder problem in the message queue caused by network delay and different execution speeds is solved, ensuring that messages are processed in order, and achieving the smooth completion and processing efficiency of message groups. improvement.

CN114443327BActive Publication Date: 2024-10-22INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202210109146.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-01-28
Publication Date
2024-10-22
Estimated Expiration
2042-01-28

AI Technical Summary

Technical Problem

In the message queue, due to network delays or different logic execution speeds of code blocks, messages cannot be processed in a logical sequence, resulting in disordered and stuck message group processes, making it difficult to ensure the smooth completion of all messages.

Method used

By logically numbering the same group of messages, comparing the sequence number and the executable sequence number, only executing the message corresponding to the executable sequence number, ensuring that the messages are executed in the predetermined order, avoiding message order disorder, and setting an alarm threshold when execution fails to handle the failure. Condition.

Benefits of technology

It effectively avoids the disorder of the message producer and consumer, ensures that the message group can be successfully completed, and improves the reliability and efficiency of message processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114443327B_ABST
    Figure CN114443327B_ABST
Patent Text Reader

Abstract

The present application discloses a message scheduling method, system and related components, the method comprising: continuously receiving messages from message producers; performing the following operations on the same group of messages: numbering all messages in increasing order according to a logical sequence to determine the sequence number of each message, and initializing the executable sequence number to the sequence number of the first message; repeating the following operations until all messages are executed: judging whether there is a target message, the target message is specifically a message with the same sequence number as the current executable sequence number; if so, executing the target message and adding one to the current executable sequence number. The present application numbers the same group of messages according to a logical sequence, compares the sequence number and the executable sequence number, and only executes the message corresponding to the executable sequence number, thereby avoiding the problem of disordered message order on the message producer side, and at the same time clarifies the order of message execution, avoiding disordered order on the consumer side, and ensuring that the group of messages can be completed smoothly.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of message queue processing, and in particular to a message scheduling method, system and related components. Background Art

[0002] When currently processing messages, in some application scenarios, due to network delays or different logic execution speeds of code blocks, the messages in the message queue cannot be processed in the logical order of the messages. At the same time, there are multiple consumers in the consumer group executing messages, and each consumer has the opportunity to execute the message, which also makes it impossible for the messages to be executed in the normal logical order. Once the messages are not processed in order, the message group will experience process disorder and jamming, making it difficult to ensure the smooth completion of all messages.

[0003] Therefore, how to provide a solution to the above technical problems is a problem that those skilled in the art need to solve. Summary of the invention

[0004] In view of this, the purpose of the present invention is to provide a message scheduling method, system and related components to eliminate the interference caused by disordered order when producing and consuming messages and ensure the smooth execution of messages. The specific scheme is as follows:

[0005] A message scheduling method, comprising:

[0006] Continue to receive messages from message producers;

[0007] Perform the following actions on the same set of said messages:

[0008] Numbering all the messages in increasing order according to a logical sequence to determine a sequence number of each message, and initializing an executable sequence number to be the sequence number of the first message;

[0009] Repeat the following steps until all the messages are completed:

[0010] Determine whether there is a target message among all the messages, wherein the target message is specifically the message with the same sequence number as the current executable sequence number;

[0011] If so, the target message is executed and the current executable sequence number is increased by one.

[0012] Preferably, the process of determining whether the target message exists in all the messages includes:

[0013] It is determined periodically whether a target message exists in all the messages according to a preset period.

[0014] Preferably, the process of executing the target message and increasing the current executable sequence number by one includes:

[0015] executing the target message;

[0016] When the target message is executed successfully, the current executable sequence number is increased by one;

[0017] When the target message fails to be executed, the target message is executed again;

[0018] When the number of execution failures of the target message reaches an alarm threshold, an alarm message is issued.

[0019] Preferably, the process of performing the following operations on the same group of messages further includes:

[0020] The messages in the same group are marked with a group number.

[0021] Preferably, the process of continuously receiving messages from the message producer includes:

[0022] Continuously receive messages from message producers and cache the messages in a database.

[0023] Preferably, the process of determining whether the target message exists in all the messages includes:

[0024] Retrieving a window message from the database, the window message being the message with the smallest sequence number among all the messages;

[0025] Determine whether the sequence number of the window message is equal to the current executable sequence number;

[0026] If so, determining the window message as a target message;

[0027] If not, the window message is cached in the database.

[0028] Accordingly, the present application also discloses a message scheduling system, including:

[0029] Processing message interface, used to continuously receive messages from message producers;

[0030] The processing module is used to perform the following operations on the same group of messages:

[0031] A numbering unit, used to number all the messages in increasing order according to a logical sequence to determine a sequence number of each message, and to initialize an executable sequence number to be the sequence number of the first message;

[0032] The judgment unit is used to repeatedly perform the following operations until all the messages are executed: judging whether there is a target message among all the messages, wherein the target message is specifically the message whose sequence number is the same as the current executable sequence number; if so, triggering the action unit and adding one to the current executable sequence number;

[0033] The action unit is used to execute the target message.

[0034] Correspondingly, the present application also discloses a message scheduling device, comprising:

[0035] Memory for storing computer programs;

[0036] A processor is used to implement the steps of the message scheduling method as described in any one of the above items when executing the computer program.

[0037] Correspondingly, the present application also discloses a readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the message scheduling method described in any one of the above items are implemented.

[0038] The present application discloses a message scheduling method, including: continuously receiving messages from message producers; performing the following operations on the same group of messages: numbering all the messages in increasing order according to a logical sequence to determine the sequence number of each message, and initializing the executable sequence number to the sequence number of the first message; repeating the following operations until all the messages are executed: judging whether there is a target message among all the messages, the target message being specifically the message with the same sequence number as the current executable sequence number; if so, executing the target message and adding one to the current executable sequence number. The message scheduling method in the present application numbers the same group of messages according to a logical sequence, compares the sequence number and the executable sequence number, and only executes the message corresponding to the executable sequence number, thereby avoiding the problem of disordered message order on the message producer side, and at the same time clarifies the order of message execution, avoiding disordered order on the consumer side, and ensuring that the group of messages can be completed smoothly. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0040] Figure 1 A flowchart of a message scheduling method according to an embodiment of the present invention;

[0041] Figure 2 A sub-step flow chart of a message scheduling method in an embodiment of the present invention;

[0042] Figure 3 The structure distribution diagram of a message scheduling system in an embodiment of the present invention. DETAILED DESCRIPTION

[0043] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0044] When currently processing messages, in some application scenarios, due to network delays or different logic execution speeds of code blocks, the messages in the message queue cannot be processed in the logical order of the messages. At the same time, there are multiple consumers in the consumer group executing messages, and each consumer has the opportunity to execute the message, which also makes it impossible for the messages to be executed in the normal logical order. Once the messages are not processed in order, the message group will experience process disorder and jamming, making it difficult to ensure the smooth completion of all messages.

[0045] The message scheduling method in the present application numbers the same group of messages in logical order, compares the sequence number and the executable number, and only executes the messages corresponding to the executable number, thereby avoiding the problem of message disorder on the message producer side. At the same time, it clarifies the order of message execution, avoids the order disorder on the consumer side, and ensures that the group of messages can be completed smoothly.

[0046] The embodiment of the present invention discloses a message scheduling method, see Figure 1 As shown, including:

[0047] S1: Continuously receive messages from message producers;

[0048] S2: Perform the following operations on the same group of messages:

[0049] S21: numbering all messages in increasing order according to the logical sequence to determine the sequence number of each message, and initializing the executable sequence number to be the sequence number of the first message;

[0050] Repeat the following steps until all messages are executed:

[0051] S22: Determine whether there is a target message among all messages, where the target message is specifically a message with the same sequence number as the current executable sequence number;

[0052] S23: If yes, execute the target message and increase the current executable sequence number by one;

[0053] After step S23, it is determined whether all messages have been executed. If so, step S2 is ended. If not, it returns to step S22 and repeats steps S22-S23.

[0054] It is understandable that step S2 may also include marking the same group of messages with group numbers to avoid mutual interference or confusion between messages in different groups.

[0055] Furthermore, step S1 and step S22 are both ongoing actions, which can be executed regularly at a specific cycle, and their respective corresponding cycles can be set accordingly according to the message sending speed, message generation speed, and message execution speed requirements. That is, step S22 is a process for determining whether there is a target message among all messages, including: regularly determining whether there is a target message among all messages according to a preset cycle.

[0056] It can be understood that step S1 continues to receive messages, and steps S21-S23 logically number the messages in the same group, determine the target message using the executable number, and execute the process of the target message, wherein the target message is the executable message. If there is no executable message in the currently received messages in the same group, no message will be executed. After execution, the executable number is increased by one to point to the next executable message. This process ensures that the messages in the same group must be executed in a logical order. Therefore, the disordered message order in the prior art will no longer occur in this embodiment.

[0057] Specifically, the action of executing the target message in step S23 is actually realized by triggering an application program, which is also the consumer. The process of triggering the application program is specifically completed by calling the execution logic interface to send a message to the application program.

[0058] Furthermore, considering the situation that the message execution may fail, a message for restarting the failed execution can be set. However, in order to avoid the restart loop, an alarm threshold can be set. Once the number of message execution failures reaches the alarm threshold, the restart loop is exited and an alarm message is issued. The alarm message is used to remind the user that the message execution failed. According to the importance of the message, if the message is a key node in the logical sequence, the group of messages is terminated or suspended. If the message is a minor node that can be ignored in the logical sequence, the message can be marked and filtered from the logical sequence, skipping the message and directly executing the next message in the logical sequence.

[0059] For details, see Figure 2 As shown, step S23 executes the target message and increases the current executable sequence number by one, including:

[0060] Execute the target message;

[0061] When the target message is executed successfully, the current executable sequence number is increased by one;

[0062] When the target message fails to execute, execute the target message again;

[0063] When the number of target message execution failures reaches the alarm threshold, an alarm message is issued.

[0064] It can be understood that when the target message fails to be executed, the process of executing the target message again specifically includes: when the target message fails to be executed, if the number of execution failures reaches the alarm threshold, an alarm message is issued; if the alarm threshold is not reached, the step of executing the target message is returned again.

[0065] The present application discloses a message scheduling method, including: continuously receiving messages from message producers; performing the following operations on the same group of messages: numbering all the messages in increasing order according to a logical sequence to determine the sequence number of each message, and initializing the executable sequence number to the sequence number of the first message; repeating the following operations until all the messages are executed: judging whether there is a target message among all the messages, the target message being specifically the message with the same sequence number as the current executable sequence number; if so, executing the target message and adding one to the current executable sequence number. The message scheduling method in the present application numbers the same group of messages according to a logical sequence, compares the sequence number and the executable sequence number, and only executes the message corresponding to the executable sequence number, thereby avoiding the problem of disordered message order on the message producer side, and at the same time clarifies the order of message execution, avoiding disordered order on the consumer side, and ensuring that the group of messages can be completed smoothly.

[0066] The embodiment of the present invention discloses a specific message scheduling method. Compared with the previous embodiment, this embodiment further illustrates and optimizes the technical solution.

[0067] Specifically, the process of continuously receiving the message from the message producer in step S1 includes:

[0068] Continuously receive messages from message producers and cache them in the database.

[0069] Specifically, the database may be redis or other databases.

[0070] Furthermore, the process of determining whether the target message exists in all messages in step S22 includes:

[0071] Retrieve the window message from the database. The window message is the message with the smallest sequence number among all messages.

[0072] Determine whether the sequence number of the window message is equal to the current executable sequence number;

[0073] If so, the window message is determined as the target message;

[0074] If not, cache the window message in the database.

[0075] It can be understood that the window message is the message with the highest execution priority among all pending messages. The process of retrieving the window message from the database to match the current executable sequence number can determine the target message as quickly as possible. If the window message is not the target message, other pending messages in the same group cannot become the target message. If the window message is the target message, it can be executed immediately, and the target message will no longer be cached in the database, or the target message will be marked as executed or being processed according to the execution status, and will be excluded from the next determination of the target message from all pending messages.

[0076] It can be understood that since the messages are cached in the database, specifically in the key = cache_queue in redis, all operations on the messages in step S2 need to take into account the characteristics of the database, for example, the messages in the same group are marked with a group number of bid, and each message is marked with a sequence number of seq. The key = {bid}_max_seq in the database is assigned a value of max_seq, corresponding to the current executable sequence number in the group of messages with the group number {bid}. If the sequence numbers seq of the messages cached in the database are all greater than the current executable sequence number max_seq, there is currently no executable message. If there is a message with a sequence number seq equal to the current executable sequence number max_seq, the message is determined to be the target message, and the execution interface is called to trigger the relevant application to execute the target message.

[0077] Furthermore, if the target message is executed successfully, the current executable sequence number is updated by adding 1 to max_seq and then updated to the database key={bid}_max_seq.

[0078] Furthermore, if the execution of the target message fails, the execution failure count value fail_num of the target message is stored in the hash storage of key = handle-fail in the database. If fail_num reaches the alarm threshold, the alarm interface is called to issue an alarm message. It can be understood that the execution of the same group of messages can use the same key = handle-fail to store the number of related message executions. If the current target message is executed successfully, the execution failure count value of key = handle-fail is cleared or key = handle-fail is deleted. After deleting key = handle-fail, if the execution fails again during the execution of subsequent messages, a new key = handle-fail can be created and counted.

[0079] It can be understood that the message scheduling method in this embodiment can take different implementation forms, use different storage methods, and implement programs, which are not limited in this embodiment.

[0080] Accordingly, the embodiment of the present application also discloses a message scheduling system, including:

[0081] Processing message interface 1, used to continuously receive messages from message producers;

[0082] Processing module 2 is used to perform the following operations on the same group of messages:

[0083] A numbering unit 21 is used to number all the messages in increasing order according to a logical sequence to determine a sequence number of each message, and to initialize an executable sequence number to be the sequence number of the first message;

[0084] The judgment unit 22 is used to repeatedly perform the following operations until all the messages are executed: judging whether there is a target message among all the messages, wherein the target message is specifically the message with the same sequence number as the current executable sequence number; if so, triggering the action unit 23 and adding one to the current executable sequence number;

[0085] The action unit 23 is used to execute the target message.

[0086] This embodiment numbers the same group of messages in logical order, compares the sequence number and the executable number, and only executes the messages corresponding to the executable number, thereby avoiding the problem of message disorder on the message producer side. At the same time, it clarifies the order of message execution, avoids the order disorder on the consumer side, and ensures that the group of messages can be completed smoothly.

[0087] In some specific embodiments, the process in which the judging unit 22 judges whether there is a target message in all the messages includes: regularly judging whether there is a target message in all the messages according to a preset period.

[0088] In some specific embodiments, the process of executing the target message and adding one to the current executable sequence number by the determination unit 22 includes:

[0089] executing the target message;

[0090] When the target message is executed successfully, the current executable sequence number is increased by one;

[0091] When the target message fails to be executed, the target message is executed again;

[0092] When the number of execution failures of the target message reaches an alarm threshold, an alarm message is issued.

[0093] In some specific embodiments, the processing module 2 is further used for:

[0094] The messages in the same group are marked with a group number.

[0095] In some specific embodiments, the message processing interface 1 is specifically used for:

[0096] Continuously receive messages from message producers and cache the messages in a database.

[0097] In some specific embodiments, the process of the judging unit 22 judging whether there is a target message in all the messages includes:

[0098] Retrieving a window message from the database, the window message being the message with the smallest sequence number among all the messages;

[0099] Determine whether the sequence number of the window message is equal to the current executable sequence number;

[0100] If so, determining the window message as a target message;

[0101] If not, the window message is cached in the database.

[0102] Correspondingly, the embodiment of the present application also discloses a message scheduling device, including:

[0103] Memory for storing computer programs;

[0104] A processor is used to implement the steps of the message scheduling method described in any of the above embodiments when executing the computer program.

[0105] Correspondingly, an embodiment of the present application further discloses a readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the message scheduling method described in any of the above embodiments are implemented.

[0106] Among them, the specific details of the message scheduling method in this embodiment can be referred to the relevant description in the above embodiment, and will not be repeated here.

[0107] Among them, the message scheduling device and the readable storage medium in this embodiment have the same technical effects as the message scheduling method in the above embodiment, which will not be repeated here.

[0108] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0109] The above is a detailed introduction to a message scheduling method, system and related components provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for general technical personnel in this field, according to the idea of ​​the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A message scheduling method, characterized in that: include: Continue to receive messages from message producers; Perform the following actions on the same set of said messages: Numbering all the messages in increasing order according to a logical sequence to determine a sequence number of each message, and initializing an executable sequence number to be the sequence number of the first message; Repeat the following steps until all the messages are completed: Determine whether there is a target message among all the messages, wherein the target message is specifically the message with the same sequence number as the current executable sequence number; If yes, execute the target message and increase the current executable sequence number by one; The process of continuously receiving messages from the message producer includes: Continuously receiving messages from message producers and caching the messages in a database; The process of determining whether there is a target message in all the messages includes: Retrieving a window message from the database, the window message being the message with the smallest sequence number among all the messages; Determine whether the sequence number of the window message is equal to the current executable sequence number; If so, determining the window message as a target message; If not, the window message is cached in the database.

2. The message scheduling method according to claim 1, characterized in that: The process of determining whether there is a target message in all the messages includes: It is determined periodically whether a target message exists in all the messages according to a preset period.

3. The message scheduling method according to claim 1, characterized in that: The process of executing the target message and increasing the current executable sequence number by one includes: executing the target message; When the target message is executed successfully, the current executable sequence number is increased by one; When the target message fails to be executed, the target message is executed again; When the number of execution failures of the target message reaches an alarm threshold, an alarm message is issued.

4. The message scheduling method according to claim 1, characterized in that: The process of performing the following operations on the same group of messages also includes: The messages in the same group are marked with a group number.

5. A message scheduling system, characterized in that: include: Processing message interface, used to continuously receive messages from message producers; The processing module is used to perform the following operations on the same group of messages: A numbering unit, used to number all the messages in increasing order according to a logical sequence to determine a sequence number of each message, and to initialize an executable sequence number to be the sequence number of the first message; The judgment unit is used to repeatedly perform the following operations until all the messages are executed: judging whether there is a target message among all the messages, wherein the target message is specifically the message whose sequence number is the same as the current executable sequence number; if so, triggering the action unit and adding one to the current executable sequence number; The action unit is used to execute the target message; The process of continuously receiving messages from the message producer includes: Continuously receiving messages from message producers and caching the messages in a database; The process of determining whether there is a target message in all the messages includes: Retrieving a window message from the database, the window message being the message with the smallest sequence number among all the messages; Determine whether the sequence number of the window message is equal to the current executable sequence number; If so, determining the window message as a target message; If not, the window message is cached in the database.

6. A message scheduling device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the steps of the message scheduling method as claimed in any one of claims 1 to 4 when executing the computer program.

7. A readable storage medium, characterized in that: The readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the message scheduling method according to any one of claims 1 to 4 are implemented.

Citation Information

Patent Citations

  • Server, method, and program for providing financial information

    CN102314665A

  • Message queue-based data processing method and system, and server

    CN112416614A

  • Message processing

    US20120054775A1

  • Systems and methods to organize the flow and processing of queued messages that have been received from healthcare entities

    US20200152337A1