Message management method, device, storage medium and computer equipment
By introducing a queue cutting mechanism in the message queue, consuming and correcting error messages, the problem of error correction delay in the message queue system is solved, ensuring the real-time and stability of the system.
Patent Information
- Application Number
- CN202011599121.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-29
- Publication Date
- 2025-01-07
- Estimated Expiration
- 2040-12-29
AI Technical Summary
In distributed scenarios, there is a delay in the error correction function of messages in the message queue system, resulting in the inability to correct error messages in time, affecting the real-time and stability of system data.
By introducing a queue jump mechanism in the message queue, we can judge whether there is a queue jump message to be consumed based on the message mapping table, and consume and correct error messages without affecting the normal message transmission to ensure that the data is updated in a timely manner.
It realizes timely correction and revocation of error messages in the message queue, ensures the real-time and stability of the system, and avoids data update delays and errors.
Smart Images

Figure CN112631807B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a message management method, device, storage medium and computer equipment. Background Art
[0002] NATS is a lightweight and efficient message queue system. However, messages to be sent can only be added to the end of the message queue, so messages cannot be operated and managed after entering the message queue. In a distributed scenario, assuming that our messages support error correction, after a message is sent, it is found that the content of the message is wrong. However, in this case, there are a large number of messages being sent or consumed in each time period. If the error correction message is sent directly to the message queue and then waits for the queue to send it out, the update of the system data will be delayed. This will result in that if the content of one or some messages is found to be wrong, it cannot be corrected in time, resulting in untimely or even erroneous system data updates. Summary of the invention
[0003] In order to solve the technical problem that the above-mentioned message cannot be corrected in time, the embodiments of the present application provide a message management method, apparatus, storage medium and computer device.
[0004] In a first aspect, an embodiment of the present application provides a message management method, the method comprising:
[0005] Obtain the message ID of the message to be consumed in the first message queue according to the outgoing direction of the first message queue;
[0006] Obtain the message mapping table corresponding to the message to be consumed according to the message ID of the message to be consumed;
[0007] Determine whether there is a queue-jumping message among the messages to be consumed according to the message mapping table corresponding to the messages to be consumed;
[0008] If there are queue-jumping messages among the messages to be consumed, the messages to be consumed and the queue-jumping messages of the messages to be consumed are consumed.
[0009] Optionally, consuming the to-be-consumed message and the queue-jumping message of the to-be-consumed message includes:
[0010] After consuming the waiting-to-be-consumed message, consume the queue-jumping message of the waiting-to-be-consumed message.
[0011] Optionally, the message mapping table includes a message management table;
[0012] Before obtaining the message ID of the message to be consumed in the first message queue according to the dequeue direction of the first message queue, the method further includes:
[0013] A corresponding message management table is established for each incoming message in the first message queue, and the message management table stores a message ID and a message code of the corresponding incoming message;
[0014] Obtain the queue-jumping message, and determine the queue-jumped message corresponding to the queue-jumping message in the first message queue;
[0015] Determine whether the queue-intercepted message is at the end of the first message queue;
[0016] If the queue-jumped message is not at the end of the first message queue, the message content of the queue-jumped message is encoded to obtain a sub-message code;
[0017] The sub-message code of the queue-jumping message is stored in the message management table corresponding to the queue-jumping message.
[0018] Optionally, if the interrupted message is at the end of the first message queue and the first message queue is not full, the interrupted message is added to the first message queue after the interrupted message.
[0019] Optionally, a corresponding message management table is established for each incoming message in the first message queue, including:
[0020] Get the message ID and message content of each incoming message in the first message queue respectively;
[0021] Encode the message content of each incoming message to obtain the corresponding message code;
[0022] A message management table is established for each incoming message in the first message queue according to the message ID and the message code.
[0023] Optionally, the sub-message code of the queue-jumping message is stored in the message management table corresponding to the queue-jumped message, including:
[0024] Determine whether the number of sub-message codes stored in the message management table corresponding to the queued message has reached the maximum allowed storage capacity;
[0025] If the number of sub-message codes stored in the message management table corresponding to the interrupted message does not reach the maximum allowed storage capacity, the sub-message codes of the interrupted message are stored in the target position in the message management table corresponding to the interrupted message in sequence.
[0026] Optionally, after encoding the message content of the queue-jumping message to obtain a sub-message code, the method further includes:
[0027] If the number of sub-message codes stored in the message management table corresponding to the interrupted message has reached the maximum allowed storage capacity, then obtain a standby interrupted message in the first message queue that is located after the interrupted message and the number of sub-message codes stored in the corresponding message management table has not reached the maximum allowed storage capacity;
[0028] The sub-message codes of the queue-jumping message are stored in a target position in the message management table corresponding to the candidate queue-jumping message in sequence.
[0029] Optionally, judging whether there is a queue-jumping message among the messages to be consumed according to the message mapping table corresponding to the messages to be consumed includes:
[0030] According to the message management table corresponding to the message to be consumed, it is determined whether there is a queue-jumping message among the messages to be consumed.
[0031] Optionally, the message mapping table also includes a message operation table;
[0032] According to the message mapping table corresponding to the message to be consumed, it is determined whether there is a queue-jumping message in the message to be consumed, including:
[0033] Get the queue-jumping status in the message operation table corresponding to the message to be consumed to determine whether there is a queue-jumping message among the messages to be consumed;
[0034] If the queue-jumping status is valid, it is determined that there is a queue-jumping message among the messages to be consumed.
[0035] Optionally, before obtaining the message ID of the message to be consumed in the first message queue according to the dequeue direction of the first message queue, the method further includes:
[0036] A corresponding message operation table is established for each incoming message in the first message queue.
[0037] The message operation table stores the message ID and queue-jumping status of the corresponding queued message.
[0038] After storing the sub-message code of the queue-jumping message in the message management table corresponding to the queue-jumped message, the method further includes:
[0039] Set the queue interruption status in the message operation table corresponding to the queue interrupted message to be valid.
[0040] Optionally, if there is a queue-jumping message in the message to be consumed, before consuming the message to be consumed and the queue-jumping message of the message to be consumed, the method further includes:
[0041] Get the revocation status in the message mapping table corresponding to the message to be consumed to determine whether the message to be consumed is a message to be revoked.
[0042] If the cancellation status is valid, the message to be consumed is determined to be a message to be cancelled, and the consumption of the message to be consumed is canceled.
[0043] If there is a queue-jumping message among the messages to be consumed, the queue-jumping message of the message to be consumed is consumed;
[0044] If there is a queue-jumping message in the message to be consumed, the message to be consumed and the queue-jumping message of the message to be consumed are consumed, including:
[0045] If the revocation status is invalid, it is determined that the message to be consumed is not a message to be revoked. If there is a queue-jumping message in the message to be consumed, the message to be consumed and the queue-jumping message of the message to be consumed are consumed.
[0046] Optionally, the message mapping table includes a message operation table;
[0047] Before obtaining the message ID of the message to be consumed in the first message queue according to the dequeue direction of the first message queue, the method further includes:
[0048] A corresponding message operation table is established for each incoming message in the first message queue.
[0049] The message operation table stores the message ID and cancellation status of the corresponding queued message.
[0050] Get the revocation instruction, which carries the message ID of the message to be revoked.
[0051] According to the message ID of the message to be revoked and the message operation table of the queued messages in the first message queue, the queued message with the same message ID as the message to be revoked is searched as the message to be revoked,
[0052] The revocation status in the message operation table of the message to be revoked is set to valid.
[0053] Optionally, the message mapping table includes a message operation table;
[0054] Before obtaining the message ID of the message to be consumed in the first message queue according to the dequeue direction of the first message queue, the method further includes:
[0055] A corresponding message operation table is established for each incoming message in the first message queue.
[0056] The message operation table stores the message ID, message code and cancellation status of the corresponding queued message.
[0057] Get the revocation instruction, which carries the message content of the message to be revoked.
[0058] The message content of the message to be revoked is encoded to obtain the corresponding revocation message code.
[0059] According to the cancellation message code and the message operation table of the queued messages in the first message queue, the queued message with the same message code as the cancellation message code is searched as the message to be cancelled,
[0060] Set the revocation status in the message operation table of the message to be revoked to valid.
[0061] Optionally, the queue-interrupting message carries the message ID of the queue-interrupted message.
[0062] Optionally, consuming the waiting-to-be-consumed message and the queue-jumping message of the waiting-to-be-consumed message includes:
[0063] Decode the message code of the message to be consumed in the message management table corresponding to the message to be consumed to obtain the content of the message to be consumed;
[0064] Send the to-be-consumed message content to the target subscriber through the first message queue;
[0065] Decode the sub-message code of the queue-jumping message in the message management table corresponding to the message to be consumed to obtain the content of the queue-jumping message to be consumed;
[0066] The content of the queue-jumping message to be consumed is sent to the target subscriber through the second message queue.
[0067] In a second aspect, an embodiment of the present application provides a message management device, the device comprising:
[0068] A first message acquisition module, used to acquire the message ID of the message to be consumed in the first message queue according to the dequeue direction of the first message queue;
[0069] The first search module is used to obtain a message mapping table corresponding to the message to be consumed according to the message ID of the message to be consumed;
[0070] The first judgment module is used to judge whether there is a queue-jumping message among the messages to be consumed according to the message mapping table corresponding to the messages to be consumed;
[0071] The consumption module is used to consume the message to be consumed and the queue-jumping message of the message to be consumed if there is a queue-jumping message in the message to be consumed.
[0072] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the processor executes the steps of any of the foregoing methods.
[0073] In a fourth aspect, an embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the steps of any of the foregoing methods when executing the program.
[0074] The above technical solution provided by the embodiment of the present application has the following advantages compared with the prior art:
[0075] The embodiment of the present application obtains the message ID of the message to be consumed in the first message queue according to the dequeue direction of the first message queue; obtains the message mapping table corresponding to the message to be consumed according to the message ID of the message to be consumed; determines whether there is a queue-jumping message in the message to be consumed according to the message mapping table corresponding to the message to be consumed; if there is a queue-jumping message in the message to be consumed, consumes the message to be consumed and the queue-jumping message of the message to be consumed. Through the present application, it is realized to modify and correct the error message in the message queue by queue-jumping, and it does not affect the normal sending of other messages, and the data is updated in time to ensure the real-time and stability of the system. At the same time, if a message carrying erroneous data is found in the queue, the message can be revoked in time to ensure the safety and reliability of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0076] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0077] 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, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0078] Figure 1 A flowchart of a message management method provided by an embodiment of the present application;
[0079] Figure 2 A mapping relationship diagram between messages and a message management table provided in an embodiment of the present application;
[0080] Figure 3 A structural block diagram of a message management device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0081] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0082] Figure 1 A flow chart of a message management method provided by an embodiment of the present application; Figure 1, the method comprises the following steps:
[0083] S600: Obtain the message ID of the message to be consumed in the first message queue according to the dequeue direction of the first message queue.
[0084] Specifically, the incoming messages in the message queue are consumed in the order of first-in, first-out. Therefore, the order of queuing the incoming messages is based on the outbound direction of the message queue, with the first-in messages at the head of the queue and the last-in messages at the back of the queue.
[0085] The message ID is a unique identifier or identity for each message.
[0086] The message to be consumed is the message currently to be consumed in the first message queue, and is located at the head of the queue in the outbound direction of the first message queue.
[0087] In the present application, the first message queue is a queue that normally stores incoming messages and consumed messages during message transmission.
[0088] S700: Obtain a message mapping table corresponding to the message to be consumed according to the message ID of the message to be consumed.
[0089] Each incoming message in the first message queue has its own corresponding message mapping table, and the message mapping table stores the message ID corresponding to the incoming message and the related information of the queue-jumping message corresponding to the incoming message.
[0090] The messages to be consumed belong to the queued messages in the first message queue.
[0091] S800: Determine whether there is any queue-jumping message among the messages to be consumed according to the message mapping table corresponding to the messages to be consumed.
[0092] Specifically, if the message mapping table corresponding to the message to be consumed stores relevant information of the queue-jumping message, it means that there is a queue-jumping message for the message to be consumed; if the message mapping table corresponding to the message to be consumed does not exist or does not store relevant information of the queue-jumping message, it means that there is no corresponding queue-jumping message for the message to be consumed.
[0093] S900: If there is an interrupting message among the messages to be consumed, the messages to be consumed and the interrupting messages of the messages to be consumed are consumed.
[0094] Specifically, since the message to be consumed and the corresponding queue-jumping message correspond to the same subscriber and the contents may be mutually exclusive, in order to avoid system disorder, the message to be consumed and the corresponding queue-jumping message cannot be consumed at the same time, that is, they need to be consumed at different times.
[0095] In a specific embodiment, the to-be-consumed message and the corresponding queue-jumping message are queued in different message queues, and the to-be-consumed message is consumed first, and then the corresponding queue-jumping message is consumed.
[0096] In one embodiment, the message mapping table includes a message management table.
[0097] Before step S600, the message management method further includes the following steps:
[0098] S010: A corresponding message management table is established for each incoming message in the first message queue, and the message management table stores a message ID and a message code of the corresponding incoming message.
[0099] Step S010 specifically includes:
[0100] S011: Obtain the message ID and message content of each incoming message in the first message queue respectively;
[0101] S012: Encode the message content of each incoming message to obtain a corresponding message code;
[0102] S013: Establish a message management table for each incoming message in the first message queue according to the message ID and the message code.
[0103] Specifically, the incoming messages in the message queue are consumed in the order of first-in, first-out. Therefore, the order of queuing the incoming messages is based on the outbound direction of the message queue, with the first-in messages at the head of the queue and the last-in messages at the back of the queue.
[0104] In the present application, the first message queue is a queue that normally stores incoming messages and consumed messages during message transmission. Incoming messages in the first message queue can be queued.
[0105] Each incoming message in the first message queue has its own corresponding message management table, and the message management table stores the message ID and message code of the corresponding incoming message. The message management table is a part of the message mapping table.
[0106] The message code is obtained by encoding the message content of the corresponding incoming message. Message coding is equivalent to another storage form of message content. Since message coding is the encoding of message content, message coding can improve the security and confidentiality of message content.
[0107] S020: Obtain a queue-jumping message, and determine the queue-jumped message corresponding to the queue-jumping message in the first message queue.
[0108] Specifically, the interrupted message is an incoming message in the first message queue. The interrupted message is an error correction message of the interrupted message, which is used to correct part of the content of the interrupted message after consumption, or to replace and update the entire content of the interrupted message.
[0109] The queue-intercepting message corresponding to the queue-intercepting message is consumed first, and the queue-intercepting message is consumed later.
[0110] The queue-jumping message is specifically an error correction message generated when an error is found in the content of a previously sent message. The message being queued is the error message.
[0111] S030: Determine whether the interrupted message is at the end of the first message queue.
[0112] Specifically, the queued message is a queued message that is normally queued in the first message queue, and may be located at the head or the tail of the first message queue, or may be located somewhere in the middle of the first message queue.
[0113] S040: If the queue-jumped message is not at the end of the first message queue, encode the message content of the queue-jumped message to obtain a sub-message code;
[0114] S050: Store the sub-message code of the queue-jumping message in the message management table corresponding to the queue-jumped message.
[0115] Specifically, if the interrupted message is not at the end of the first message queue, the message content of the interrupted message is encoded to obtain the sub-message code of the interrupted message. The sub-message code is equivalent to another storage form of the message content of the interrupted message.
[0116] Of course, the encoding process of the present application can also be encoding process and encryption process, that is, the message content is not only encoded but also encrypted to obtain a message code or a sub-message code.
[0117] The obtained sub-message code is stored in the message management table of the queued message. In this application, the queued message and the queued message are queued in different message queues. Therefore, the queued message will not be queued in the first message queue, nor will it affect the normal execution progress of other queued messages in the first message queue.
[0118] Because each message will be quickly consumed within a certain period of time after entering the queue, if it is consumed for a long time before sending a queue-jumping message, it will not make much sense. Therefore, the maximum number of times each queue-entering message can be queued is limited in this application, that is, the number of corresponding queue-jumping messages is limited. It is set according to the actual situation. For example, the maximum number of queue-jumping messages corresponding to each queue-entering message is 1, 2, 3, etc., but it is not limited to this.
[0119] In one embodiment, step S050 specifically includes:
[0120] S051: Determine whether the number of sub-message codes stored in the message management table corresponding to the queue-jumped message has reached the maximum allowed storage capacity;
[0121] S052: If the number of sub-message codes stored in the message management table corresponding to the interrupted message does not reach the maximum allowed storage capacity, the sub-message codes of the interrupted message are stored in sequence to the target position in the message management table corresponding to the interrupted message.
[0122] Specifically, the number of times each queue-entering message can be interrupted is limited, that is, the number of corresponding queue-intercepting messages is limited. Therefore, the storage capacity of the sub-message code that can be stored in the message management table corresponding to each queue-intercepted message is limited. Therefore, only when there is remaining storage capacity in the message management table corresponding to the queue-intercepted message, the sub-message code of the queue-intercepting message can be stored in the message management table of the queue-intercepted message.
[0123] At the same time, the sub-message codes of each queue-jumping message in the message management table of the queue-jumped message are stored in the order of acquisition to ensure that the first-stored-first-consumed. Specifically, a storage code can be set for the sub-message code of each queue-jumping message in the message management table, and the storage code represents the order in which the sub-message codes are stored and consumed.
[0124] However, in order to prevent important error correction messages from being filtered out due to insufficient storage capacity, after step S040, the method further includes the following steps:
[0125] S060: storing the sub-message code of the queue-jumping message in the message management table corresponding to the queue-entering message located after the queue-jumped message.
[0126] Steps S050 and S060 are parallel solutions. After S040, only one of steps S050 and S060 can be selected to be executed.
[0127] Step S060 specifically includes the following steps:
[0128] S061: If the number of sub-message codes stored in the message management table corresponding to the queue-jumped message has reached the maximum allowed storage capacity, then obtain a candidate queue-jumped message in the first message queue that is located after the queue-jumped message and whose number of sub-message codes stored in the corresponding message management table has not reached the maximum allowed storage capacity;
[0129] S062: storing the sub-message codes of the queue-jumping message in order of precedence to the target position in the message management table corresponding to the candidate queue-jumping message.
[0130] Specifically, in this embodiment, the queue-jumped message is not the queue-entering message at the end of the first message queue, so there are other queue-entering messages behind the queue-jumped message. If the number of sub-message codes stored in these other queue-entering messages does not reach the maximum allowed storage capacity, they will be used as standby queue-jumped messages.
[0131] Prioritize, this application selects the queue entry message that is located after the queued message and closest to the queued message, and the number of sub-message codes stored in the corresponding message management table does not reach the maximum allowed storage capacity as the standby queued message. In this way, as long as the standby queued message is consumed, the queued message can be consumed immediately. It is ensured that the queued message can be consumed as quickly as possible. In order to correct the error of the queued message as soon as possible.
[0132] Although the queue-jumping message is essentially not a queue-jumping message of the queue-jumping message, the queue-jumping message does not affect the execution of the queue-jumping message, which not only realizes the full utilization of resources, but also ensures that errors are corrected in time and maintains system stability.
[0133] In one embodiment, the method further comprises the following steps:
[0134] S070: If the interrupted message is at the end of the first message queue and the first message queue is not full, add the interrupted message to the first message queue after the interrupted message.
[0135] Specifically, the moment when the message to be consumed in this application is consumed is close to the moment when the message to be consumed is consumed, that is, after the message to be consumed is consumed, the message to be consumed is consumed immediately, and the delay will not be too long, so as to achieve the purpose of correcting the error as quickly as possible. If the message to be consumed is already the last message to enter the queue of the first message queue, and the current first message queue is not full, and other messages can be queued, then the message to be consumed is directly inserted behind the message to be consumed in the first message queue, which will not delay the execution of other messages to be consumed in the queue of the first message queue, and can also ensure that the message to be consumed can be consumed in time, and the error of the message to be consumed can be updated or corrected as soon as possible.
[0136] When the queue-jumping message is inserted into the first message queue, a corresponding message management table will be created for it.
[0137] Step S040 and step S070 are parallel solutions. After step S030, only one of step S040 and step S070 can be selected to be executed.
[0138] In one embodiment, step S800 specifically includes: judging whether there is any queue-jumping message among the messages to be consumed according to the message management table corresponding to the messages to be consumed.
[0139] Specifically, if there is a queue-jumping message among the messages to be consumed, the message management table stores the sub-message code corresponding to the queue-jumping message. The sub-message code in the message management table can be used to determine whether there is a queue-jumping message among the messages to be consumed.
[0140] It can be seen from steps S061 and S062 that the sub-message code stored in the message management table of each queue-jumping message may be the sub-message code of its actual queue-jumping message, i.e., the error correction message, or it may be the sub-message code of the queue-jumping message or error correction message of the previous queue-entering message.
[0141] In one embodiment, the message mapping table also includes a message operation table.
[0142] Step S800 specifically includes:
[0143] S810: Obtain the queue-jumping status in the message operation table corresponding to the message to be consumed to determine whether there is a queue-jumping message among the messages to be consumed;
[0144] S820: If the queue-jumping status is valid, determine that there is a queue-jumping message among the messages to be consumed.
[0145] Specifically, the message operation table stores the message ID and queue-jumping status of the corresponding queue-entering message; the queue-jumping status indicates whether the queue-entering message is queue-jumped, that is, whether there is a queue-jumping message.
[0146] The queue-jumping status can be represented by 0 and 1, 0 represents invalid, indicating that the queue has not been jumped, and 1 represents valid, indicating that the queue has been jumped.
[0147] The queue-jumping status can also be represented by false and true. False means invalid, indicating that the queue has not been jumped, and true means valid, indicating that the queue has been jumped.
[0148] By searching the message operation table according to the message ID of the message to be consumed, it can be determined whether there is a queue-jumping message among the messages to be consumed.
[0149] In one embodiment, before step S600, the method further includes the following steps:
[0150] S090: Create a corresponding message operation table for each incoming message in the first message queue.
[0151] The message operation table stores the message ID and queue interruption status corresponding to the queue entry message.
[0152] After step S050, the method further comprises the following steps:
[0153] S0100: Set the queue-interrupting status in the message operation table corresponding to the queue-interrupting message to be valid.
[0154] After step S060, the method further includes the following steps:
[0155] S0200: Set the queue-intercepting status in the message operation table corresponding to the queue-entering message after the queue-intercepted message to be valid.
[0156] Specifically, the queue interruption status in the message operation table corresponding to the queue interruption candidate message is set to valid.
[0157] In one embodiment, before step S900, the method further includes the following steps:
[0158] S001: Obtain the revocation status in the message mapping table corresponding to the message to be consumed to determine whether the message to be consumed is a message to be revoked;
[0159] S002: If the cancellation status is valid, determine that the message to be consumed is a message to be cancelled, cancel the consumption of the message to be consumed, and if there is a queue-jumping message in the message to be consumed, consume the queue-jumping message in the message to be consumed.
[0160] Specifically, the queued messages in the first message queue can be queued or cancelled before being consumed.
[0161] If the message to be consumed is a message to be revoked, the consumption of the message to be revoked is directly canceled. That is, the message to be revoked is not sent to the target subscriber. Specifically, the purpose of canceling consumption can be achieved by discarding the message to be revoked. Revoking a message can also serve the purpose of correcting an error.
[0162] After the consumption of the pending revocation message is cancelled, it does not affect the normal consumption of the queued messages. When the pending revocation message is discarded, its queued messages can be executed. The queued messages of the pending revocation message will not be consumed until the pending revocation message becomes the message to be consumed, that is, it is queued to the head of the queue, and it is determined to be discarded before the pending revocation message is consumed. Although the pending revocation message is not consumed normally, its queue order determines the time when its queued messages are consumed.
[0163] S003: If the revocation status is invalid, it is determined that the message to be consumed does not belong to the message to be revoked, and step S900 is executed.
[0164] Specifically, if the message to be consumed does not belong to the message to be revoked, and it has a queue-jumping message, then after consuming the message to be consumed, the queue-jumping message is consumed.
[0165] In this application, the message mapping table of all consumed queued messages will be cleared.
[0166] In one embodiment, the message mapping table includes a message operation table.
[0167] Before step S600, the method further includes the following steps:
[0168] S004: Create a corresponding message operation table for each incoming message in the first message queue, where the message operation table stores the message ID and cancellation status of the corresponding incoming message.
[0169] S005: Get a revocation instruction, which carries the message ID of the message to be revoked.
[0170] S006: According to the message ID of the message to be revoked and the message operation table of the queued messages in the first message queue, search for the queued message with the same message ID as the message ID of the message to be revoked as the message to be revoked,
[0171] S007: Set the cancellation status in the message operation table of the message to be cancelled to be valid.
[0172] Specifically, each incoming message in the first message queue has a corresponding message operation table, which stores the message ID and revocation status of the corresponding incoming message. Initially, the revocation status is invalid, indicating that the incoming message does not belong to the message to be revoked.
[0173] When there is an incoming message that needs to be revoked, a revocation instruction will be received. The revocation instruction carries the message ID of the message to be revoked. According to the table lookup, it can be found which incoming message in the first message queue is the message to be revoked. Then the revocation status of the message to be revoked can be updated from invalid to valid. The valid status indicates that the incoming message is a message to be revoked. When the message to be revoked is at the head of the queue, it is not consumed normally, that is, it is not sent to the target subscriber, but is directly discarded.
[0174] In one embodiment, the queue-jumping message carries the message ID of the queue-jumped message. Step S020 specifically includes the following steps:
[0175] According to the message ID of the interrupted message carried by the interrupting message, a queue entry message having the same message ID as the interrupted message carried by the interrupting message is searched from the message management table of the first message queue as the interrupted message.
[0176] In a specific embodiment, step S900 specifically includes:
[0177] S910: decoding the message code of the message to be consumed in the message management table corresponding to the message to be consumed to obtain the content of the message to be consumed;
[0178] S920: Send the to-be-consumed message content to the target subscriber through the first message queue;
[0179] S930: Decode the sub-message code of the queue-jumping message in the message management table corresponding to the message to be consumed to obtain the content of the queue-jumping message to be consumed;
[0180] S940: Send the queue-jumping message content to be consumed to the target subscriber through the second message queue.
[0181] Specifically, the message encoding is obtained by encoding or encrypting the message content of the queued message, so when sending, it is necessary to decode the real message content and then send the real message content to the target subscriber.
[0182] Similarly, the sub-message encoding is obtained by encoding or encrypting the message content of the queue-jumping message. Therefore, when sending, it is necessary to decode the real message content and then send the real message content to the target subscriber.
[0183] In a specific embodiment, if there is no queue-jumping message among the messages to be consumed, the message to be consumed is consumed normally according to the normal process, and then the next message to be consumed in the first message queue is consumed according to the dequeue direction.
[0184] In this application, the queue-jumping message is either queued in the second message queue, without actually queue-jumping in the first message queue; or it is inserted at the end of the first message queue. Therefore, the queue-jumping message will not affect the consumption order or progress of any queue-entering message in the first message queue. However, after the queue-entering message with the queue-jumping message in the first message queue is consumed, its queue-jumping message will be automatically consumed afterwards. The consumption time of the queue-jumped message determines the consumption time of its queue-jumping message.
[0185] It should be understood that, unless otherwise specified herein, the execution of the various steps of the above message management method is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0186] This application realizes error correction and cancellation management of messages in the message queue. While not affecting the normal process of messages in the normal queue, the previous erroneous messages can be modified in time to ensure the stability of the system.
[0187] For example, in an application scenario: ResourcesType is the type of resource, ResourceID is the ID of the resource, and DataJson is the content that needs to be updated. There is a blockchain resource that has three states: normal, processing, and stopped. Its ResourceID is 1. Blockchain resource No. 1 is in a normal state, but due to an error in the underlying system processing, it mistakenly believes that resource No. 1 is in a stopped state, so a message to stop it is sent to the message queue. However, since the system will process multiple times in a short period of time, when the system processes it for the second time, it finds that the resource is in a normal state, so the record of the last message sent is found in the message operation table, and its isWithdrawed field is modified to true to cancel the sending of the message. At the same time, we can also find the wrong message in the message queue table and queue the correct message directly after it, so that the previous wrong message can be modified in time to ensure the stability of the system.
[0188] Figure 2 A mapping relationship diagram between messages and message management tables provided in an embodiment of the present application; Figure 2 In the outbound direction of a message queue, multiple incoming messages are queued from the head to the tail, and each incoming message has its own message management table.
[0189] refer to Figure 2 As shown in Table 1, the message management table includes the message ID (primary_key) and message code of each incoming message in the message queue, and each incoming message can only store up to three sub-message codes of queue-jumping messages (sub-message code No. 1, sub-message code No. 2, sub-message code No. 3). Each queue-jumping message has corresponding codes code_one, code_two, and code_three in the message management table.
[0190] Refer to Table 2, each queue entry message also has a corresponding message operation table, which includes the message ID (primary_key), message code, and queue insertion status (isInserted) and withdrawal status (isWithdrawed). Among them, the queue insertion status and withdrawal status both use false and true as values. False means invalid, indicating that it has not been queued or withdrawn. True means valid, indicating that it has been queued or withdrawn.
[0191] Of course, in a specific embodiment, the message management table and message operation table of each queue entry message can be combined into a message mapping table. The message mapping table includes a message ID field, a message code code field, queue-jumping message code_one, code_two, code_three fields, a queue-jumping status field and a revocation status field and their corresponding values.
[0192] Table 1: Message management table
[0193]
[0194] Table 2: Message operation table
[0195] id(primary_key) code isInserted isWithdrawed long string bool bool ID Message Encoding True / False True / False
[0196] Figure 3 A structural block diagram of a message management device provided in an embodiment of the present application; the device includes:
[0197] The first message acquisition module 600 is used to acquire the message ID of the message to be consumed in the first message queue according to the dequeue direction of the first message queue;
[0198] The first search module 700 is used to obtain a message mapping table corresponding to the message to be consumed according to the message ID of the message to be consumed;
[0199] The first judgment module 800 is used to judge whether there is a queue-jumping message among the messages to be consumed according to the message mapping table corresponding to the messages to be consumed;
[0200] The consumption module 900 is used to consume the message to be consumed and the queue-jumping message of the message to be consumed if there is a queue-jumping message among the messages to be consumed.
[0201] In one embodiment, the consumption module 900 is specifically used to consume the queue-jumping message of the message to be consumed after consuming the message to be consumed.
[0202] In one embodiment, the consumption module 900 specifically includes:
[0203] The first decoding module 910 is used to decode the message code of the message to be consumed in the message management table corresponding to the message to be consumed to obtain the content of the message to be consumed;
[0204] A first sending module 920 is used to first send the to-be-consumed message content to a target subscriber through a first message queue;
[0205] The second decoding module 930 is used to decode the sub-message code of the queue-jumping message in the message management table corresponding to the to-be-consumed message to obtain the content of the to-be-consumed queue-jumping message;
[0206] The second sending module 940 is used to send the queue-jumping message content to be consumed to the target subscriber through the second message queue.
[0207] In one embodiment, the message mapping table includes a message management table.
[0208] The message management device also includes:
[0209] The first construction module 010 is used to establish a corresponding message management table for each incoming message in the first message queue, wherein the message management table stores a message ID and a message code of the corresponding incoming message;
[0210] The second message acquisition module 020 is used to acquire the queue-jumping message and determine the queue-jumped message corresponding to the queue-jumping message in the first message queue;
[0211] The second judgment module 030 is used to judge whether the queue-intercepted message is at the end of the first message queue;
[0212] The encoding module 040 is used to encode the message content of the queue-jumping message to obtain a sub-message code if the queue-jumping message is not at the end of the first message queue;
[0213] The first storage module 050 is used to store the sub-message code of the queue-jumping message in the message management table corresponding to the queue-jumped message.
[0214] In one embodiment, the device includes: a second storage module 060, which is used to store the sub-message code of the queue-jumping message in the message management table corresponding to the queue-entering message located after the queue-jumped message.
[0215] In one embodiment, the first building block 010 specifically includes:
[0216] The first sub-message acquisition module 011 is used to respectively acquire the message ID and message content of each incoming message in the first message queue;
[0217] The first sub-encoding module 012 is used to encode the message content of each incoming message to obtain a corresponding message code;
[0218] The first sub-construction module 013 is used to respectively establish a message management table for each incoming message in the first message queue according to the message ID and the message code.
[0219] In one embodiment, the first storage module 050 specifically includes:
[0220] The first sub-judgment module 051 is used to determine whether the number of sub-message codes stored in the message management table corresponding to the queue-jumped message has reached the maximum allowed storage capacity;
[0221] The first sub-storage module 052 is used to store the sub-message codes of the queue-jumping message in a target position in the message management table corresponding to the queue-jumping message in sequence if the number of sub-message codes stored in the message management table corresponding to the queue-jumping message has not reached the maximum allowed storage capacity.
[0222] In one embodiment, the second storage module 060 specifically includes:
[0223] The second sub-judgment module 061 is used to obtain a candidate queue-jumped message in the first message queue that is located after the queue-jumped message and whose corresponding message management table has stored the number of sub-message codes that has not reached the maximum allowed storage capacity if the number of sub-message codes stored in the message management table corresponding to the queue-jumped message has reached the maximum allowed storage capacity;
[0224] The second sub-storage module 062 is used to store the sub-message codes of the queue-jumping message in a target position in the message management table corresponding to the candidate queue-jumping message in sequence.
[0225] In one embodiment, the apparatus further comprises:
[0226] The queue entry module 070 is used to add the queue-interrupted message to the first message queue after the queue-interrupted message if the queue-interrupted message is at the end of the first message queue and the first message queue is not full.
[0227] In one embodiment, the first judgment module 800 is specifically used to judge whether there is a queue-jumping message among the messages to be consumed according to the message management table corresponding to the messages to be consumed.
[0228] In one embodiment, the message mapping table also includes a message operation table. The first judgment module 800 specifically includes:
[0229] The queue-jumping status acquisition module 810 is used to obtain the queue-jumping status in the message operation table corresponding to the message to be consumed to determine whether there is a queue-jumping message among the messages to be consumed;
[0230] The first determination module 820 is configured to determine if there is a queue-jumping message among the messages to be consumed if the queue-jumping state is valid.
[0231] In one embodiment, the apparatus further comprises:
[0232] The second construction module 090 is used to establish a corresponding message operation table for each incoming message in the first message queue, and the message operation table stores the message ID and queue interruption status of the corresponding incoming message.
[0233] In one embodiment, the apparatus further comprises:
[0234] The first queue-jumping state updating module 0100 is used to set the queue-jumping state in the message operation table corresponding to the queue-jumping message to be valid.
[0235] The second queue-jumping status updating module 0200 is used to set the queue-jumping status in the message management table corresponding to the queue-entering message after the queue-jumping message to be valid.
[0236] In one embodiment, the apparatus further comprises:
[0237] The revocation status acquisition module 001 is used to obtain the revocation status in the message mapping table corresponding to the message to be consumed to determine whether the message to be consumed is a message to be revoked;
[0238] The second determination module 002 is used to determine that the message to be consumed is a message to be revoked if the revocation status is valid;
[0239] The cancellation module 003 is used to cancel the consumption of the pending consumption message.
[0240] In one embodiment, the message mapping table includes a message operation table.
[0241] The device also includes:
[0242] The third building module 004 is used to establish a corresponding message operation table for each incoming message in the first message queue, wherein the message operation table stores the message ID and the revocation status of the corresponding incoming message.
[0243] The revocation instruction acquisition module 005 is used to acquire the revocation instruction, which carries the message ID of the message to be revoked.
[0244] The second search module 006 is used to search for an incoming message with the same message ID as the message to be revoked as the message to be revoked according to the message ID of the message to be revoked and the message operation table of the incoming messages in the first message queue,
[0245] The revocation status updating module 007 is used to set the revocation status in the message operation table of the message to be revoked to be valid.
[0246] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the following steps are implemented: obtaining a message ID of a message to be consumed in a first message queue according to a dequeue direction of the first message queue; obtaining a message mapping table corresponding to the message to be consumed according to the message ID of the message to be consumed; determining whether there is a queue-jumping message among the messages to be consumed according to the message mapping table corresponding to the messages to be consumed; and consuming the messages to be consumed and the queue-jumping messages among the messages to be consumed if there is a queue-jumping message among the messages to be consumed.
[0247] When the processor executes the computer program, the processor also implements the steps of any one of the above message management methods.
[0248] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented: obtaining the message ID of the message to be consumed in the first message queue according to the dequeue direction of the first message queue; obtaining the message mapping table corresponding to the message to be consumed according to the message ID of the message to be consumed; judging whether there is a queue-jumping message among the messages to be consumed according to the message mapping table corresponding to the messages to be consumed; if there is a queue-jumping message among the messages to be consumed, consuming the messages to be consumed and the queue-jumping messages of the messages to be consumed.
[0249] When the computer program is executed by a processor, the steps of any one of the above message management methods are also implemented.
[0250] It should be noted that, in this article, relational terms such as "first" and "second" 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 existence of other identical elements in the process, method, article or device including the elements.
[0251] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A message management method, characterized in that: The method comprises: Obtain the message ID of the message to be consumed in the first message queue according to the dequeue direction of the first message queue; Obtain a message mapping table corresponding to the message to be consumed according to the message ID of the message to be consumed; the message mapping table also includes a message operation table; Determine whether there is a queue-jumping message among the messages to be consumed according to the message mapping table corresponding to the messages to be consumed; If there is a queue-jumping message among the messages to be consumed, consuming the messages to be consumed and the queue-jumping messages among the messages to be consumed; Wherein, judging whether there is a queue-jumping message among the messages to be consumed according to the message mapping table corresponding to the messages to be consumed includes: Obtaining the queue-jumping status in the message operation table corresponding to the message to be consumed to determine whether there is a queue-jumping message among the messages to be consumed; If the queue-jumping status is valid, it is determined that there is a queue-jumping message among the messages to be consumed.
2. The method according to claim 1, characterized in that The message mapping table includes a message management table; Before obtaining the message ID of the message to be consumed in the first message queue according to the dequeue direction of the first message queue, the method further includes: A corresponding message management table is established for each incoming message in the first message queue, wherein the message management table stores a message ID and a message code of the corresponding incoming message; Obtain a queue-jumping message, and determine a queue-jumped message corresponding to the queue-jumping message in the first message queue; Determine whether the queue-intercepted message is at the end of the first message queue; If the queue-intercepted message is not at the end of the first message queue, encoding the message content of the queue-intercepted message to obtain a sub-message code; The sub-message code of the queue-jumping message is stored in the message management table corresponding to the queue-jumped message, or the sub-message code of the queue-jumping message is stored in the message management table corresponding to the queue-entering message located after the queue-jumped message; If the interrupted message is at the end of the first message queue and the first message queue is not full, the interrupted message is added to the first message queue after the interrupted message.
3. The method according to claim 2, characterized in that The step of establishing a corresponding message management table for each incoming message in the first message queue comprises: Get the message ID and message content of each incoming message in the first message queue respectively; Encode the message content of each incoming message to obtain the corresponding message code; A message management table is established for each incoming message in the first message queue according to the message ID and the message code.
4. The method according to claim 2, characterized in that: The step of encoding the sub-message of the queue-jumping message and storing it in the message management table corresponding to the queue-jumped message includes: Determine whether the number of sub-message codes stored in the message management table corresponding to the queue-jumped message has reached the maximum allowed storage capacity, If the number of sub-message codes stored in the message management table corresponding to the queue-jumped message does not reach the maximum allowed storage capacity, the sub-message codes of the queue-jumped message are stored in a target position in the message management table corresponding to the queue-jumped message in sequence; The step of storing the sub-message code of the queue-jumping message in a message management table corresponding to the queue-entering message after the queue-jumped message comprises: If the number of sub-message codes stored in the message management table corresponding to the interrupted message has reached the maximum allowed storage capacity, then obtain a standby interrupted message in the first message queue that is located after the interrupted message and whose number of sub-message codes stored in the corresponding message management table has not reached the maximum allowed storage capacity, The sub-message codes of the queue-jumping message are stored in a target position in the message management table corresponding to the candidate queue-jumping message in sequence.
5. The method according to claim 1, characterized in that Before obtaining the message ID of the message to be consumed in the first message queue according to the dequeue direction of the first message queue, the method further includes: A corresponding message operation table is established for each incoming message in the first message queue. The message operation table stores the message ID and queue-jumping status of the corresponding queue-entering message. After storing the sub-message code of the queue-jumping message in the message management table corresponding to the queue-jumped message, or storing the sub-message code of the queue-jumping message in the message management table corresponding to the queue-entering message located after the queue-jumped message, the method further includes: The queue-interrupting status in the message operation table corresponding to the queue-interrupted message is set to be valid, or the queue-interrupting status in the message management table corresponding to the queue-entering message after the queue-interrupted message is set to be valid.
6. The method according to claim 1, characterized in that If there is a queue-jumping message among the messages to be consumed, before consuming the messages to be consumed and the queue-jumping messages of the messages to be consumed, the method further includes: Obtain the revocation status in the message mapping table corresponding to the message to be consumed to determine whether the message to be consumed is a message to be revoked, If the revocation status is valid, the message to be consumed is determined to be a message to be revoked, and the consumption of the message to be consumed is canceled. If there is a queue-jumping message among the messages to be consumed, consuming the queue-jumping message among the messages to be consumed; If there is a queue-jumping message among the messages to be consumed, consuming the messages to be consumed and the queue-jumping messages of the messages to be consumed includes: If the revocation status is invalid, it is determined that the message to be consumed is not a message to be revoked, and if there is a queue-jumping message among the messages to be consumed, the message to be consumed and the queue-jumping message of the message to be consumed are consumed.
7. The method according to claim 6, characterized in that The message mapping table includes a message operation table; Before obtaining the message ID of the message to be consumed in the first message queue according to the dequeue direction of the first message queue, the method further includes: A corresponding message operation table is established for each incoming message in the first message queue. The message operation table stores the message ID and cancellation status of the corresponding queued message. Get a revocation instruction, the revocation instruction carries the message ID of the message to be revoked, According to the message ID of the message to be revoked and the message operation table of the queued messages in the first message queue, searching for the queued message with the same message ID as the message ID of the message to be revoked as the message to be revoked, The revocation status in the message operation table of the message to be revoked is set to valid.
8. The method according to claim 2, characterized in that: Consuming the message to be consumed and the queue-jumping message of the message to be consumed includes: Decoding the message code of the message to be consumed in the message management table corresponding to the message to be consumed to obtain the content of the message to be consumed; Sending the to-be-consumed message content to a target subscriber through the first message queue; Decoding the sub-message code of the queue-jumping message in the message management table corresponding to the message to be consumed to obtain the content of the queue-jumping message to be consumed; The queue-jumping message content to be consumed is sent to the target subscriber through the second message queue.
9. A message management device, characterized in that: The device comprises: A first message acquisition module, used to acquire the message ID of the message to be consumed in the first message queue according to the dequeue direction of the first message queue; A first search module is used to obtain a message mapping table corresponding to the message to be consumed according to the message ID of the message to be consumed; the message mapping table also includes a message operation table; A first judgment module is used to judge whether there is a queue-jumping message in the message to be consumed according to the message mapping table corresponding to the message to be consumed; A consumption module, configured to consume the message to be consumed and the queue-jumping message of the message to be consumed if there is a queue-jumping message among the message to be consumed; The first judgment module specifically includes: The queue-jumping status acquisition module is used to obtain the queue-jumping status in the message operation table corresponding to the message to be consumed to determine whether there is a queue-jumping message among the messages to be consumed; The first determination module is used to determine whether there is a queue-jumping message among the messages to be consumed if the queue-jumping state is valid.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the processor is caused to perform the steps of the method according to any one of claims 1 to 8.
11. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of the method according to any one of claims 1 to 8 are performed.
Citation Information
Patent Citations
Consumption method and device based on database message queue, server and medium
CN108536544A
Message processing method and device and computer equipment
CN110955532A