Message queue processing method and device, electronic equipment and storage medium

By storing the producer as a database backup when sending a message and degrading the consumption process by the consumer, the problem of messages being unable to be processed when the message queue service failure is solved, the reliable delivery and processing of messages is realized, and the system's fault tolerance is ensured. Sex and message integrity.

CN119003204APending Publication Date: 2024-11-22CHINA MERCHANTS BANK
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411033490.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-30
Publication Date
2024-11-22

AI Technical Summary

Technical Problem

The existing message communication system highly relies on centralized message queue services, which leads to messages being unable to be processed and delivered when the message queue service fails, affecting the continuity of message delivery and processing.

Method used

When the producer sends a target message, the message is stored in the database as a backup, marking the message that failed to send is the first backup message, and the consumer reads it from the database for downgrading consumption processing, ensuring that the message is still reliable in the event of a queue failure. Pass and process.

Benefits of technology

Through the message backup mechanism and downgraded consumption processing, message data loss is avoided, message integrity and system fault tolerance are ensured, and message queue service failure can still be reliably delivered and processed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119003204A_ABST
    Figure CN119003204A_ABST
Patent Text Reader

Abstract

The invention discloses a message queue processing method and device, electronic equipment and a storage medium, and relates to the technical field of data processing, the message queue processing method and device are applied to a message queue processing system, and the message queue processing system comprises a producer, a consumer, a target queue and a database. Storing the target message to a database as a backup message; sending the target message to a target queue, and marking a backup message corresponding to the target message which fails to be sent in a database as a first backup message; and reading the first backup message from the database so that the consumer can execute degraded consumption processing on the first backup message. According to the invention, reliable transmission and processing of the message when the message queue service fails can be guaranteed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a message queue processing method, device, electronic device and storage medium. Background Art

[0002] At present, distributed message queues are widely used in message communication systems due to their high throughput, low latency and message persistence. Message queues allow decoupling between producers (message senders) and consumers (message receivers), which can improve the scalability and fault tolerance of message communication systems.

[0003] However, the application of this message communication system is highly dependent on centralized message queue services, which may also be subject to risks such as downtime and network failure. If the message queue service is unavailable, all messages will not be processed and delivered, thus affecting the continuity of message delivery and processing.

[0004] In summary, how to ensure reliable delivery and processing of messages when message queue services fail has become a technical problem that urgently needs to be solved in this field. Summary of the invention

[0005] The main purpose of the present application is to provide a message queue processing method, device, electronic device and storage medium, aiming to ensure the reliable delivery and processing of messages when the message queue service fails.

[0006] To achieve the above purpose, the present application proposes a message queue processing method, which is applied to a message queue processing system. The message queue processing system includes a producer, a consumer, a target queue and a database. The message queue processing method includes:

[0007] When the producer sends a target message, the target message is stored in the database as a backup message;

[0008] Sending the target message to the target queue, and marking the backup message corresponding to the target message that failed to be sent in the database as the first backup message;

[0009] The first backup message is read from the database so that the consumer can perform downgrade consumption processing on the first backup message.

[0010] In one embodiment, after the step of sending the target message to the target queue, the step further includes:

[0011] Marking the backup message corresponding to the successfully sent target message in the database as a second backup message;

[0012] Monitoring the target queue based on a preset first monitoring annotation;

[0013] When it is monitored that the target queue receives the target message, the second backup message is deleted from the database.

[0014] In one embodiment, when monitoring that the target queue receives the target message, the step of deleting the second backup message from the database includes:

[0015] Monitor a preset asynchronous deletion queue through a preset message deletion thread, wherein the asynchronous deletion queue is used to store target messages received by the target queue;

[0016] When it is monitored that the asynchronous deletion queue receives the target message, the target message is read from the asynchronous deletion queue through a preset message deletion task thread, and the second backup message corresponding to the target message is deleted from the database.

[0017] In one embodiment, the step of storing the target message in the database as a backup message includes:

[0018] Monitor a preset asynchronous storage queue through a preset message saving thread, wherein the asynchronous storage queue is used to store the target message sent by the producer;

[0019] When it is monitored that the asynchronous storage queue receives the target message, the target message is read from the asynchronous storage queue through a preset message saving task thread, and the target message is stored in a database as a backup message.

[0020] In one embodiment, the step of reading the first backup message from the database so that the consumer can perform downgrade consumption processing on the first backup message includes:

[0021] Monitoring the database based on a preset second monitoring annotation;

[0022] When it is monitored that the first backup message exists in the database, the first backup message is read from the database, and the first backup message is added to a preset downgrade consumption queue;

[0023] The first backup message is read from the downgrade consumption queue through a preset downgrade consumption thread, so that the consumer performs downgrade consumption processing on the first backup message.

[0024] In one embodiment, the method further comprises:

[0025] Monitoring the database through a preset database monitoring thread;

[0026] For the second backup message in the database, when the storage time of the second backup message exceeds a preset storage time threshold, if the second backup message has not been deleted, the second backup message is added to the downgrade consumption queue;

[0027] The second backup message is read from the downgrade consumption queue through the downgrade consumption thread, so that the consumer performs downgrade consumption processing on the second backup message.

[0028] In one embodiment, the message queue processing system further includes a consumption logic storage container, and the method further includes:

[0029] Identify the target queue name corresponding to the target message;

[0030] The target consumption logic matching the target queue name is determined from the consumption logic storage container by the downgraded consumption thread, and downgraded consumption processing is performed on the first backup message and / or the second backup message in the downgraded consumption queue according to the target consumption logic.

[0031] In addition, to achieve the above purpose, the present application also proposes a message queue processing device, which is applied to a message queue processing system. The message queue processing system includes a producer, a consumer, a target queue and a database. The message queue processing device includes:

[0032] A backup storage module, used for storing the target message in the database as a backup message when the producer sends the target message;

[0033] A message marking module, used for sending the target message to the target queue, and marking the backup message corresponding to the target message that fails to be sent in the database as the first backup message;

[0034] A processing module is used to read the first backup message from the database so that the consumer can perform downgrade consumption processing on the first backup message.

[0035] In addition, to achieve the above objectives, the present application also proposes an electronic device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the message queue processing method as described above.

[0036] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium. A computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the message queue processing method as described above are implemented.

[0037] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the message queue processing method described above are implemented.

[0038] The present application proposes a message queue processing method. Before a producer in a message queue processing system sends a target message to a target queue, the target message is stored in a database as a backup message. Then, when the producer sends the target message to the target queue, the backup message corresponding to the target message that failed to be sent in the database is marked as a first backup message. Finally, the message data marked as the first backup message is read from the database, and a consumer in the message queue processing system performs downgraded consumption processing on the first backup message.

[0039] In summary, the present application implements a message backup mechanism when the producer sends the target message. Even if the target queue fails, all pending messages can be retained in the database, thereby avoiding the loss of message data and ensuring the integrity of the message. At the same time, by performing message marking and downgraded consumption processing mechanisms for failed messages, the system can automatically read the backup message that the producer failed to send from the database when it detects that the target queue has failed, and the consumer can perform downgraded consumption processing, thereby ensuring that the message can still be reliably delivered and processed when the message queue service fails. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0041] In order to more clearly illustrate the embodiments of the present application 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.

[0042] Figure 1 A flowchart of the first embodiment of the message queue processing method of the present application is provided;

[0043] Figure 2 Another flowchart provided for the first embodiment of the message queue processing method of the present application;

[0044] Figure 3 A schematic diagram of a message queue processing flow provided for Embodiment 2 of the message queue processing method of the present application;

[0045] Figure 4 This is a schematic diagram of the module structure of the message queue processing device according to an embodiment of the present application;

[0046] Figure 5 This is a schematic diagram of the device structure of the hardware operating environment involved in the message queue processing method in the embodiment of the present application.

[0047] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0048] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.

[0049] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0050] The main solution of the embodiment of the present application is: when the producer sends the target message, the target message is stored in the database as a backup message; the target message is sent to the target queue, and the backup message corresponding to the target message that failed to be sent in the database is marked as the first backup message; the first backup message is read from the database for the consumer to perform downgrade consumption processing on the first backup message.

[0051] Since the current message communication system applications are highly dependent on centralized message queue services, the message queue services themselves may also be subject to risks such as downtime and network failures. If the message queue service is unavailable, all messages will not be processed and delivered, thus affecting the continuity of message delivery and processing.

[0052] The embodiment of the present application provides a solution. By implementing a message backup mechanism when the producer sends the target message, even if the target queue fails, all pending messages can be retained in the database, thereby avoiding the loss of message data and ensuring the integrity of the message. At the same time, by performing a message marking and downgraded consumption processing mechanism for failed sending, the system can automatically read the backup message that the producer failed to send from the database when it detects that the target queue has failed, and the consumer can perform downgraded consumption processing, thereby ensuring that the message can still be reliably delivered and processed when the message queue service fails.

[0053] It should be noted that the execution subject of this embodiment can be an electronic device with data processing, network communication and program running functions. The electronic device can be hardware or software. When the electronic device is hardware, it can be implemented as a distributed cluster composed of multiple servers or terminal devices, or it can be implemented as a single server or a single terminal device; when the electronic device is embodied as software, it can be installed in the hardware devices listed above, which can be implemented as multiple software or software modules for providing distributed services, or it can be implemented as a single software or software module. No specific limitation is made here. The following embodiment takes a message queue processing system that provides distributed services as an example to illustrate the embodiment.

[0054] Before describing the embodiments, for ease of understanding and explanation, the producer, consumer and target queue in the system are first introduced, where:

[0055] Producer: A component or application responsible for generating and sending messages to a target queue. It is the origin of messages and is responsible for encapsulating business data or events into a message format and then sending it to a specified target queue. There can be multiple producers in the system.

[0056] Consumer: A component or application that is responsible for obtaining and processing messages from a target queue. It is the destination of the message and is responsible for reading messages from the queue and processing them accordingly based on business logic. There can be multiple consumers in the system.

[0057] Target queue: used to store messages sent by producers and for consumers to read and process. There can be multiple queues in the system.

[0058] There are some differences in the way of determining the target queue from multiple queues in different types of message queues. The following are some differences in determining the target queue in some common message queues:

[0059] 1.Kafka:

[0060] In Kafka, the target queue is usually called a topic. Producers send messages by specifying the topic name, and consumers receive messages by subscribing to the topic.

[0061] Kafka supports topic partitioning and replica mechanisms to achieve distributed storage and high availability of data.

[0062] 2. RabbitMQ:

[0063] In RabbitMQ, the target queue is determined by the queue name. The producer sends the message to the specified queue, and the consumer pulls the message from the queue for processing.

[0064] RabbitMQ supports the concepts of exchanges and bindings to achieve flexible routing and distribution of messages.

[0065] 3. ActiveMQ:

[0066] ActiveMQ also uses queue names to identify the target queue. Producers send messages to the specified queue, and consumers read messages from the queue.

[0067] ActiveMQ supports multiple messaging modes, including point-to-point (P2P) and publish / subscribe (Pub / Sub).

[0068] Based on this, the embodiment of the present application provides a message queue processing method, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the message queue processing method of the present application.

[0069] In this embodiment, the message queue processing method is applied to a message queue processing system, and the message queue processing system includes a producer, a consumer, a target queue and a database; the message queue processing method includes steps S10 to S30:

[0070] Step S10, when the producer sends the target message, the target message is stored in the database as a backup message;

[0071] It should be noted that the target message is any one or more messages sent by the producer, which carries the identification information of the specified receiving target queue. For example, in RabbitMQ, the target message carries the specified queue name. The producer sends the message to the Exchange, and the Exchange distributes the message to the target queue according to the routing rules and the information carried by the message.

[0072] When the producer in the system is ready to send a target message to the target queue, the system will first perform a backup operation. Specifically, the system will use AOP (Aspect Oriented Programming) technology to cut into the production station before sending the target message to the target message queue, and immediately store the target message in the database. The database can be a MySQL database, which is used to back up the target message to ensure that the target message data will not be lost even if the message queue service fails or interrupts during the subsequent message delivery process.

[0073] Step S20, sending the target message to the target queue, and marking the backup message corresponding to the target message that failed to be sent in the database as the first backup message;

[0074] It should be noted that the message queue service has multiple mechanisms for confirming whether the target message sent by the producer has successfully arrived at the target queue. Taking RabbitMQ as an example, after the producer sends the message, it can listen to the RabbitMQ callback method to determine whether the message has successfully arrived at the queue. If the message successfully arrives at the queue, a confirmation receipt (ack) will be received in the callback method; if the message fails to arrive at the queue, a nack (rejection) receipt will be received in the callback method. In this way, the system can determine the sending status of the target message based on this type of confirmation mechanism. Of course, the system can also adopt other publicly available mechanisms to determine the sending status of the message, which is not specifically limited in this embodiment.

[0075] During the process of the producer sending the target message to the target queue, the system will monitor the sending status of the target message to detect whether there is any sending failure. If it is monitored that the sending of the target message fails, the system will immediately search the database and mark the backup message corresponding to the target message as the first backup message, or mark the status of the backup message as sending failure. This mark is used to clarify which backup messages in the database failed to successfully reach the target queue when they were sent.

[0076] Step S30, reading the first backup message from the database, so that the consumer can perform downgrade consumption processing on the first backup message.

[0077] The system will actively read the backup message data marked as the first backup message from the database, that is, the target message that was not successfully sent to the target queue, and the consumer will downgrade the first backup message. The downgraded consumption processing refers to the business logic processing of the first backup message between consumers to avoid the risk of data loss or business interruption.

[0078] In a possible embodiment, Figure 2 As shown, after the step of "sending the target message to the target queue" in step S20, steps S40 to S60 may also be included:

[0079] Step S40, marking the backup message corresponding to the successfully sent target message in the database as a second backup message;

[0080] When the producer sends the target message to the target queue, the system monitors the sending status of the target message to detect whether there is any sending failure. If it is monitored that the target message is sent successfully, the system will immediately search the database and mark the backup message corresponding to the target message as the second backup message, or mark the status of the backup message as sent successfully. This mark is used to clarify which backup messages in the database have successfully arrived at the target queue when they were sent.

[0081] Step S50, monitoring the target queue based on a preset first monitoring annotation;

[0082] It should be noted that the first monitoring annotation is an annotation used to monitor the message reception status of the target queue. Different message queues usually have their own specific monitoring mechanisms or support monitoring in different ways.

[0083] For example, for RabbitMQ, @RabbitListener is a very convenient annotation provided by the Spring AMQP framework, which is used to listen to messages in the RabbitMQ queue in the Spring Boot application; for Kafka, @KafkaListener is an annotation in Spring Kafka for listening to Kafka topic messages. By marking @KafkaListener on the method, you can specify the Kafka topic and partition to be listened to. When a new message arrives, SpringKafka will automatically forward the message to the annotated method.

[0084] The system will start real-time monitoring of the target queue according to the preset first monitoring annotation to determine whether the target message has been successfully received by the target queue, further ensuring the integrity and timeliness of message delivery.

[0085] Step S60: When it is monitored that the target queue receives the target message, the second backup message is deleted from the database.

[0086] When it is detected that the target queue has received the target message, the system will query the database again, find the target message marked as the second backup message in the database, and delete it from the database to free up database space and avoid potential management complexity and cost increase caused by redundant backup.

[0087] In summary, the embodiment of the present application implements a message backup mechanism when the producer sends the target message. Even if the target queue fails, all pending messages can be retained in the database, thereby avoiding the loss of message data and ensuring the integrity of the message. At the same time, by performing message marking and downgraded consumption processing mechanisms for failed messages, the system can automatically read the backup message that the producer failed to send from the database when it detects that the target queue has failed, and the consumer can perform downgraded consumption processing, thereby ensuring that the message can still be reliably delivered and processed when the message queue service fails.

[0088] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. On this basis, step S60 can include steps S601 to S602:

[0089] Step S601, monitoring a preset asynchronous deletion queue through a preset message deletion thread, wherein the asynchronous deletion queue is used to store target messages received by a target queue;

[0090] In order to more effectively manage the deletion of backup messages and reduce interference with the main business logic process, the system uses an asynchronous processing method to delete the second backup message in the database.

[0091] The system has a pre-set asynchronous deletion queue, which is used to store target messages that have been successfully received by the target queue. In order to respond to these changes in a timely manner, the system starts a preset message deletion thread, which continuously monitors the status of the asynchronous deletion queue. This design allows the system to independently perform backup message deletion operations without affecting the main message processing flow.

[0092] Step S602, when monitoring that the asynchronous deletion queue receives the target message, the target message is read from the asynchronous deletion queue through a preset message deletion task thread, and the second backup message corresponding to the target message is deleted from the database.

[0093] When the message deletion thread monitors the appearance of a new message in the asynchronous deletion queue (that is, the target queue has successfully received the target message), the system will read the successfully received target message from the asynchronous deletion queue through the preset message deletion task thread. Subsequently, the message deletion task thread will query the database to find the second backup message corresponding to the target message and completely delete it from the database to ensure that only the backups of messages that have been successfully sent to the target queue and confirmed to be received by the target queue will be deleted, thereby avoiding the risk of data loss.

[0094] In a feasible embodiment, step S10 may include:

[0095] Step S101, monitoring a preset asynchronous storage queue through a preset message saving thread, wherein the asynchronous storage queue is used to store a target message sent by a producer;

[0096] In order to optimize system performance and reduce the blocking of the producer's message sending process, this embodiment adopts an asynchronous storage mechanism to process the target message sent by the producer.

[0097] An asynchronous storage queue is preset in the system, which is designed to temporarily store the target messages sent by the producer. In order to respond to these newly arrived messages in a timely manner, the system uses a preset message saving thread, which continuously monitors the status of the asynchronous storage queue. This design allows the system to independently handle the backup storage task of the target message without interrupting the producer from sending the target message to the target queue.

[0098] Step S102, when monitoring that the asynchronous storage queue receives the target message, the target message is read from the asynchronous storage queue through a preset message saving task thread, and the target message is stored in the database as a backup message.

[0099] When the message saving thread monitors the appearance of a new message in the asynchronous storage queue (that is, the producer sends a target message to the target queue), the system will read the target message from the asynchronous storage queue through the preset message saving task thread. Subsequently, the message saving task thread stores the target message in the database as a backup message to ensure that even if a system failure occurs after the producer sends the message, these messages can be restored through the database backup, thereby improving the reliability of the system and the security of the data.

[0100] For example, in a feasible embodiment, in order to help understand the implementation process of this embodiment combined with the first embodiment, please refer to Figure 3 , Figure 3 A brief flowchart of a message queue processing method using RabbitMQ as an example is provided. Specifically:

[0101] In traditional RabbitMQ message queue processing, the producer sends the message to the switch, the switch routes the message to the queue, and then the consumer reads the message from the queue and executes the consumption logic. Although this processing flow can decouple the producer and the consumer, there is a risk of being highly dependent on the message queue service. In this embodiment, before the producer sends the message to the switch, the message to be sent is pushed to the asynchronous storage queue, and the message saving thread continuously monitors the asynchronous storage queue. When a new message is detected in the asynchronous storage queue, the message saving task thread extracts the new message from the asynchronous storage queue and stores it in the database as a backup message. Then, based on the first monitoring annotation, the queue is monitored. , and when it is detected that the queue has received a new message, the message received by the queue is pushed to the asynchronous deletion queue, and the message deletion thread continuously monitors the asynchronous deletion queue. When it is monitored that there is a new message added to the asynchronous deletion queue, the message deletion task thread extracts the newly added message from the asynchronous deletion queue and deletes the corresponding backup message of the message in the database. It should also be noted that the steps of storing messages and deleting messages in the database in this embodiment are asynchronously implemented steps, which will not affect the process of message sending and processing in the message queue service, thereby ensuring the message sending and processing under the normal operation of the message queue service, and also ensuring the message sending and processing when the message queue service fails, thereby improving the reliability of the system.

[0102] In a feasible embodiment, step S30 may include steps S301 to S303:

[0103] Step S301, monitoring a database based on a preset second monitoring annotation;

[0104] It should be noted that the second monitoring annotation is an annotation used to monitor the message reception status of the database. Different message queues usually have their own specific monitoring mechanisms or support monitoring in different ways.

[0105] For example, for RabbitMQ, the consumer configures an annotation @DbMessageListener(queues={"ab","aa"}), where "ab" and "aa" indicate the queue name to be monitored, and the queue name needs to correspond to the queue name specified when the message is sent.

[0106] The system will start real-time monitoring of the database according to the second monitoring annotation or monitor at a certain time interval to determine whether there is a new target message in the database that has been backed up and stored.

[0107] Step S302: when it is monitored that there is a first backup message in the database, read the first backup message from the database, and add the first backup message to a preset downgrade consumption queue;

[0108] When the system detects the appearance of a backup message marked as the first backup message in the database (i.e., the backup message data of the target message that the producer failed to send to the target queue), the system will immediately perform a read operation to extract the first backup message from the database. Subsequently, the first backup message will be added to the system's pre-set downgrade consumption queue, which is used to temporarily store messages that cannot be processed normally by consumers for some reason.

[0109] Step S303: Read the first backup message from the downgrade consumption queue through a preset downgrade consumption thread, so that the consumer performs downgrade consumption processing on the first backup message.

[0110] The system schedules a predefined downgrade consumption thread to read the first backup message from the downgrade consumption queue, and the consumer performs downgrade consumption processing on the first backup message.

[0111] In this way, the system can not only effectively ensure the security and integrity of messages when facing message queue service failures, but also flexibly adjust consumption strategies. Consumers obtain messages from the database for processing, ensuring the continuity and stability of the message processing process, avoiding message loss or business interruption caused by message queue service failures, and improving the system's fault tolerance for message processing.

[0112] In a feasible embodiment, the message queue processing method may further include steps A10 to A30:

[0113] Step A10, monitoring the database through a preset database monitoring thread;

[0114] The system deploys a preset database listening thread, which is configured to continuously monitor the database status and data changes to ensure that the system can capture the message backup status in the database in real time.

[0115] Step A20, for the second backup message in the database, when the storage time of the second backup message exceeds the preset storage time threshold, if the second backup message has not been deleted, the second backup message is added to the downgrade consumption queue;

[0116] The system periodically checks the second backup message in the database. The second backup information is the target information that has been successfully sent to the target queue by the producer. This type of target message needs to be listened to and extracted from the target queue by the consumer through the first listening annotation for processing. In actual applications, this type of target message may not be processed in time due to some reason (such as consumer processing delay, message queue failure, etc.), then the second backup message of this type of target message backed up in the database is also not deleted.

[0117] When the storage time of the second backup message (i.e. the time interval from when the message is added to the database to the current time) exceeds the system preset storage time threshold (such as 10 minutes), and the message is not deleted or successfully consumed during this period, the system will regard the second backup message as an expired and unprocessed abnormal message. Subsequently, the system will extract the second backup message from the database and add it to the downgraded consumption queue.

[0118] Step A30: Read the second backup message from the downgrade consumption queue through the downgrade consumption thread, so that the consumer can perform downgrade consumption processing on the second backup message.

[0119] The system schedules a predefined downgrade consumption thread to read the second backup message that has timed out and not been deleted or has not been successfully consumed from the downgrade consumption queue, and the consumer performs downgrade consumption processing on the second backup message.

[0120] This ensures that messages that have not been consumed for a long time will not be forgotten or lost, which helps improve the overall reliability and stability of the system.

[0121] In a feasible embodiment, the message queue processing system further includes a consumption logic storage container, and the message queue processing method may further include steps B10 to B20:

[0122] Step B10, identifying the target queue name corresponding to the target message;

[0123] Before the consumer downgrades the backup message in the database, the system first identifies the target queue name corresponding to the target message to be processed to ensure that the message can be correctly routed to the corresponding consumption logic. This identification process relies on the identification information of the designated receiving target queue carried by the target message itself.

[0124] Step B20, determining the target consumption logic matching the target queue name from the consumption logic storage container through the downgrade consumption thread, and performing downgrade consumption processing on the first backup message and / or the second backup message in the downgrade consumption queue according to the target consumption logic.

[0125] It should be noted that the consumption logic storage container is used to store and manage the consumption logics corresponding to different queues, so that the target consumption logic of the target queue can be quickly located and applied when the system needs it.

[0126] The system starts the downgraded consumption thread and searches for the target consumption logic that matches the identified target queue name from the consumption logic storage container. Subsequently, the downgraded consumption thread will perform downgraded consumption processing on the first backup message and / or the second backup message in the downgraded consumption queue according to the found target consumption logic.

[0127] In this way, the system can flexibly adjust consumption strategies according to different business scenarios and needs, ensuring the continuity and effectiveness of message processing even in the face of message queue service failures. At the same time, by setting up a consumption logic storage container to centrally store consumption logic, the system can also more easily update and maintain logic, thereby improving the maintainability and scalability of the system.

[0128] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the message queue processing method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.

[0129] The embodiment of the present application also provides a message queue processing device, which is applied to a message queue processing system. The message queue processing system includes a producer, a consumer, a target queue and a database. Please refer to Figure 4 , the message queue processing device comprises:

[0130] The backup storage module 10 is used to store the target message in the database as a backup message when the producer sends the target message;

[0131] A message marking module 20, configured to send a target message to a target queue, and mark a backup message corresponding to a target message that fails to be sent in a database as a first backup message;

[0132] The processing module 30 is used to read the first backup message from the database so that the consumer can perform downgrade consumption processing on the first backup message.

[0133] Optionally, the message queue processing device further includes a message deletion module (not shown), and the message deletion module is used to:

[0134] Mark the backup message corresponding to the successfully sent target message in the database as the second backup message;

[0135] Monitor the target queue based on the preset first monitoring annotation;

[0136] When it is monitored that the target queue receives the target message, the second backup message is deleted from the database.

[0137] Optionally, the message deletion module is further used to:

[0138] The preset asynchronous deletion queue is monitored through a preset message deletion thread, wherein the asynchronous deletion queue is used to store the target message received by the target queue;

[0139] When it is monitored that the asynchronous deletion queue receives the target message, the target message is read from the asynchronous deletion queue through a preset message deletion task thread, and the second backup message corresponding to the target message is deleted from the database.

[0140] Optionally, the backup storage module 10 is further used for:

[0141] The preset asynchronous storage queue is monitored through a preset message saving thread, wherein the asynchronous storage queue is used to store the target message sent by the producer;

[0142] When the asynchronous storage queue is monitored to receive the target message, the target message is read from the asynchronous storage queue through a preset message saving task thread, and the target message is stored in the database as a backup message.

[0143] Optionally, the processing module 30 is further configured to:

[0144] A monitoring database based on a preset second monitoring annotation;

[0145] When the first backup message is detected in the database, the first backup message is read from the database, and the first backup message is added to a preset downgrade consumption queue;

[0146] The first backup message is read from the downgrade consumption queue through a preset downgrade consumption thread, so that the consumer performs downgrade consumption processing on the first backup message.

[0147] Optionally, the processing module 30 is further configured to:

[0148] Monitor the database through the preset database monitoring thread;

[0149] For the second backup message in the database, when the storage time of the second backup message exceeds the preset storage time threshold, if the second backup message has not been deleted, the second backup message is added to the downgrade consumption queue;

[0150] The second backup message is read from the downgrade consumption queue through the downgrade consumption thread, so that the consumer performs downgrade consumption processing on the second backup message.

[0151] Optionally, the message queue processing system further includes a consumption logic storage container, and the processing module 30 is further used to:

[0152] Identify the target queue name corresponding to the target message;

[0153] The target consumption logic matching the target queue name is determined from the consumption logic storage container through the downgrade consumption thread, and downgrade consumption processing is performed on the first backup message and / or the second backup message in the downgrade consumption queue according to the target consumption logic.

[0154] The message queue processing device provided in the embodiment of the present application adopts the message queue processing method in the above embodiment, which can ensure the reliable transmission and processing of messages when the message queue service fails. Compared with the prior art, the beneficial effects of the message queue processing device provided in the embodiment of the present application are the same as the beneficial effects of the message queue processing method provided in the above embodiment, and other technical features in the message queue processing device are the same as the features disclosed in the message queue processing method in the above embodiment, which will not be repeated here.

[0155] An embodiment of the present application provides an electronic device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the message queue processing method in the above-mentioned embodiment one.

[0156] Reference below Figure 5 , which shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiment of the present application. The electronic device in the embodiment of the present application may include a mobile terminal and a fixed terminal of the MCU. Figure 5 The microcontroller shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0157] like Figure 5As shown, the electronic device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the electronic device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows an electronic device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.

[0158] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0159] The electronic device provided in the embodiment of the present application adopts the message queue processing method in the above embodiment, which can ensure the reliable transmission and processing of messages when the message queue service fails. Compared with the prior art, the beneficial effects of the electronic device provided in the embodiment of the present application are the same as the beneficial effects of the message queue processing method provided in the above embodiment, and other technical features in the electronic device are the same as the features disclosed in the message queue processing method in the previous embodiment, which will not be repeated here.

[0160] It should be understood that the various parts disclosed in the embodiments of the present application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0161] The above are only specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0162] An embodiment of the present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the message queue processing method in the above embodiment.

[0163] The computer-readable storage medium provided in the embodiment of the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM: Random Access Memory), a read-only memory (ROM: Read Only Memory), an erasable programmable read-only memory (EPROM: Erasable Programmable Read Only Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency: Radio Frequency), etc., or any suitable combination of the above.

[0164] The computer-readable storage medium may be included in the electronic device, or may exist independently without being installed in the electronic device.

[0165] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by an electronic device, the electronic device: when the producer sends the target message, stores the target message in the database as a backup message; sends the target message to the target queue, and marks the backup message corresponding to the target message that failed to be sent in the database as the first backup message; reads the first backup message from the database so that the consumer can perform downgrade consumption processing on the first backup message.

[0166] The computer program code for performing the operation of the embodiment of the present application can be written in one or more programming languages ​​or a combination thereof, and the above-mentioned programming languages ​​include object-oriented programming languages, such as Java, Smalltalk, C++, and also include conventional procedural programming languages, such as "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on the remote computer, or completely on the remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (e.g., using an Internet service provider to connect through the Internet).

[0167] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0168] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0169] The readable storage medium provided in the embodiment of the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned message queue processing method, and can ensure the reliable delivery and processing of messages when the message queue service fails. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in the embodiment of the present application are the same as the beneficial effects of the message queue processing method provided in the above-mentioned embodiment, and will not be repeated here.

[0170] The present application also provides a computer program product, including a computer program, which implements the steps of the message queue processing method as described above when the computer program is executed by a processor.

[0171] The computer program product provided by the present application can solve the technical problem of message queue processing. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the message queue processing method provided by the above embodiment, which will not be repeated here.

[0172] The above are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect application in other related technical fields are included in the patent protection scope of the present application.

Claims

1. A message queue processing method, characterized in that: Applied to a message queue processing system, the message queue processing system comprising a producer, a consumer, a target queue and a database; The method includes: When the producer sends a target message, the target message is stored in the database as a backup message; Sending the target message to the target queue, and marking the backup message corresponding to the target message that failed to be sent in the database as the first backup message; The first backup message is read from the database so that the consumer can perform downgrade consumption processing on the first backup message.

2. The method according to claim 1, characterized in that After the step of sending the target message to the target queue, the following steps are further included: Marking the backup message corresponding to the successfully sent target message in the database as a second backup message; Monitoring the target queue based on a preset first monitoring annotation; When it is monitored that the target queue receives the target message, the second backup message is deleted from the database.

3. The method according to claim 2, characterized in that The step of deleting the second backup message from the database when monitoring that the target queue receives the target message comprises: Monitor a preset asynchronous deletion queue through a preset message deletion thread, wherein the asynchronous deletion queue is used to store target messages received by the target queue; When it is monitored that the asynchronous deletion queue receives the target message, the target message is read from the asynchronous deletion queue through a preset message deletion task thread, and the second backup message corresponding to the target message is deleted from the database.

4. The method according to claim 1, characterized in that The step of storing the target message in the database as a backup message comprises: Monitor a preset asynchronous storage queue through a preset message saving thread, wherein the asynchronous storage queue is used to store the target message sent by the producer; When it is monitored that the asynchronous storage queue receives the target message, the target message is read from the asynchronous storage queue through a preset message saving task thread, and the target message is stored in a database as a backup message.

5. The method according to any one of claims 1 to 4, characterized in that The step of reading the first backup message from the database so that the consumer can perform downgrade consumption processing on the first backup message includes: Monitoring the database based on a preset second monitoring annotation; When it is monitored that the first backup message exists in the database, the first backup message is read from the database, and the first backup message is added to a preset downgrade consumption queue; The first backup message is read from the downgrade consumption queue through a preset downgrade consumption thread, so that the consumer performs downgrade consumption processing on the first backup message.

6. The method according to claim 5, characterized in that The method further comprises: Monitoring the database through a preset database monitoring thread; For the second backup message in the database, when the storage time of the second backup message exceeds a preset storage time threshold, if the second backup message has not been deleted, the second backup message is added to the downgrade consumption queue; The second backup message is read from the downgrade consumption queue through the downgrade consumption thread, so that the consumer performs downgrade consumption processing on the second backup message.

7. The method according to claim 6, characterized in that The message queue processing system further includes a consumption logic storage container, and the method further includes: Identify the target queue name corresponding to the target message; The downgraded consumption thread determines the target consumption logic matching the target queue name from the consumption logic storage container, and performs downgraded consumption processing on the first backup message and / or the second backup message in the downgraded consumption queue according to the target consumption logic.

8. A message queue processing device, characterized in that: Applied to a message queue processing system, the message queue processing system includes a producer, a consumer, a target queue and a database, and the device includes: A backup storage module, used for storing the target message in the database as a backup message when the producer sends the target message; A message marking module, used for sending the target message to the target queue, and marking the backup message corresponding to the target message that fails to be sent in the database as the first backup message; A processing module is used to read the first backup message from the database so that the consumer can perform downgrade consumption processing on the first backup message.

9. An electronic device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the message queue processing method according to any one of claims 1 to 7.

10. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the message queue processing method according to any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Data processing method and device and storage medium

    CN114296999A

  • Message matching method, device and equipment for point-to-point conditional subscription between client and message-oriented middleware

    CN119342098A