Message enqueueing method and device

By setting up multi-level priority queues in the message queue and performing sinking processing, the message backlog problem is solved and fast and effective consumption of messages is achieved.

CN114296959BActive Publication Date: 2025-09-16BEIJING JINGDONG TUOXIAN TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202111602225.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-24
Publication Date
2025-09-16
Estimated Expiration
2041-12-24

AI Technical Summary

Technical Problem

Messages can easily accumulate during transmission, causing the message queue to be unable to provide services normally, messages to be lost, or even system crashes.

Method used

By setting up multi-level priority queues in the message queue, the messages in the high-priority queue are transferred to the low-priority queue through sinking processing until all queues are free of backlogs, and external storage is set up in the lowest priority queue as a backup solution.

Benefits of technology

Effectively reduce the occurrence of message backlogs, ensure that newly generated messages can be consumed quickly, and ensure that messages in each message queue can be consumed effectively.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114296959B_ABST
    Figure CN114296959B_ABST
Patent Text Reader

Abstract

The present invention discloses a message enqueueing method and device, and relates to the field of computer technology. A specific implementation of the method includes: determining whether there is a message backlog in the first queue of a target queue set, the target queue set includes multiple message queues, and the first queue is the queue with the highest priority among the multiple message queues; if there is a message backlog in the first queue, performing a sinking process on the message queue in the target queue set so that there is no message backlog in each message queue in the target queue set, the sinking process is used to transfer the messages in the target queue to the subordinate queue of the target queue, and the priority of the subordinate queue of the target queue is lower than the priority of the target queue; adding the to-be-processed message to the first queue. This implementation can reduce the occurrence of message backlogs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a message enqueuing method and device. Background Art

[0002] A message is a unit of data transmitted between two computers. A message queue is a container that stores messages during their transmission. If consumers cannot keep up with producers, a message backlog will occur. This backlog can cause the message queue to fail to provide services properly, messages to be lost, or even system crashes. Summary of the Invention

[0003] In view of this, an embodiment of the present invention provides a message enqueuing method and apparatus, which can reduce the occurrence of message backlog.

[0004] In a first aspect, an embodiment of the present invention provides a message enqueue method, comprising:

[0005] Get pending messages;

[0006] Determining whether a first queue in a target queue set has a message backlog, the target queue set including multiple message queues, the first queue being a queue with the highest priority among the multiple message queues;

[0007] In the case where there is a message backlog in the first queue, a sinking process is performed on the message queues in the target queue set so that no message queues in the target queue set have a message backlog. The sinking process is used to transfer the messages in the target queue to a subordinate queue of the target queue, and the priority of the subordinate queue of the target queue is lower than the priority of the target queue;

[0008] Add the to-be-processed message to the first queue.

[0009] Optionally, the sinking processing of the message queues in the target queue set includes:

[0010] Determining a second queue from the target queue set, where the priority of the second queue is higher than that of other queues in the target queue set except the first queue;

[0011] Determining whether there is a message backlog in the second queue;

[0012] If there is a message backlog in the second queue, sink the second queue;

[0013] Transfer the messages in the first queue to the second queue.

[0014] Optionally, the sinking processing of the message queues in the target queue set includes:

[0015] In the case where a current queue in the target queue set has a message backlog, determining a subordinate queue of the current queue from the target queue set, where the priority of the subordinate queue of the current queue is lower than the priority of the current queue;

[0016] Determine whether there is a message backlog in the subordinate queues of the current queue;

[0017] When there is a message backlog in the subordinate queue of the current queue, the subordinate queue of the current queue is subjected to sinking processing;

[0018] Transfer the messages in the current queue to the subordinate queue of the current queue.

[0019] Optionally, the subordinate queue of the current queue is a queue with the lowest priority in the target queue set;

[0020] The sinking processing of the lower-level queue of the current queue includes:

[0021] The messages in the queue with the lowest priority are transferred to an external storage.

[0022] Optionally, after storing the messages in the queue with the lowest priority in the external storage, the method further includes:

[0023] determining whether the queue with the lowest priority is in an idle state;

[0024] When the queue with the lowest priority is in an idle state, the message in the external storage is transferred to the queue with the lowest priority.

[0025] Optionally, the storage space of the target message queue in the target queue set is proportional to the priority parameter of the target message queue;

[0026] and / or,

[0027] The time for consumers to consume corresponding to the target message queue in the target queue set is inversely proportional to the priority parameter of the target message queue.

[0028] Optionally, after obtaining the message to be processed, the method further includes:

[0029] According to the prediction strategy, the target queue set is determined from multiple queue sets.

[0030] In a second aspect, an embodiment of the present invention provides a message enqueueing device, comprising:

[0031] Message acquisition module, used to obtain messages to be processed;

[0032] a situation determination module, configured to determine whether a first queue in a target queue set has a message backlog, the target queue set including a plurality of message queues, the first queue being a queue with the highest priority among the plurality of message queues;

[0033] a sinking processing module, configured to, when there is a message backlog in the first queue, perform a sinking process on the message queues in the target queue set so that no message queues in the target queue set have a message backlog, wherein the sinking process is configured to transfer the messages in the target queue to a subordinate queue of the target queue, wherein the priority of the subordinate queue of the target queue is lower than that of the target queue;

[0034] A message adding module is used to add the to-be-processed message to the first queue.

[0035] In a third aspect, an embodiment of the present invention provides an electronic device, including:

[0036] one or more processors;

[0037] a storage device for storing one or more programs,

[0038] When the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any one of the above embodiments.

[0039] In a fourth aspect, an embodiment of the present invention provides a computer-readable medium having a computer program stored thereon, which implements the method described in any of the above embodiments when the program is executed by a processor.

[0040] One embodiment of the above invention has the following advantages or beneficial effects: before adding a message to a message queue, it is first determined whether there is a message backlog in the first queue. If there is no message backlog in the first queue, the message is directly added to the first queue. If there is a message backlog in the first queue, the message queue in the target queue set is subjected to sinking processing so that there is no message backlog in each message queue in the target queue set, and then the message is added to the first queue after the sinking processing. Therefore, the method of the embodiment of the present invention can reduce the occurrence of message backlogs.

[0041] Furthermore, since the first queue is the highest-priority queue in the target queue set, adding messages to it ensures that newly generated messages are consumed quickly. Furthermore, consumers can be assigned to each message queue in the target queue set, ensuring that messages in each queue are consumed effectively.

[0042] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] The accompanying drawings are provided for a better understanding of the present invention and are not intended to limit the present invention.

[0044] Figure 1 This is a flow chart of a message enqueueing method provided by one embodiment of the present invention;

[0045] Figure 2 1 is a flow chart of another message enqueueing method provided by one embodiment of the present invention;

[0046] Figure 3 This is a schematic diagram of the architecture of a message processing system provided by one embodiment of the present invention;

[0047] Figure 4 This is a flow chart of a message queue sinking process provided by an embodiment of the present invention;

[0048] Figure 5 This is a schematic diagram of a process for enqueuing a message into a four-level message queue provided by an embodiment of the present invention;

[0049] Figure 6 It is a structural diagram of a message enqueueing device provided by an embodiment of the present invention;

[0050] Figure 7 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION

[0051] The following description of exemplary embodiments of the present invention is made in conjunction with the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding. These details should be considered as merely exemplary. Therefore, it should be appreciated by those skilled in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0052] When dealing with message backlogs in message queues, emergency capacity expansion can be used to handle the issue. The specific steps include: 1) first fix the consumer problem to ensure that it recovers its consumption speed, and then stop all existing consumers; 2) create a new topic with t times the original partitions, and temporarily establish a corresponding number of queues; 3) then write a temporary consumer program to distribute data, deploy this program to consume the backlog of data, and after consumption, do not perform time-consuming processing, but directly poll and write to the temporarily established t times the number of queues; 4) then temporarily requisition t times the number of machines to deploy consumers, with each batch of consumers consuming data from a temporary queue; 5) after quickly consuming the backlog of data, restore the original deployment architecture and use the original consumer machine to consume messages again. This approach is equivalent to temporarily expanding the queue resources and consumer resources by several times, and consuming data at the normal speed of t times.

[0053] You can also handle message backlogs by setting a message expiration time. If a message backlog exceeds a certain time, it will be cleared from the message queue, and the data will be lost. In this case, you can let this batch of data expire first. After the peak period, you can retrieve the lost messages and re-enter the message queue.

[0054] In production environments, setting message expiration times is generally not recommended. If a message queue is backlogged for more than a certain period of time, it will be cleared from the queue, and the message will disappear. This requires waiting for traffic peaks to pass before it can be resent, which is unacceptable in scenarios with high real-time requirements. Therefore, emergency capacity expansion is often considered. In the event of an online incident, as many servers as possible are requested to consume the backlogged messages as quickly as possible. However, if the requested servers are limited in server resources, they may not be able to obtain sufficient resources, making the problem difficult to resolve.

[0055] Based on this, an embodiment of the present invention proposes a method for enqueuing messages, which can reduce the occurrence of message backlog. Figure 1 FIG. 1 is a flow chart of a message enqueueing method provided by an embodiment of the present invention. Figure 1 As shown, the method includes:

[0056] Step 101: Get the message to be processed.

[0057] Step 102: Determine whether there is a message backlog in a first queue in a target queue set, where the target queue set includes multiple message queues, and the first queue is a queue with the highest priority among the multiple message queues.

[0058] The target queue set includes multiple message queues, each with a different priority. If a message queue has a message backlog, the message backlog is reduced by sinking the messages in the message queue to the lower queue within the message queue.

[0059] There are several ways to determine if a message queue is experiencing a message backlog. For example, you can set a threshold, such as k%. When messages in the queue account for k% of the total size, the current message consumer is consuming slowly, risking a message backlog. You can also obtain the consumption rate of the consumer and the production rate of the producer corresponding to the current queue, and use these rates to determine if the queue is experiencing a message backlog.

[0060] Step 103: When there is a message backlog in the first queue, sinking processing is performed on the message queues in the target queue set so that there is no message backlog in each message queue in the target queue set.

[0061] Sinking processing is used to transfer messages in the target queue to the subordinate queue of the target queue. The priority of the subordinate queue of the target queue is lower than that of the target queue.

[0062] For example, in descending order of priority, the target queues include: PQ1, PQ2, PQ3, and PQ4. Before adding a message to a message queue, determine whether PQ1 has a message backlog. If PQ1 does not have a message backlog, directly add the message to PQ1. If PQ1 does have a message backlog, determine whether PQ2 has a message backlog. If PQ2 does not have a message backlog, then, through sinking processing, transfer the messages in PQ1 to PQ2, and then add the pending messages to PQ1.

[0063] If there is a backlog in PQ2, determine whether there is a backlog in PQ3. If there is a backlog in PQ3, transfer the messages in PQ3 to PQ4 through sinking processing, transfer the messages in PQ2 to PQ3, transfer the messages in PQ1 to PQ2, and finally add the pending messages to PQ1.

[0064] This process continues until all messages in the message queue are free of message backlogs. If a backlog occurs in the final level, PQ4, a database or external storage system can be used for backup storage.

[0065] Step 104: Add the message to be processed to the first queue.

[0066] In an embodiment of the present invention, before adding a message to a message queue, it is first determined whether the first queue has a message backlog. If the first queue does not have a message backlog, the message is directly added to the first queue. If the first queue does have a message backlog, the message queues in the target queue set are processed downward to ensure that no message queues in the target queue set have a message backlog. The message is then added to the first queue after the downward processing. Therefore, the method of the embodiment of the present invention can reduce the occurrence of message backlogs.

[0067] Furthermore, since the first queue is the highest-priority queue in the target queue set, adding messages to it ensures that newly generated messages are consumed quickly. Furthermore, since every message queue in the target queue set has a corresponding consumer, messages in each queue are effectively consumed.

[0068] In one embodiment of the present invention, the storage space of the target message queue in the target queue set is proportional to the priority parameter of the target message queue; and / or, the time of consumption of the allocated consumer corresponding to the target message queue in the target queue set is inversely proportional to the priority parameter of the target message queue. Generally, the smaller the priority parameter, the higher the priority. For example, if the priority parameter is 1, the message has the highest priority. The higher the priority of the message queue, the smaller the priority parameter, and the smaller the allocated storage space. The smaller the priority of the message queue, the larger the priority parameter, and the larger the allocated storage space. In this way, not only the storage space required by the system can be reduced, but also when performing the sinking operation, it can ensure that the messages in the upper message queue are smoothly transferred to the lower message queue.

[0069] The higher the priority of a message queue, the smaller the priority parameter, and the longer it takes to be consumed by the consumer. The lower the priority of a message queue, the larger the priority parameter, and the shorter the time it takes to be consumed by the consumer. This allows messages in high-priority message queues to be consumed longer and be executed first.

[0070] In one embodiment of the present invention, after obtaining pending messages, the process further includes determining a target queue set from multiple queue sets based on a prediction strategy. The prediction strategy can be set based on specific needs, for example, by sequentially placing newly generated messages into each queue set. A correspondence between message producers and queue sets can also be established, and the target queue set can be determined based on the correspondence. The message storage status of each target queue set can also be obtained, and the queue set with the most remaining space can be selected as the target queue set.

[0071] In one embodiment of the present invention, the message queues in the target queue set are subjected to sinking processing, including: determining a second queue from the target queue set, the priority of the second queue being higher than that of other queues in the target queue set except the first queue; determining whether there is a message backlog in the second queue; if there is a message backlog in the second queue, sinking the second queue; transferring the messages in the first queue to the second queue. If there is no message backlog in the second queue, transfer the messages in the first queue to the second queue, and then add the pending messages to the first queue. If there is a message backlog in the second queue, sinking the second queue, transferring the messages in the first queue to the second queue, and then adding the pending messages to the first queue. It can be ensured that after adding the pending messages, there will be no message backlog in the first queue and the second queue.

[0072] Figure 2 FIG. 1 is a flow chart of another message enqueueing method provided by an embodiment of the present invention. Figure 2 As shown, the method includes:

[0073] Step 201: Obtain a message to be processed.

[0074] Step 202: Determine whether there is a message backlog in the first queue in the target queue set, where the first queue is the queue with the highest priority in the target queue set.

[0075] If yes, go to step 203. If no, go to step 212.

[0076] Step 203: Determine the first queue as the current queue.

[0077] Step 204: Determine a subordinate queue of the current queue from the target queue set, where the priority of the subordinate queue is lower than that of the current queue.

[0078] Step 205: Determine whether there is a message backlog in the lower queue.

[0079] If yes, go to step 206. If no, go to step 209.

[0080] Step 206: Determine whether the lower queue is the queue with the lowest priority in the target queue set.

[0081] If yes, go to step 207. If no, go to step 208.

[0082] Step 207: Transfer the messages in the queue with the lowest priority to the external storage.

[0083] The external storage can be a database or a document such as TXT, EXCEL, etc. When a queue with the lowest priority has a message backlog, the external storage is used to store the messages to reduce the possibility of message loss due to the message backlog.

[0084] Step 208: Determine the lower queue as the current queue.

[0085] Step 204 is re-executed to find a message queue that has no message backlog, and the message queue is used to sequentially sink the upper queues of the message queue.

[0086] Step 209: Transfer the messages in the current queue to the lower-level queue.

[0087] Step 210: Determine whether the current queue is the first queue.

[0088] If yes, the sinking process has been completed for each queue, and step 212 is executed. If no, step 211 is executed.

[0089] Step 211: Determine the parent queue of the current queue from the target queue set, and determine the parent queue as the current queue.

[0090] The priority of the parent queue of the current queue is higher than the priority of the current queue. Re-execute step 209. Transfer the messages in the current queue to the subordinate queues in sequence until the current queue becomes the first queue.

[0091] Step 212: Add the message to be processed to the first queue.

[0092] In an embodiment of the present invention, a search is performed on each level of message queues in the target queue set until a message queue without message backlogs is found. Using this message queue without message backlogs, each of its parent queues is sequentially processed downwards until all message queues in the current queue set are free of message backlogs. Using the method of this embodiment of the present invention, the risk of message backlogs can be reduced.

[0093] In one embodiment of the present invention, after storing the messages in the queue with the lowest priority in the external storage, it also includes: determining whether the queue with the lowest priority is in an idle state; if the queue with the lowest priority is in an idle state, transferring the messages in the external storage to the queue with the lowest priority.

[0094] There are several ways to determine whether a message queue is idle. For example, you can set a threshold, such as k%. When the space occupied by messages in the current queue is less than k% of the total size of the message queue, the current message consumer is consuming quickly and the message queue is idle. You can also obtain the consumption rate of the consumer and the production rate of the producer corresponding to the current queue, and use these rates to determine whether the current queue is idle.

[0095] When the queue with the lowest priority is in an idle state, the message in the external storage is transferred to the queue with the lowest priority, so that the message in the external storage can be executed smoothly.

[0096] To make the solution of the embodiment of the present invention easier to understand, the embodiment of the present invention also provides a message processing system. Figure 3 This is a schematic diagram of the architecture of a message processing system provided by one embodiment of the present invention. Figure 3 As shown, the solution of the embodiment of the present invention is to reduce the occurrence of message backlogs and the situation where a large number of servers need to be expanded to solve the message backlog by combining message queues and multi-level priority queues. After the producer produces the message, it is delivered to the message queue cluster. There is a structure composed of multi-level priority queues in the message queue. The message is sent to one of the nodes. Each node corresponds to a message queue set. Each message queue set includes multiple message queues, and different message queues correspond to different priorities. After the message enters the node, it is evaluated according to the threshold set for each level of queue and the actual storage situation, the queue is adjusted, and the new message is stored for consumption by consumers.

[0097] When using the solution of the embodiment of the present invention, it is necessary to create a system consisting of multiple nodes, each of which is composed of multiple levels of priority queues. For each queue in each node, a corresponding threshold value, such as k%, needs to be set. This means that when the messages stored in the current queue occupy k% of the total size, it indicates that the current message consumption process is relatively slow and there is a risk of message backlog. To ensure the timeliness of subsequent message consumption, the messages in priority queue PQ1 are downgraded and sent to PQ2. At this time, PQ1 will be cleared and all subsequent new messages will enter PQ1. Similarly, each level of queue has a corresponding threshold value set in turn. The lower the level, the lower the priority, the larger the storage space, and the less time will be allocated for consuming messages. For example, the priorities of PQ1, PQ2, PQ3, and PQ4 decrease in sequence. When the PQ1, PQ2, PQ3, and PQ4 queues are all full, the time allocated to consumers for consumption should be reduced in sequence, such as t, 0.5t, 0.25t, and 0.125t. When the lowest-priority queue reaches its threshold, messages in the queue are temporarily stored in a database, such as Redis or Oracle. When the lowest-priority queue's storage rate drops or reaches 0, the relevant messages are returned from the database to the lowest-priority queue. In this mode, the probability of message backlogs is greatly reduced. When slow consumption leads to a message backlog, the rapid consumption of subsequent messages is effectively guaranteed by sinking messages. Consuming messages from queues of every priority level also ensures that messages in queues at all levels are effectively consumed. Furthermore, a database is used as a backup solution to store node messages, preventing queues from being completely full.

[0098] Figure 4 This is a flow chart of a message queue sinking process provided by an embodiment of the present invention. Figure 4 As shown, when building a node, multiple queues of different sizes are used to form a multi-level priority queue. When the message storage threshold of priority queue 1, the highest priority node, is reached, its internal messages are transferred to priority queue 2, which has greater storage space. Similarly, when priority queue 2 reaches the threshold, it is transferred to priority queue 3, which is then transferred to priority queue 4. The database temporarily stores messages and returns them when node pressure is low. This method is used to build a message queue cluster. The reliability of the message queue is guaranteed even when a large number of messages are accessed. When an empty queue becomes empty, it becomes the new lowest priority queue for messages from other queues to be transferred to. The other queues then adjust the message consumption time of each queue.

[0099] Figure 5 This is a flow chart of a message queue entry process for a four-level message queue provided by an embodiment of the present invention. Figure 5As shown in the figure, when the highest priority queue exceeds the set threshold, the second-level queue is determined to have exceeded the set threshold. When the second-level queue exceeds the set threshold, the third-level queue is determined to have exceeded the set threshold. When the third-level queue exceeds the set threshold, the fourth-level queue is determined to have exceeded the set threshold. When the fourth-level queue exceeds the set threshold, the fourth-level queue is temporarily stored in Redis, and the remaining third-level queue is recursively stored until the highest priority queue is empty. Messages are then added to the highest priority queue.

[0100] Figure 6 FIG. 1 is a structural diagram of a message enqueueing device provided by an embodiment of the present invention. Figure 6 As shown, the device includes:

[0101] Message acquisition module 601, used to obtain messages to be processed;

[0102] A situation determination module 602 is configured to determine whether a first queue in a target queue set has a message backlog, wherein the target queue set includes multiple message queues, and the first queue is a queue with the highest priority among the multiple message queues;

[0103] A sinking processing module 603 is configured to, when there is a message backlog in the first queue, perform a sinking process on the message queues in the target queue set so that no message queues in the target queue set have a message backlog. The sinking process is configured to transfer the messages in the target queue to a subordinate queue of the target queue, where the priority of the subordinate queue of the target queue is lower than that of the target queue.

[0104] The message adding module 604 is configured to add the to-be-processed message to the first queue.

[0105] Optionally, the sinking processing module 603 is specifically configured to:

[0106] Determining a second queue from the target queue set, where the priority of the second queue is higher than that of other queues in the target queue set except the first queue;

[0107] Determining whether there is a message backlog in the second queue;

[0108] If there is a message backlog in the second queue, sink the second queue;

[0109] Transfer the messages in the first queue to the second queue.

[0110] Optionally, the sinking processing module 603 is specifically configured to:

[0111] In the case where a current queue in the target queue set has a message backlog, determining a subordinate queue of the current queue from the target queue set, where the priority of the subordinate queue of the current queue is lower than the priority of the current queue;

[0112] Determine whether there is a message backlog in the subordinate queues of the current queue;

[0113] When there is a message backlog in the subordinate queue of the current queue, the subordinate queue of the current queue is subjected to sinking processing;

[0114] Transfer the messages in the current queue to the subordinate queue of the current queue.

[0115] Optionally, the subordinate queue of the current queue is a queue with the lowest priority in the target queue set;

[0116] The sinking processing module 603 is specifically used to:

[0117] The messages in the queue with the lowest priority are transferred to an external storage.

[0118] Optionally, the device further comprises:

[0119] A return module 605 is configured to determine whether the queue with the lowest priority is in an idle state;

[0120] When the queue with the lowest priority is in an idle state, the message in the external storage is transferred to the queue with the lowest priority.

[0121] Optionally, the storage space of the target message queue in the target queue set is proportional to the priority parameter of the target message queue;

[0122] and / or,

[0123] The time for consumers to consume corresponding to the target message queue in the target queue set is inversely proportional to the priority parameter of the target message queue.

[0124] Optionally, the device further comprises:

[0125] The queue set determination module 606 is configured to determine the target queue set from multiple queue sets according to a prediction strategy.

[0126] An embodiment of the present invention provides an electronic device, including:

[0127] one or more processors;

[0128] a storage device for storing one or more programs,

[0129] When one or more programs are executed by one or more processors, the one or more processors implement the method of any of the above embodiments.

[0130] Reference below Figure 7 , which shows a schematic structural diagram of a computer system 700 of a terminal device suitable for implementing an embodiment of the present invention. Figure 7 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0131] like Figure 7 As shown, the computer system 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage unit 708 into a random access memory (RAM) 703. Various programs and data required for the operation of the system 700 are also stored in the RAM 703. The CPU 701, ROM 702, and RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.

[0132] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, a mouse, and the like; an output section 707 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and a speaker; a storage section 708 including a hard disk; and a communication section 709 including a network interface card such as a LAN card or a modem. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 710 as needed, so that computer programs read therefrom can be installed into the storage section 708 as needed.

[0133] In particular, according to the embodiments disclosed in the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in the present invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program comprising program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 709, and / or installed from a removable medium 711. When the computer program is executed by the central processing unit (CPU) 701, the above-mentioned functions defined in the system of the present invention are executed.

[0134] It should be noted that the computer-readable medium described in the present invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of computer-readable storage media can include, but are not limited to, an electrical connection having one or more conductors, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. This propagated data signal can take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device. Program code embodied on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wireline, optical fiber cable, RF, or any suitable combination thereof.

[0135] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the above-mentioned module, program segment, or a part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0136] The modules involved in the embodiments of the present invention may be implemented in software or hardware. The modules described may also be provided in a processor. For example, they may be described as: a message acquisition module, a situation determination module, a sinking processing module, and a message adding module. The names of these modules do not, in some cases, constitute limitations on the modules themselves. For example, the message acquisition module may also be described as a "module for acquiring messages to be processed."

[0137] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiments, or may exist independently without being incorporated into the device. The computer-readable medium carries one or more programs, and when the one or more programs are executed by the device, the device includes:

[0138] Get pending messages;

[0139] Determining whether a first queue in a target queue set has a message backlog, the target queue set including multiple message queues, the first queue being a queue with the highest priority among the multiple message queues;

[0140] In the case where there is a message backlog in the first queue, a sinking process is performed on the message queues in the target queue set so that no message queues in the target queue set have a message backlog. The sinking process is used to transfer the messages in the target queue to a subordinate queue of the target queue, and the priority of the subordinate queue of the target queue is lower than the priority of the target queue;

[0141] Add the to-be-processed message to the first queue.

[0142] According to the technical solution of an embodiment of the present invention, before adding a message to a message queue, it is first determined whether there is a message backlog in the first queue. If there is no message backlog in the first queue, the message is directly added to the first queue. If there is a message backlog in the first queue, the message queue in the target queue set is subjected to sinking processing so that there is no message backlog in each message queue in the target queue set, and then the message is added to the first queue after the sinking processing. Therefore, the method of the embodiment of the present invention can reduce the occurrence of message backlogs.

[0143] Furthermore, since the first queue is the highest-priority queue in the target queue set, adding messages to it ensures that newly generated messages are consumed quickly. Furthermore, since every message queue in the target queue set has a corresponding consumer, messages in each queue are effectively consumed.

[0144] The above specific embodiments do not limit the scope of protection of the present invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention.

Claims

1. A message enqueue method, characterized in that: include: Get pending messages; Determining whether a first queue in a target queue set has a message backlog, the target queue set including multiple message queues, the first queue being a queue with the highest priority among the multiple message queues; In the case where there is a message backlog in the first queue, a sinking process is performed on the message queues in the target queue set so that no message queues in the target queue set have a message backlog. The sinking process is used to transfer the messages in the target queue to a subordinate queue of the target queue, and the priority of the subordinate queue of the target queue is lower than the priority of the target queue; The sinking of the message queues in the target queue set includes: determining a second queue from the target queue set, wherein the priority of the second queue is higher than that of other queues in the target queue set except the first queue; determining whether there is a message backlog in the second queue; sinking the second queue if there is a message backlog in the second queue; and transferring the messages in the first queue to the second queue; Add the to-be-processed message to the first queue.

2. The method according to claim 1, characterized in that The sinking processing of the message queue in the target queue concentration includes: In the case where a current queue in the target queue set has a message backlog, determining a subordinate queue of the current queue from the target queue set, where the priority of the subordinate queue of the current queue is lower than the priority of the current queue; Determine whether there is a message backlog in the subordinate queues of the current queue; When there is a message backlog in the subordinate queue of the current queue, the subordinate queue of the current queue is subjected to sinking processing; Transfer the messages in the current queue to the subordinate queue of the current queue.

3. The method according to claim 2, characterized in that The subordinate queue of the current queue is the queue with the lowest priority in the target queue set; The sinking processing of the lower-level queue of the current queue includes: The messages in the queue with the lowest priority are transferred to an external storage.

4. The method according to claim 3, characterized in that After storing the messages in the queue with the lowest priority in the external storage, the method further includes: determining whether the queue with the lowest priority is in an idle state; When the queue with the lowest priority is in an idle state, the message in the external storage is transferred to the queue with the lowest priority.

5. The method according to claim 1, characterized in that The storage space of the target message queue in the target queue set is proportional to the priority parameter of the target message queue; and / or, The time for consumers to consume corresponding to the target message queue in the target queue set is inversely proportional to the priority parameter of the target message queue.

6. The method according to claim 1, characterized in that After obtaining the message to be processed, the method further includes: According to the prediction strategy, the target queue set is determined from multiple queue sets.

7. A message enqueueing device, characterized in that: include: Message acquisition module, used to obtain messages to be processed; a situation determination module, configured to determine whether a first queue in a target queue set has a message backlog, the target queue set including a plurality of message queues, the first queue being a queue with the highest priority among the plurality of message queues; a sinking processing module, configured to, when there is a message backlog in the first queue, perform a sinking process on the message queues in the target queue set so that no message queues in the target queue set have a message backlog, wherein the sinking process is configured to transfer the messages in the target queue to a subordinate queue of the target queue, wherein the priority of the subordinate queue of the target queue is lower than that of the target queue; The sinking processing module is specifically configured to: determine a second queue from the target queue set, where the priority of the second queue is higher than that of other queues in the target queue set except the first queue; determine whether there is a message backlog in the second queue; if there is a message backlog in the second queue, perform sinking processing on the second queue; and transfer messages in the first queue to the second queue; A message adding module is used to add the to-be-processed message to the first queue.

8. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 6.

9. A computer-readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Message processing method and device based on message queue system

    CN107197015A

  • Message storage method and device in message queue, medium and electronic device

    CN110333956A

  • Design method of data storage architecture and message transmission method and device

    CN113342544A