Message processing method, apparatus, device, and storage medium
By using tail insertion and caching mechanisms to handle failed message consumption, the blocking problem caused by failed message consumption in the message queue is solved, and the sequential consumption of messages and the normal execution of process tasks are realized.
Patent Information
- Application Number
- CN202111631962.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-28
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2041-12-28
AI Technical Summary
In existing technologies, messages that fail to be consumed in the message queue cannot be consumed normally, leading to message queue blockage and the inability of process tasks to execute normally.
The tail insertion method is used to store failed messages to a message queue. Through caching and identification information management, it is ensured that messages are re-consumed in order.
This avoids discarding failed messages, ensures the normal execution of process tasks, and achieves closed-loop processing of the message queue.
Smart Images

Figure CN114327948B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a message processing method, apparatus, device, and storage medium. Background Technology
[0002] Message queues (MQ) are a type of "first-in, first-out" (FIFO) data structure in basic data structures. Specifically, they are a technique for exchanging information between distributed applications, used to achieve system decoupling and improve system response time.
[0003] In a message queue, there are producers and consumers. A producer can be a client that sends its messages to the server. The server then stores the received messages in the message queue in chronological order of receipt. A consumer can be another client that pulls messages from the server's message queue for consumption. Because message queues follow a first-in, first-out (FIFO) rule, if the consumption of one message fails, it will block the consumption of subsequent messages in the queue.
[0004] To address the aforementioned issues, the current approach involves processing failed messages multiple times. If a message fails to be processed within a preset time, it is discarded, which in turn prevents the message from being processed properly. Summary of the Invention
[0005] This application provides a message processing method, apparatus, device, and storage medium to solve the problem that messages that fail to be consumed in the message queue are currently discarded, causing the discarded messages to be unable to be consumed normally.
[0006] In a first aspect, embodiments of this application provide a message processing method applied to a server, wherein the server is provided with a first message queue, and the message processing method includes: sending a first message in the first message queue to a first client; if a consumption failure message sent by the first client for the first message is received, then caching the first message; and storing the cached first message in the first message queue using a tail insertion method.
[0007] In one possible implementation, sending a first message from a first message queue to a first client includes: obtaining the identification information of the first message, wherein multiple messages representing the same task flow in the first message queue have the same identification information; if the identification information is different from a pre-stored target identifier, then sending the first message to the first client, wherein the target identifier is the identification information of a second message that failed to be consumed.
[0008] In one possible implementation, sending the first message from the first message queue to the first client further includes: if the identification information is the same as the target identifier, then obtaining the content data of the first message; if the content data is the same as the pre-stored target content corresponding to the target identifier, then sending the first message to the first client, wherein the target content is the content data of the second message.
[0009] In one possible implementation, the message processing method further includes: caching the first message if the content data differs from the target content.
[0010] In one possible implementation, if the content data is the same as the pre-stored target content corresponding to the target identifier, after sending the first message to the first client, the method further includes: if a consumption success message sent by the first client in response to the first message is received, then the target identifier and target content are cleared.
[0011] In one possible implementation, the server further includes a second message queue for caching the first message, including storing the first message in the second message queue.
[0012] In one possible implementation, the message processing method further includes: if a consumption failure message sent by a first client for a first message is received, storing the identification information and content data of the first message.
[0013] In one possible implementation, the first message in the cache is stored in the first message queue using a tail insertion method, including: pulling the first message from the second message queue through a consumer module; and storing the first message in the first message queue through a tail insertion method through a consumer module, wherein the consumer module has the function of a consumer.
[0014] In one possible implementation, after caching the first message, the method further includes: marking the first message as successfully consumed in the first message queue, so that the server sends the third message to the corresponding second client for consumption, wherein the third message is a message in the first message queue that is ordered after the first message.
[0015] Secondly, embodiments of this application provide a message processing apparatus applied to a server, wherein the server is provided with a first message queue, and the message processing apparatus includes:
[0016] The sending module is used to send the first message in the first message queue to the first client;
[0017] The caching module is used to cache the first message if a consumption failure message is received from the first client for the first message.
[0018] The storage module is used to store the first message in the cache into the first message queue using a tail insertion method.
[0019] In one possible implementation, the sending module is specifically used to: obtain the identification information of a first message, wherein multiple messages in the first message queue representing the same task flow have the same identification information; if the identification information is different from the pre-stored target identifier, then the first message is sent to the first client, and the target identifier is the identification information of the second message that failed to be consumed.
[0020] In one possible implementation, the sending module is further configured to: if the identification information is the same as the target identifier, then obtain the content data of the first message; if the content data is the same as the pre-stored target content corresponding to the target identifier, then send the first message to the first client, wherein the target content is the content data of the second message.
[0021] In one possible implementation, the sending module is further configured to: cache the first message if the content data differs from the target content.
[0022] In one possible implementation, if the content data is the same as the pre-stored target content corresponding to the target identifier, after sending the first message to the first client, the message processing device further includes:
[0023] The clearing module is used to clear the target identifier and target content if a consumption success message sent by the first client for the first message is received.
[0024] In one possible implementation, the server further includes a second message queue, and the caching module is specifically used to store the first message in the second message queue.
[0025] In one possible implementation, the message processing apparatus further includes:
[0026] The first message storage module is used to store the identification information and content data of the first message if it receives a consumption failure message sent by the first client for the first message.
[0027] In one possible implementation, the storage module is specifically used to: pull the first message from the second message queue through the consumer module; and store the first message into the first message queue using a tail insertion method through the consumer module, wherein the consumer module has the function of a consumer.
[0028] In one possible implementation, after caching the first message, the message processing device further includes:
[0029] The marking module is used to mark the first message in the first message queue as successfully consumed, so that the server can send the third message to the corresponding second client for consumption. The third message is the message in the first message queue that is ordered after the first message.
[0030] Thirdly, embodiments of this application provide an electronic device, including a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the method as described in any of the first aspects.
[0031] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when run on an electronic device, causes the electronic device to perform the method as described in any of the first aspects.
[0032] Fifthly, embodiments of this application provide a computer program product, including a computer program that, when run on an electronic device, causes the electronic device to perform the method as described in any of the first aspects.
[0033] The message processing method, apparatus, device, and storage medium provided in this application are applied to a server. The server has a first message queue. The message processing method includes: sending a first message from the first message queue to a first client; if a consumption failure message is received from the first client regarding the first message, then caching the first message; and storing the cached first message into the first message queue using a tail insertion method. By storing the first message that failed to be consumed in the first message queue using a tail insertion method, this application can prevent the first message that failed to be consumed from being discarded and thus unable to be consumed normally, thereby affecting the normal execution of the process task in which the first message is located.
[0034] These and other aspects of this application will become more apparent in the description of the following embodiments(s). Attached Figure Description
[0035] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0036] Figure 1 A schematic diagram illustrating the application scenario of the message processing method provided in this application;
[0037] Figure 2 A flowchart illustrating a message processing method provided in an embodiment of this application;
[0038] Figure 3 A schematic diagram of a server provided in an embodiment of this application. Figure 1 ;
[0039] Figure 4 A flowchart illustrating a message processing method provided in another embodiment of this application;
[0040] Figure 5A schematic diagram of a server provided for another embodiment of this application. Figure 2 ;
[0041] Figure 6 This is a schematic diagram of the structure of a message processing apparatus provided in an embodiment of this application;
[0042] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0043] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0044] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0045] Normally, messages in a message queue follow a first-in, first-out (FIFO) principle. Only after the message at the head of the queue is successfully consumed or discarded can subsequent messages be consumed. If the consumption of the message at the head of the queue fails, it will prevent the normal consumption of subsequent messages. If the message at the head of the queue is discarded after a consumption failure, it will affect the normal consumption of the discarded message.
[0046] To address the aforementioned issues, this application provides a message processing method, apparatus, device, and storage medium. By storing the first message that failed to be consumed in the first message queue into the first message queue using the tail insertion method, the first message that failed to be consumed can be avoided from being discarded and thus unable to be consumed normally, thereby affecting the normal execution of the process task in which the first message is located.
[0047] For example, Figure 1 A schematic diagram illustrating an application scenario for the message processing method provided in this application. For example... Figure 1 As shown, this application scenario can include: at least one producer client ( Figure 1 The client 11 and client 12 shown), server 13 with message queue 131, and consumer client (shown) Figure 1(Clients 14, 15, and 16 are shown). Producer client 11 produces messages a1, a2, and a3, and producer client 12 produces messages b1, b2, and b3. Messages from each producer client are stored sequentially in message queue 131. Messages a1, a2, and a3 represent a complete process, and messages b1, b2, and b3 represent another complete process. Only when all messages corresponding to a complete process are successfully consumed in sequence can the task corresponding to that complete process be completed. For example, after message a1 is successfully consumed by consumer client 14, then message a2 is successfully consumed by consumer client 15, and then message a3 is successfully consumed by consumer client 16, the task corresponding to messages a1, a2, and a3 is completed.
[0048] For example, in the pharmaceutical requisition process, pharmacy A's producer client 11 sends requisition order A to server 13. Server 13 splits requisition order A into messages a1, a2, and a3, stores them in message queue 131, and then sends message a1 to the purchasing department's consumer client 14. After consumer client 14 approves the message (i.e., message a1 is successfully consumed), it sends a confirmation message to server 13 (consumption successful). Server 13 then sends message a2 to headquarters' consumer client 15. After consumer client 15 approves the message (i.e., message a2 is successfully consumed), it sends a confirmation message to server 13 (consumption successful). Server 13 then sends message a3 to the supplier's consumer client 16 for stock preparation. Upon receiving message a3, consumer client 16 returns a confirmation message that message a3 was successfully consumed to server 13. Server 13 can then use the same process to handle subsequent messages.
[0049] It should be noted that the appendix Figure 1 This is merely a schematic diagram illustrating one application scenario provided by an embodiment of this application. This embodiment of the application does not necessarily represent an application scenario. Figure 1 The included equipment is not limited, nor is it restricted. Figure 1 The location relationships between the devices are defined. In addition, server 13 can be a standalone server or a service cluster, etc.
[0050] The technical solution of this application will now be described in detail through specific embodiments. It should be noted that the following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments.
[0051] Figure 2This is a flowchart illustrating a message processing method provided in one embodiment of this application. This application provides a message processing method applied to a server, which has a first message queue and a second message queue. The following description uses the server as the execution subject.
[0052] like Figure 2 As shown, the message processing method includes the following steps:
[0053] S201, send the first message in the first message queue to the first client.
[0054] In practical applications, the first message queue is an MQ (Message Queue) system, a first-in, first-out (FIFO) container for storing messages. Messages are enqueued from the tail of the queue and dequeued from the head. The first client is the consumer of the first message. The first message is the data to be transmitted, which can be a simple text string or a custom, complex format.
[0055] In this process, the server sends the first message at the head of the first message queue to the corresponding first client, following the first-in-first-out principle of the first message queue.
[0056] Accordingly, the first message queue allows multiple producer clients to send messages to it. Furthermore, the first message queue can also correspond to multiple consumer clients, each consuming messages within it. The principle followed by the first message queue is that once a message is successfully consumed by a consumer client, that successfully consumed message is deleted from the first message queue.
[0057] In addition, before the server sends the first message in the first message queue to the first client, the server will receive a request for the first message from the first client.
[0058] S202, if a consumption failure message is received from the first client for the first message, then the first message is cached.
[0059] Specifically, after the server sends the first message to the first client, if the first client fails to consume the first message, it will return a response to the server, which is a message consumption failure message. Optionally, this response can be caught using Java's try-catch block.
[0060] Specifically, caching the first message could mean caching it in storage or another container. No specific limitation is specified here.
[0061] For example, refer to Figure 3If server 30 is configured with a first message queue 31 and a second message queue 32, then after the first message a1 fails to be consumed, the first message a1 can be cached in the second message queue 32.
[0062] In this embodiment of the application, a threshold number can be set. If the number of times the consumption failure information sent by the first client for the first message is less than the threshold number, the first message will continue to be sent to the first client. If the number of times the consumption failure information sent by the first client for the first message is greater than or equal to the threshold number, the first message will be cached.
[0063] S203, store the first message in the cache into the first message queue using tail insertion.
[0064] Specifically, refer to Figure 3 The first message a1 is stored at the end of the first message queue 31. When it is the next time to process the first message a1, the first message a1 is sent to the first client.
[0065] It is understood that the embodiments of this application can achieve closed-loop processing, and there will be no problem of messages in the first message queue being discarded, which would prevent normal consumption.
[0066] The message processing method, apparatus, device, and storage medium provided in this application are applied to a server. The server has a first message queue. The message processing method includes: sending a first message from the first message queue to a first client; if a consumption failure message is received from the first client regarding the first message, then caching the first message; and storing the cached first message into the first message queue using a tail insertion method. By storing the first message that failed to be consumed in the first message queue using a tail insertion method, this application can prevent the first message that failed to be consumed from being discarded and thus unable to be consumed normally, thereby affecting the normal execution of the process task in which the first message is located.
[0067] Reference Figure 4 This diagram illustrates a flowchart of another message processing method provided in an embodiment of this application. The message processing method specifically includes the following steps:
[0068] S401. Obtain the identification information of the first message.
[0069] In the first message queue, multiple messages representing the same task process have the same identification information.
[0070] Specifically, each message in the first message queue has an identifier (order ID). The same identifier represents the same task flow. For example, refer to... Figure 1 ,exist Figure 1If messages a1, a2, and a3 follow the same task flow, then the identification information for messages a1, a2, and a3 is identical.
[0071] S402. Determine whether the identification information is the same as the pre-stored target identification.
[0072] The target identifier is the identification information of the second message that failed to consume. If the identification information is the same as the target identifier, then execute step S403. If the identification information is different from the pre-stored target identifier, then execute step S405.
[0073] In actual use, the target identifier and target content of the second message that failed to be consumed are pre-stored in the storage (Redis).
[0074] In this application, it is necessary to first determine whether the identifier information of the first message is the same as the target identifier of the second message. If they are the same, it is determined that the first message and the second message belong to the same task flow that needs to be executed sequentially, or they are the same message.
[0075] If they are different, it is determined that the first message and the second message do not belong to the same task process, and the first message has also failed to be consumed before, so it can be directly sent to the first client for consumption.
[0076] Furthermore, if there is no pre-stored target identifier, the first information can be directly sent to the first client.
[0077] S403, retrieve the content data of the first message.
[0078] If the identification information and the target identification are the same, it is first determined that the first message and the second message do not belong to the same task process. Then, the content data of the first message needs to be obtained to determine whether the first message and the second message are the same message.
[0079] S404, determine whether the content data and the target identifier correspond to the same pre-stored target content.
[0080] The target content is the content data of the second message. If the content data of the first message is the same as the pre-stored target content corresponding to the target identifier, execute S405. If the content data is different from the target content, execute S407.
[0081] Specifically, if the target content and the content data of the second message are the same, then it is determined that the first message and the second message are the same message. The process then involves the second message, after failing to be consumed, being appended to the end of the first message queue and consumed again. Alternatively, the first message can be directly sent to the first client for consumption.
[0082] If the content of the first message differs from the pre-stored target content corresponding to the target identifier, then it is determined that the first message and the second message belong to the same task flow but are not the same message. Since the second message consumption failed, and the first and second messages belong to the same sequential task flow, the first message can only be consumed after the second message is successfully consumed. Therefore, the first message is directly cached in the second message queue.
[0083] S405 sends the first message to the first client.
[0084] S406, determine whether the message sent by the first client in response to the first message is a message failure message.
[0085] If the received message from the first client is a consumption failure message for the first message, then execute S407. If the received message from the first client is not a consumption failure message, then it is a consumption success message, and execute S412.
[0086] S407, store the first message in the second message queue.
[0087] The second message queue has the same structure as the first message queue and follows a first-in, first-out (FIFO) rule. Therefore, in the second message queue, messages that fail to be consumed first are placed before those that fail to be consumed later.
[0088] In addition, the second message queue serves as a relay for message compensation in the first message queue.
[0089] S408, mark the first message in the first message queue as successfully consumed.
[0090] Specifically, the first message is marked as successfully consumed in the first message queue so that the server can send the third message to the corresponding second client for consumption. The third message is the message in the first message queue that is ordered after the first message.
[0091] Specifically, marking the first message as successfully consumed can instruct that subsequent messages continue to be processed.
[0092] S409 stores the identification information and content data of the first message.
[0093] In this application, if the memory does not store the same identification information as the first message, then the identification information and content data of the first message are stored. If the memory already stores the same identification information as the first message, then it is not necessary to store the identification information and content data of the first message; it is only necessary to send the first message to the second message queue.
[0094] In the specific implementation process, if the memory stores the identification information and content data of the first message, it can be executed synchronously with S407 or sequentially, and the execution order is not limited.
[0095] S410 pulls the first message from the second message queue through the consumer module.
[0096] In practical applications, the consumer module functions as a consumer. It is a virtual module within the server that simulates a consumer, used to pull the first message from the second message queue.
[0097] S411 stores the first message into the first message queue using a tail insertion method through the consumer module.
[0098] In this embodiment, the consumer module also has the function of a producer, which can store the first message pulled into the first message queue using the tail insertion method.
[0099] S412, Clear target identifier and target content.
[0100] Specifically, after the first message is successfully sent, if the identification information and content data of the first message are pre-stored in the memory, the identification information and content data of the first message stored in the memory are cleared so that other messages belonging to the same task process as the first message can be sent normally.
[0101] Reference Figure 5 This diagram illustrates a structural block diagram of a server 50 according to an embodiment of this application. The server 50 includes a first message queue 51, a memory 52, a second message queue 53, and a consumer module 54. An embodiment of this application is illustrated based on this server 50. Details are as follows:
[0102] First, if it is determined that no target identifier or target content is stored in memory 52, then message a1 from the first message queue 51 is retrieved and sent to the first client. If message a1 from the first client indicates successful consumption, then message a2 from the first message queue 51 is retrieved and sent to the corresponding client. If message a1 from the first client indicates message failure, then the identifier information 'a' of message a1 is stored in memory 52 as the target identifier and the content data '1' is stored as the target data.
[0103] Simultaneously, message a1 is stored in the second message queue 53, and message a1 in the first message queue 51 is marked as successfully consumed. Then, message a1 is pulled by the consumer module 54, and the pulled message a1 is stored at the tail of the first message queue 51 by the consumer module using the tail insertion method.
[0104] Next, the identifier information 'a' of message a2 in the first message queue 51 is obtained. It is then determined that identifier information 'a' is the same as the target identifier 'a' stored in memory 52. The content data 2 of message a2 is then obtained. If the content data 2 of message a2 is determined to be different from the content data 1 corresponding to the target identifier 'a', message a2 is stored in the second message queue 53 using tail insertion. The consumption of message a2 in the first message queue 51 is marked as successful. Then, message a2 is pulled by the consumer module 54 and stored at the tail of the first message queue 52 using tail insertion. Thus, message a2 is still ordered after message a1 in the first message queue.
[0105] If message a3 is processed using the same method as message a2, then message a3 will eventually be inserted at the end of the first message queue 51, following message a2.
[0106] Next, message b1 is processed. First, the identifier information b of message b1 is obtained. If this identifier information b is different from the target identifier a stored in the memory, message b1 is sent to the corresponding client. If a consumption success message is received from the client, the identifier information b of b2 is obtained. If this identifier information b is different from the target identifier a stored in the memory, message b2 is sent to the corresponding client. If a consumption failure message is received from the client, the identifier information b of message b2 is used as another target identifier, and the content data 2 of message b2 is stored as the target content corresponding to the other target identifier. In memory 52, at this time, memory 52 stores two target identifiers (a and b) and the target content corresponding to each target identifier. Then, message b2 is appended to the tail of the first message queue 51 in the same way.
[0107] The same method is used to process messages after message b2 until message a1 is processed. Then, the identification information a of message a1 is obtained. If the identification information a is found to be the same as a target identifier a stored in memory 52, the content data 1 of message a1 is obtained. If the content data is found to be the same as the target content 1 corresponding to the target identifier a, then message a1 is sent to the first client.
[0108] In summary, the embodiments of this application enable closed-loop processing of each message in the first message queue. Furthermore, when the first message queue contains multiple messages belonging to the same task flow and requiring sequential consumption, it ensures that each message is successfully consumed in a preset order, thereby completing the corresponding task flow. In addition, the embodiments of this application also prevent blocking of the first message queue and the discarding of first messages.
[0109] The following are embodiments of the apparatus described in this application, which can be used to execute the embodiments of the method described in this application. For details not disclosed in the apparatus embodiments of this application, please refer to the embodiments of the method described in this application.
[0110] Figure 6 This is a schematic diagram of a message processing apparatus provided according to an embodiment of this application. This application provides a message processing apparatus that can be integrated into electronic devices such as servers. Figure 6 As shown, the message processing device 60 includes: a sending module 61, a buffer module 62, and a storage module 63. Wherein:
[0111] Sending module 61 is used to send the first message in the first message queue to the first client;
[0112] The caching module 62 is used to cache the first message if it receives a consumption failure message sent by the first client for the first message;
[0113] Storage module 63 is used to store the first message in the cache into the first message queue using a tail insertion method.
[0114] Furthermore, the sending module 61 is specifically used to: obtain the identification information of the first message, wherein multiple messages in the first message queue representing the same task process have the same identification information; if the identification information is different from the pre-stored target identifier, the first message is sent to the first client, and the target identifier is the identification information of the second message that failed to be consumed.
[0115] Optionally, the sending module 61 is further configured to: if the identification information is the same as the target identifier, then obtain the content data of the first message; if the content data is the same as the target content corresponding to the target identifier, then send the first message to the first client, wherein the target content is the content data of the second message.
[0116] Optionally, the sending module 61 is also configured to: cache the first message if the content data is different from the target content.
[0117] Optionally, if the content data is the same as the pre-stored target content corresponding to the target identifier, after sending the first message to the first client, the message processing device 60 further includes:
[0118] A clearing module (not shown) is used to clear the target identifier and target content if a consumption success message sent by the first client for the first message is received.
[0119] Furthermore, the server also includes a second message queue, and the caching module 62 is specifically used to store the first message in the second message queue.
[0120] Optionally, the message processing device 60 further includes:
[0121] The first message storage module (not shown) is used to store the identification information and content data of the first message if a consumption failure message is received from the first client for the first message.
[0122] Furthermore, the storage module 63 is specifically used for: pulling the first message from the second message queue through the consumer module; and storing the first message into the first message queue using a tail insertion method through the consumer module, wherein the consumer module has the function of a consumer.
[0123] Optionally, after caching the first message, the message processing device 60 further includes:
[0124] A marking module (not shown) is used to mark the first message in the first message queue as successfully consumed, so that the server can send the third message to the corresponding second client for consumption. The third message is the message in the first message queue that is ordered after the first message.
[0125] The apparatus provided in this application embodiment can be used to perform... Figure 2 and Figure 4 The methods in the illustrated embodiments are similar in principle and technical effect, and will not be described again here.
[0126] It should be noted that the division of the various modules in the above device is merely a logical functional division. In actual implementation, they can be fully or partially integrated into a single physical entity, or they can be physically separated. Furthermore, these modules can be implemented entirely in software via processing element calls; they can be fully implemented in hardware; or some modules can be implemented by processing element calls to software, while others are implemented in hardware. For example, a processing module can be a separate processing element, or it can be integrated into a chip within the device. Alternatively, it can be stored as program code in the device's memory, and its functions can be called and executed by a processing element. The implementation of other modules is similar. Moreover, these modules can be fully or partially integrated together, or they can be implemented independently. The processing element here can be an integrated circuit with signal processing capabilities. During implementation, each step of the above method or each of the above modules can be completed through integrated logic circuits in the hardware of the processor element or through software instructions.
[0127] For example, these modules can be one or more integrated circuits configured to implement the above methods, such as one or more Application Specific Integrated Circuits (ASICs), one or more Digital Signal Processors (DSPs), or one or more Field Programmable Gate Arrays (FPGAs). As another example, when a module is implemented using processing element scheduler code, the processing element can be a general-purpose processor, such as a Central Processing Unit (CPU) or other processor capable of calling program code. Furthermore, these modules can be integrated together as a System-On-a-Chip (SOC).
[0128] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. A computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, all or part of the flow or function according to the embodiments of this application is generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., a solid-state disk (SSD)).
[0129] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 7As shown, the electronic device may include: a processor 71, a memory 72, a communication interface 73, and a system bus 74. The memory 72 and the communication interface 73 are connected to the processor 71 via the system bus 74 and communicate with each other. The memory 72 is used to store instructions, the communication interface 73 is used to communicate with other devices, and the processor 71 is used to call the instructions in the memory to execute the scheme as described in the above message processing method embodiment.
[0130] Should Figure 7 The system bus 74 mentioned can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This system bus 74 can be divided into address bus, data bus, control bus, etc. For ease of representation, it is represented by only one thick line in the diagram, but this does not indicate that there is only one bus or one type of bus.
[0131] Communication interface 73 is used to enable communication between the database access device and other devices (such as clients, read-write databases, and read-only databases).
[0132] The memory 72 may include random access memory (RAM) and may also include non-volatile memory, such as at least one disk storage device.
[0133] Processor 71 can be a general-purpose processor, including a central processing unit, a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0134] This application also provides a computer-readable storage medium storing a computer program that, when run on an electronic device, causes the electronic device to execute the message processing method as described in any of the above method embodiments.
[0135] This application also provides a chip for executing instructions, which is used to execute the message processing method of any of the above method embodiments.
[0136] This application also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. At least one processor can read the computer program from the computer-readable storage medium. When the at least one processor executes the computer program, it can implement the message processing method as described in any of the above method embodiments.
[0137] In this application, "at least one" means one or more, and "more than one" means two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone, where A and B can be singular or plural. The character " / " generally indicates an "or" relationship between the preceding and following related objects; in formulas, the character " / " indicates a "division" relationship. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c can represent: a, b, c, ab, ac, bc, or abc, where a, b, and c can be single or multiple.
[0138] It is understood that the various numerical designations used in the embodiments of this application are merely for descriptive convenience and are not intended to limit the scope of the embodiments of this application. In the embodiments of this application, the order of the above-mentioned process numbers does not imply the order of execution; the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0139] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. A message processing method, characterized in that, Applied to a server, wherein a first message queue is provided in the server, and the message processing method includes: Send the first message from the first message queue to the first client; If a consumption failure message is received from the first client for the first message, then the first message is cached; The first message in the cache is stored in the first message queue using a tail insertion method; Sending the first message from the first message queue to the first client includes: Obtain the identification information of the first message, wherein multiple messages in the first message queue that represent the same task process have the same identification information; If the identification information is different from the pre-stored target identification, the first message is sent to the first client, where the target identification is the identification information of the second message that failed to be consumed; If the identification information is the same as the target identifier, then the content data of the first message is obtained; If the content data is different from the pre-stored target content corresponding to the target identifier, then the first message is cached.
2. The message processing method according to claim 1, characterized in that, Sending the first message from the first message queue to the first client further includes: If the content data is the same as the pre-stored target content corresponding to the target identifier, then the first message is sent to the first client, and the target content is the content data of the second message.
3. The message processing method according to claim 2, characterized in that, If the content data is the same as the pre-stored target content corresponding to the target identifier, then after sending the first message to the first client, the method further includes: If a consumption success message is received from the first client in response to the first message, then the target identifier and the target content are cleared.
4. The message processing method according to any one of claims 1 to 3, characterized in that, The server also includes a second message queue, and the caching of the first message includes: Store the first message in the second message queue.
5. The message processing method according to claim 4, characterized in that, Also includes: If a consumption failure message is received from the first client for the first message, the identifier information and content data of the first message are stored.
6. The message processing method according to claim 4, characterized in that, The step of storing the first message in the cache into the first message queue using a tail insertion method includes: The consumer module pulls the first message from the second message queue; The consumer module stores the first message into the first message queue using a tail insertion method. The consumer module has the function of a consumer.
7. The message processing method according to any one of claims 1 to 3, characterized in that, After caching the first message, the method further includes: The server marks the first message as successfully consumed in the first message queue so that it can send the third message to the corresponding second client for consumption. The third message is the message in the first message queue that is ordered after the first message.
8. A message processing device, characterized in that, Applied to a server, wherein the server is provided with a first message queue, the message processing device includes: The sending module is used to send the first message in the first message queue to the first client; The caching module is used to cache the first message if it receives a consumption failure message sent by the first client for the first message; The storage module is used to store the first message in the cache into the first message queue using a tail insertion method; The sending module is specifically used to: obtain the identification information of the first message, wherein multiple messages in the first message queue representing the same task process have the same identification information; if the identification information is different from the pre-stored target identifier, then send the first message to the first client, wherein the target identifier is the identification information of the second message that failed to be consumed; if the identification information is the same as the target identifier, then obtain the content data of the first message; if the content data is different from the pre-stored target content corresponding to the target identifier, then cache the first message.
9. An electronic device comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when run on an electronic device, causes the electronic device to perform the method as described in any one of claims 1 to 7.
11. A computer program product, comprising a computer program, characterized in that, When the computer program is run on an electronic device, it causes the electronic device to perform the method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Bullet screen message proces method, device, apparatus and storage medium
CN108989184A
Message queue processing method, thread pool parameter adjusting method, device and equipment
CN113722117A