Message processing method and device, storage medium and electronic device

By storing and resending the failure information of Kafka messages, the problem of data loss and consistency during Kafka message sending is solved, and the efficiency and accuracy of message sending are improved.

CN115086414BActive Publication Date: 2024-10-22BEIJING XUEZHITU NETWORK TECH
View PDF 0 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

During the Kafka message sending process, message sending fails due to network fluctuations, server abnormalities, or producer exceptions, and the normal sending of messages cannot be guaranteed, resulting in data loss and poor accuracy and consistency of data processing, and in the existing architecture Message resend efficiency is low.

Method used

By receiving the retry service request, the attribute information of the failed message is stored in the retry service database. Based on these attribute information, a collection of messages to be resent that meet the preset resending conditions is obtained, and the messages are paged using snapshot paging. Then resend the message.

Benefits of technology

It achieves data accuracy and consistency in the message sending process, improves the efficiency of message sending, and solves the problems of data loss and repeated sending.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115086414B_ABST
    Figure CN115086414B_ABST
Patent Text Reader

Abstract

The present invention discloses a message processing method and device, a storage medium and an electronic device. The method comprises: according to a received retry service request, storing the attribute information of each message in the current message set that failed to be sent into a retry service database; obtaining a message set to be resent that meets the preset resending conditions based on the attribute information; paging the message set to be resent based on snapshot paging to obtain multiple message paging subsets; and resending the messages in the multiple message paging subsets. The present invention solves the technical problem of poor data accuracy and consistency in the message sending process in the related art.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] In the process of sending messages in Kafka, a publish-subscribe messaging system, messages may be timed out due to network fluctuations, Kafka server exceptions, or message sending failures due to producer exceptions. It is impossible to ensure that messages are sent to the Kafka server normally. In the above situation, in some scenarios where messages are only sent once, such as WeChat callback messages, if a message fails to be sent during the process of sending messages to the Kafka server, data loss will occur, and the accuracy and consistency of data processing will be poor. In addition, in the existing message sending architecture system, when multiple businesses handle the failure of Kafka to send messages by themselves, messages will be sent repeatedly, resulting in low message retransmission efficiency. Summary of the invention

[0003] The embodiments of the present invention provide a message processing method and device, a storage medium and an electronic device, so as to at least solve the technical problem of poor data accuracy and consistency in the process of message sending in the related art.

[0004] According to one aspect of an embodiment of the present invention, a message processing method is provided, including: based on a received retry service request, storing the attribute information of each message in the current message set that failed to be sent in a retry service database; based on the above attribute information, obtaining a set of messages to be resent that meets preset resending conditions; paging the above message set to be resent based on snapshot paging to obtain multiple message paging subsets; and resending the messages in the above multiple message paging subsets.

[0005] According to another aspect of an embodiment of the present invention, a message processing device is also provided, including: a storage unit, which stores the current message set that failed to be sent and the attribute information of each message in the above message set to a retry service database according to a received retry service request; an acquisition unit, which is used to acquire the to-be-retransmitted message set that meets the preset retransmission conditions based on the above attribute information; a paging unit, which is used to paginate the above message set to be retransmitted based on snapshot paging to obtain multiple message paging subsets; and a retransmission unit, which is used to retransmit the messages in the above multiple message paging subsets.

[0006] According to another aspect of an embodiment of the present invention, there is further provided an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the message processing method through the computer program.

[0007] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the above-mentioned message processing method when running.

[0008] The present invention can at least achieve the following beneficial effects:

[0009] The present invention can be applied to the data transmission (secondary patent matrix technology field in the system) field of data capability (first level patent matrix technology field in the system). In an embodiment of the present invention, the attribute information of each message in the current failed message set is stored in the retry service database according to the received retry service request; a set of messages to be resent that meet the preset resending conditions is obtained based on the above attribute information; the above message set to be resent is paged based on the snapshot paging method to obtain multiple message paging subsets; a method for resending the messages in the above multiple message paging subsets, in which a set of messages to be resent that meet the preset resending conditions is obtained through attribute information, and the above message set to be resent is paged based on the snapshot paging method to obtain multiple message paging subsets, which can not only accurately obtain the failed message, but also resend the failed message according to the preset resending conditions, which not only ensures the data accuracy and consistency in the message sending process, but also improves the efficiency of message sending, thereby solving the technical problem of poor data accuracy and consistency in the message sending process in the related technology. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0011] Figure 1 is a schematic diagram of an application environment of an optional message processing method according to an embodiment of the present invention;

[0012] Figure 2 is a schematic diagram of an application environment of another optional message processing method according to an embodiment of the present invention;

[0013] Figure 3 is a flow chart of an optional message processing method according to an embodiment of the present invention;

[0014] Figure 4 is another optional Kafka topology diagram according to an embodiment of the present invention;

[0015] Figure 5 is a timing diagram of an optional message processing method according to an embodiment of the present invention;

[0016] Figure 6 is a schematic diagram of the architecture of an optional message processing method according to an embodiment of the present invention;

[0017] Figure 7 is a flowchart of another optional message processing method according to an embodiment of the present invention;

[0018] Figure 8 is a schematic structural diagram of an optional message processing device according to an embodiment of the present invention;

[0019] Fig. 9 It is a schematic diagram of the structure of an optional electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0020] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.

[0021] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0022] According to one aspect of an embodiment of the present invention, a message processing method is provided. As an optional implementation mode, the message processing method can be but is not limited to being applied to: Figure 1In the application environment shown. The application environment includes: a terminal device 102 for human-computer interaction with a user, a network 104, and a server 106. A user 108 can perform human-computer interaction with the terminal device 102, and a message processing application is running in the terminal device 102. The terminal device 102 includes a human-computer interaction screen 1022, a processor 1024, and a memory 1026. The human-computer interaction screen 1022 is used to display a message set that failed to be sent; the processor 1024 is used to obtain a retry service request. The memory 1026 is used to store the message set that failed to be sent.

[0023] In addition, the server 106 includes a database 1062 and a processing engine 1064, and the database 1062 is used to store the above-mentioned message set that failed to be sent. The processing engine 1064 is used to store the attribute information of each message in the current message set that failed to be sent to the retry service database according to the received retry service request; obtain a message set to be resent that meets the preset resending conditions based on the above-mentioned attribute information; paginate the above-mentioned message set to be resent based on the snapshot paging method to obtain multiple message paging subsets; resend the messages in the above-mentioned multiple message paging subsets; and send the message sending results to the client of the above-mentioned terminal device 102.

[0024] In one or more embodiments, the message processing method of the present application can be applied to Figure 2 In the application environment shown. Figure 2 As shown, human-computer interaction can be performed between user 202 and user device 204. User device 204 includes memory 206 and processor 208. In this embodiment, user device 204 can refer to but not be limited to executing the operations executed by the above terminal device 102 to obtain the result of message sending.

[0025] Optionally, the terminal device 102 and the user device 204 include but are not limited to mobile phones, tablet computers, laptop computers, PCs, vehicle-mounted electronic devices, wearable devices and other terminals, and the network 104 may include but is not limited to wireless networks or wired networks. Among them, the wireless network includes: WIFI and other networks that realize wireless communication. The wired network may include but is not limited to: wide area network, metropolitan area network, local area network. The server 106 may include but is not limited to any hardware device that can perform computing. The server may be a single server, or a server cluster composed of multiple servers, or a cloud server. The above is only an example, and no limitation is made to this in this embodiment.

[0026] In the related technology, when the system needs to send a large amount of messages, the Kafka message queue is used to transmit the messages. At the same time, in order to ensure the throughput, the ACK confirmation character is equal to 1 to send the message, that is, only the Kafka server leader (each partition has multiple copies, of which there is only one leader, and the leader is the partition currently responsible for reading and writing data) needs to receive the producer data and get confirmation, but it cannot ensure that the message will be received by the Kafka server. The specific process is as follows Figure 4 As shown:

[0027] i. After receiving the request, the Producer business service calls the Kafka client's message sending interface to send a message to the Kafka server and to the Leader of the Broker (a Kafka cluster contains one or more servers, and the server node is called a Broker). Since the Kafka used by the current business uses ACK=1 to send messages, after the Leader receives the message, it will send a confirmation callback to the Producer.

[0028] ii. Then copy the replica and synchronize it to the Follower. However, if the Leader of the Partition fails and the Follower has not yet copied the data, the data will be lost. The Follower follows the Leader, and all write requests are routed through the Leader. Data changes are broadcast to all Followers, and the Followers and Leader keep data synchronized. If the Leader fails, a new Leader is elected from the Followers. When the Follower and Leader hang up, get stuck, or synchronize too slowly, the leader will delete the follower from the In Sync Replicas (ISR) list and create a new Follower; here, the ISR list is a set of all replicas that synchronize data with the Partition leader.

[0029] iii. The Consumer business service monitors the corresponding Topic and consumes the message when it receives it.

[0030] Related technologies During the message sending process, due to network fluctuations, sending timeouts, Kafka server exceptions, or producer exceptions during the sending process, the message cannot be sent to the Kafka server normally. This is in important scenarios where some messages are only sent once, such as WeChat callback information. If it is lost during the sending process of Kafka, it will cause data loss problems and affect the normal use of functions. In addition, in the existing architecture system, when each business module handles the failure of Kafka to send messages on its own, a lot of duplicate work will be generated, resulting in a waste of computing resources.

[0031] In order to solve the above technical problems, as an optional implementation method, Figure 3 As shown, an embodiment of the present invention provides a message processing method, comprising the following steps:

[0032] S302: According to the received retry service request, the attribute information of each message in the current message set that failed to be sent is stored in the retry service database.

[0033] Specifically, Figure 5 As shown in the figure, in the message production service module, after the producer Producer receives a request to send a message, it first tries to send it, and then listens for the callback of sending the message (i.e., message confirmation). The message callback is a callback message that calls the sending interface of Kafka, which will inform the caller of the message sending situation, such as whether the sending is successful, the reason for failure, and other information.

[0034] When the Producer receives the callback message, it determines whether the message is sent successfully. If it is sent successfully, the current message sending process ends.

[0035] When the current message fails to be sent, the function provided by the third-party library spring-retry will be used to perform a local retry locally, completing the message sending locally without the need for additional overhead space to store failed messages and retried messages. The specific steps are as follows:

[0036] 1) Add the @EnableRetry annotation to the startup class to enable the retry function, and add the annotated class or method. EnableRetry gives the system the function of enabling message sending and retrying.

[0037] 2) Add the Retryable annotation to the sending method, and set the number of retries and interval time, and exception interception. In this way, when encountering the corresponding exception, the above annotated method will retry the corresponding number of times at the time interval according to the settings. For example, set the number of retries to 3 and the interval to 3 seconds, and retry when encountering the HttpClientErrorException request exception.

[0038] In an embodiment of the present invention, a retry service module is set to process a collection of messages that fail to be sent; when spring-retry fails to resend three times, an http request calls the interface of the retry service module to send a record of the failed message. After receiving the retry service request, the retry service stores the failed message in the retry service database and records a log. The log mainly stores the following information: the id of the message in the retry service database (mainly used to solve the problem of duplicate data storage), the topic sent, the service item to which the message belongs, the index value of the message, the content of the message, the type of the message, whether it needs to be resent, the expiration time of the message, and other information.

[0039] S304: Based on the above attribute information, a set of messages to be resent that meet preset resending conditions is obtained.

[0040] Specifically, the above-mentioned preset retransmission conditions include, but are not limited to, giving priority to sending messages that have been kept for a long time after a failed transmission, retransmitting records that have not been successfully transmitted and whose number of retries does not exceed the maximum threshold and the maximum timeout period, and determining the message set that meets the preset retransmission conditions. It should be noted that the retry service module in the embodiment of the present invention can send the messages to be retransmitted in sequence according to the configured timing duration.

[0041] S306, paging the message set to be resent based on snapshot paging to obtain multiple message paging subsets.

[0042] Specifically, the list of resent message sets is paginated, and a certain amount of data is queried each time. Through the above technical means, the resend task executed at the current moment is taken as a snapshot and cached locally, and then small batches of data are queried in pages, which can prevent excessive memory usage or memory overflow due to too many query message records.

[0043] S308: Resend the messages in the multiple message page subsets.

[0044] Specifically, the retry service module calls the API interface of Kafka to send the message to be resent.

[0045] In an embodiment of the present invention, the attribute information of each message in the current message set that failed to be sent is stored in a retry service database according to the received retry service request; a message set to be resent that meets the preset resending conditions is obtained based on the above attribute information; the message set to be resent is paged based on snapshot paging to obtain multiple message paging subsets; a method for resending the messages in the above multiple message paging subsets is provided. In the above method, a message set to be resent that meets the preset resending conditions is obtained through attribute information, and the message set to be resent is paged based on snapshot paging to obtain multiple message paging subsets. This method can not only accurately obtain the message that failed to be sent, but also resend the message that failed to be sent according to the preset resending conditions, which not only ensures the data accuracy and consistency in the message sending process, but also improves the efficiency of message sending, thereby solving the technical problem of poor data accuracy and consistency in the message sending process in the related art.

[0046] In one or more embodiments, the attribute information includes the creation time of the message that failed to be sent in the retry service database, and the acquiring of the set of messages to be resent that meet the preset resending conditions based on the attribute information includes:

[0047] Determine the resending priority of each message in the message set that failed to be sent according to the above creation time;

[0048] According to the retransmission priority and based on the attribute information, a set of messages to be retransmitted that meet the preset retransmission conditions is obtained.

[0049] Specifically, assuming that when a message fails to be sent, the retry service module receives a message retry service request corresponding to the message, and generates the creation time of the message in the retry service database according to the time of the service request, and sets the priority of the message with a longer creation time as a high sending priority; in this way, messages that have been retained for a longer time after the message fails to be sent can be sent first.

[0050] In one or more embodiments, obtaining a set of messages to be retransmitted that meet a preset retransmission condition based on the attribute information includes:

[0051] Get a set of messages to be resent that meet the preset resend conditions within each preset time interval.

[0052] Specifically, the retry service module in the embodiment of the present invention can continuously send messages to be resent within a preset time interval in a polling manner, and a certain number of messages can be selected for message resending in each time interval.

[0053] In one or more embodiments, obtaining a set of messages to be retransmitted that meet a preset retransmission condition based on the attribute information includes:

[0054] Obtain a target message set that has not been successfully sent, whose number of retry sending times does not exceed a first threshold, and whose timeout period has not exceeded a preset timeout period;

[0055] The target message set is determined as the message set to be resent.

[0056] Specifically, in the embodiment of the present invention, the stability of message sending can be controlled by configuring the first threshold, and the accuracy and consistency of message transmission can be ensured by configuring a preset timeout time.

[0057] In one or more embodiments, the attribute information includes the number of retry transmissions and the transmission status, and after the resending of the messages in the plurality of message page subsets, the method further includes:

[0058] When the first message in the plurality of message page subsets is sent successfully, the sending status of the first message is updated to sent.

[0059] Specifically, when a message in the message paging subset is sent successfully, the sending status of the successfully sent message in the retry service data is updated from not sent to sent.

[0060] When the sending of the second message in the plurality of message page subsets fails, the number of retry sending of the second message is increased and the second message is resent within the next resending time period.

[0061] Specifically, when a message in the message paging subset fails to be sent, the number of retry transmissions of the failed message in the retry service data is increased by 1, and the message is sent preferentially in the next retransmission period.

[0062] In one or more embodiments, the attribute information further includes a message retransmission unique identifier, and the increasing the number of retry transmissions of the second message and retransmitting the second message within the next retransmission time period includes:

[0063] According to the message resending unique identifier of the second message, the number of retry sending of each of the second messages is increased, and the second message is resent within the next sending time period.

[0064] Specifically, the above-mentioned message resending unique identifier (retry id) is used to uniquely identify the current message. The producer listens to the callback message. When the sending is successful, the sending status of the successfully sent message is marked as sent in the retry service database. If it fails, the number of retries is increased by 1, and it is resent in the next scheduled task. In the process of resending the Kafka message, the retry id is configured on the request header. When the consumer fails to consume the message and needs to resend it, the consumer can obtain the retry id according to the received message request header. If the retry id is not empty, the retry id is sent to the retry service module. When the retry service database is entered, if the retry id is not empty, the corresponding record in the database is updated. There is no need to add new messages to prevent duplicate records of messages, which leads to multiple resending of the same message.

[0065] In one or more embodiments, the attribute information includes a retransmission flag, and the method further includes:

[0066] When the number of retry transmissions of the third message in the plurality of message page subsets exceeds a first threshold, the retransmission flag corresponding to the third message is updated to stop retransmission.

[0067] The producer listens to the callback message. When the message is sent successfully, the sending status of the message is marked as sent in the retry service database. If it fails, the number of retries is increased by 1 and it is resent in the next scheduled task. When the number of retries exceeds a certain number, no retries will be made to prevent wasting system resources.

[0068] In one or more embodiments, before storing the attribute information of the message pair currently failing to be sent in the retry service database according to the received retry service request, the method further includes:

[0069] Configure retry service instances on multiple servers; select servers that meet the target requirements to receive retry service requests.

[0070] Specifically, Figure 6 As shown, after the current message fails to be retried three times, the http request calls the interface of the retry service module to send the failed message record. The retry service module adopts a microservice architecture (different from a single system, the microservice architecture divides different functional modules of the system into different service systems). A load balancing component is used when sending messages. When the retry service is configured with multiple instances, such as 3 instances, the 3 instances can be on one server or on different servers. When they are on different servers, the problem of message retry service unavailability caused by the crash of one of the servers can be prevented; the above technical features ensure the high availability of the message resending service.

[0071] In the related art, products such as Distributed Transaction Coordinator (DTC) are based on enterprise WeChat data for business expansion, providing customers with better quality and more humane services. The system in the embodiment of the present invention adopts a microservice architecture, and different modules in the system are independent of each other. For various data integrations and system integrations, as well as message communication between different modules, there are many shortcomings in performance, robustness, and scalability due to the use of RPC synchronous processing technology. The message-based asynchronous processing model adopts a non-blocking call feature. The sender sends the message to the message server, and the message server forwards the message to the receiver at the appropriate time; sending and receiving are asynchronous, the sender does not need to wait, and the life cycle of the two does not need to be the same, and the sender can indirectly pass the message to multiple receivers, which greatly improves the performance, scalability and robustness of the program, which makes the asynchronous processing model more advantageous than the synchronous processing model in distributed applications.

[0072] As a middle-layer software, message middleware provides a set of reliable and universal methods for creating, sending, and receiving messages in distributed systems, and realizes reliable, efficient, and real-time cross-platform data transmission in distributed systems. Message middleware reduces the complexity of developing cross-platform and network protocol software, and it shields the specific details of different operating systems and network protocols.

[0073] Faced with distributed systems that are becoming increasingly large and complex, it has the following advantages over traditional object-oriented middleware:

[0074] Adopt asynchronous communication mode: the sender can do other work after sending the message without waiting for the receiver's response, and the receiver does not have to process the sender's request immediately after receiving the message.

[0075] Loosely coupled relationship between the client and service object life cycles: The client process and the service object process are not required to run normally. If the client's request is unreachable due to a service object crash or a network failure, the client will not receive an exception, and the message middleware can ensure that the message will not be lost. Therefore, in this system, message middleware is used extensively for message transmission.

[0076] In the related technology, when the system needs to send a large amount of messages, the Kafka message queue is used to transmit the messages. At the same time, in order to ensure the throughput, the ACK confirmation character is equal to 1 to send the message, that is, only the Kafka server leader (each partition has multiple copies, of which there is only one leader, and the leader is the partition currently responsible for reading and writing data) needs to receive the producer data and get confirmation, but it cannot ensure that the message will be received by the Kafka server. The specific process is as follows Figure 4 As shown:

[0077] i. After receiving the request, the Producer business service calls the Kafka client's message sending interface to send a message to the Kafka server and to the Leader of the Broker (a Kafka cluster contains one or more servers, and the server node is called a Broker). Since the Kafka used by the current business uses ACK=1 to send messages, after the Leader receives the message, it will send a confirmation callback to the Producer.

[0078] ii. Then copy the replica and synchronize it to the Follower. However, if the Leader of the Partition fails and the Follower has not yet copied the data, the data will be lost. The Follower follows the Leader, and all write requests are routed through the Leader. Data changes are broadcast to all Followers, and the Followers and Leader keep data synchronized. If the Leader fails, a new Leader is elected from the Followers. When a Follower and Leader hang up, get stuck, or synchronize too slowly, the Leader will delete the Follower from the (In Sync Replicas, ISR) list and create a new Follower; here, the ISR list is a set of all replicas that synchronize data with the Partition leader.

[0079] iii. The Consumer business service monitors the corresponding Topic and consumes the message when it receives it.

[0080] Related technologies During the message sending process, due to network fluctuations, sending timeouts, Kafka server exceptions, or producer exceptions during the sending process, the message cannot be sent to the Kafka server normally. This is in important scenarios where some messages are only sent once, such as WeChat callback information. If it is lost during the sending process of Kafka, it will cause data loss problems and affect the normal use of functions. In addition, in the existing architecture system, when each business module handles the failure of Kafka to send messages on its own, a lot of duplicate work will be generated, resulting in a waste of computing resources.

[0081] Based on the above embodiments, in an application embodiment, if Figure 5 As shown, the above message processing method also includes:

[0082] 1. In the message production service module, after the producer Producer receives a request to send a message, it first tries to send it, and then listens for the callback of sending the message (i.e., message confirmation). The message callback is a callback message that calls the Kafka sending interface, which will inform the caller of the message sending situation, such as whether the message is sent successfully, the reason for failure, and other information.

[0083] When the Producer receives the callback message, it determines whether the message is sent successfully. If it is sent successfully, the current message sending process ends.

[0084] 2. When the current message fails to be sent, the function provided by the third-party library spring-retry will be used to perform a local retry locally, completing the message sending locally without the need for additional overhead space to store failed messages and retried messages. The specific steps are as follows:

[0085] 1) Add the @EnableRetry annotation to the startup class to enable the retry function. Add the annotated class or method, etc. EnableRetry can give the system the function of enabling retry.

[0086] 2) Add the Retryable annotation to the sending method, and set the number of retries and interval time, and exception interception. In this way, when encountering the corresponding exception, the annotated method will retry the corresponding number of times at the time interval according to the settings. For example, set the number of retries to 3 and the interval to 3 seconds, and retry when encountering the HttpClientErrorException request exception.

[0087] 3. When three retries fail, the http request calls the interface of the retry service to send a failed message record, such as Figure 6As shown, due to the use of microservice architecture (different from a single system, the microservice architecture divides the different functional modules of the system into different service systems), a load balancing component is used when sending. When the retry service is configured with multiple instances, such as 3 instances, the message resending service will not be unavailable due to abnormalities in some instances of the retry service when resending messages, thus ensuring the high availability of the retry service.

[0088] 4. After receiving the request, the retry service will record it in the database and log it. The main information saved includes: the retry ID of the message in the retry service database, the topic to which it is sent, the service to which it belongs, the index of the message, the content of the message, the type of message, whether it needs to be resent, and the expiration time of the message.

[0089] 5. As Figure 7 As shown in the figure, a scheduled task is configured on the retry service module. The execution process of the scheduled task is as follows:

[0090] 1) Set up a scheduled task to query the retry IDs of all eligible failed send records in the current retry service database in the order of creation date at regular intervals. Get the list of messages to be sent, which are currently unsuccessful, and whose retry times do not exceed the maximum threshold and the maximum timeout. The creation time is to give priority to sending the oldest messages.

[0091] 2) Then the list is paginated, and a certain amount of data is queried each time. This is mainly to take the scheduled task executed at the current moment as a snapshot, cache it locally, and then query small batches of data in pages to prevent excessive memory usage or memory overflow due to too many records.

[0092] 3) The retry service module calls Kafka's API interface to send the above list of messages to be resent.

[0093] 6. When the message to be resent is sent successfully, the sending status of the successfully sent message is marked as sent in the retry service database. If it fails, the number of retries is increased by 1, and it is resent in the next scheduled task. In the process of resending the Kafka message, the retry id is configured on the request header. When the consumer fails to consume the message and needs to resend it, the consumer can obtain the retry id according to the received message request header. If the retry id is not empty, the retry id is sent to the retry service. When entering the database in the retry service, if the retry id is not empty, the corresponding record in the database can be updated. There is no need to add new messages to prevent duplicate records of messages, which will cause the same message to be resent multiple times.

[0094] In one or more embodiments, the message processing method includes:

[0095] Use the transaction method, record through logs, and then scan the log table regularly to resend messages. The specific process is as follows:

[0096] 1.Persist message data locally.

[0097] 2. Identify the message according to the serial number and configure the rollback method locally.

[0098] 3. Configure the information of the message to be resent into an XML file, and then use the XML file as a template through a third-party library (such as log4j or logback) to generate a log table. The log status is updated locally in a transaction.

[0099] 4. The scheduled task scans the log table for abnormal or timeout records, then calls the external query interface to resend the message, and changes the log status for the message that is successfully requested and successfully resent.

[0100] 5. If the external interface returns a resend failure, call the rollback method to roll back the message.

[0101] 6. When the external interface implements idempotence (idempotence means that the results of a single request or multiple requests initiated by a user for the same operation are consistent, and no other effects will occur due to multiple clicks), the message can be retried based on the message identifier.

[0102] The embodiments of the present invention also have the following beneficial effects:

[0103] 1. For messages that fail to be sent for the first time, the message can be automatically resent in the business service. Only when the message fails to be sent continuously will it be recorded in the retry service data, reducing the possibility of failure to send the message and the number of failed sending records.

[0104] 2. For failed records, they will be queried regularly and sent again, and the number of failed sending will be recorded. When the set threshold is reached, no retries will be made to prevent the waste of system resources caused by unlimited resending of messages.

[0105] 3. For messages that fail to be sent, in the retry service, the message id will be added to the request header when it is resent to prevent the message from being sent multiple times and causing multiple duplicate data to be recorded, thereby improving consistency.

[0106] 4. The rules of the retry service are unified. All services on the entire message system only need to introduce the corresponding jar package and call the interface to complete the access of the retry service.

[0107] It should be noted that, for the above-mentioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should know that the present invention is not limited by the described action sequence, because according to the present invention, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.

[0108] According to another aspect of the embodiments of the present invention, a message processing device for implementing the above message processing method is also provided. Figure 8 As shown, the device comprises:

[0109] The storage unit 802 stores the message set that has failed to be sent and the attribute information of each message in the message set to the retry service database according to the received retry service request;

[0110] An acquisition unit 804 is used to acquire a set of messages to be retransmitted that meet a preset retransmission condition based on the attribute information;

[0111] A paging unit 806, configured to paginate the message set to be resent based on snapshot paging to obtain a plurality of message paging subsets;

[0112] The resending unit 808 is used to resend the messages in the above-mentioned multiple message page subsets.

[0113] In an embodiment of the present invention, the attribute information of each message in the current message set that failed to be sent is stored in a retry service database according to the received retry service request; a message set to be resent that meets the preset resending conditions is obtained based on the above attribute information; the message set to be resent is paged based on snapshot paging to obtain multiple message paging subsets; a method for resending the messages in the above multiple message paging subsets is provided. In the above method, a message set to be resent that meets the preset resending conditions is obtained through attribute information, and the message set to be resent is paged based on snapshot paging to obtain multiple message paging subsets. This method can not only accurately obtain the message that failed to be sent, but also resend the message that failed to be sent according to the preset resending conditions, which not only ensures the data accuracy and consistency in the message sending process, but also improves the efficiency of message sending, thereby solving the technical problem of poor data accuracy and consistency in the message sending process in the related art.

[0114] In one or more embodiments, the attribute information includes the creation time of the message that failed to be sent in the retry service database, and the acquisition unit 804 specifically includes:

[0115] A first determination module, used to determine the retransmission priority of each message in the message set that failed to be sent according to the above creation time;

[0116] The first acquisition module is used to acquire a set of messages to be retransmitted that meet the preset retransmission conditions according to the retransmission priority and based on the attribute information.

[0117] In one or more embodiments, the acquisition unit 804 further includes:

[0118] The second acquisition module is used to acquire a set of messages to be retransmitted that meet a preset retransmission condition within each preset time interval.

[0119] In one or more embodiments, the acquisition unit 804 further includes:

[0120] A third acquisition module is used to acquire a target message set that has not been successfully sent, the number of retry transmissions does not exceed the first threshold, and does not exceed a preset timeout period;

[0121] The second determination module is used to determine the target message set as the to-be-retransmitted message set.

[0122] In one or more embodiments, the attribute information includes the number of retry transmissions and the transmission status, and the message processing device further includes:

[0123] A first updating unit, configured to update the sending status of the first message to sent when the first message in the plurality of message page subsets is sent successfully;

[0124] The adjusting unit is used to increase the number of retry transmissions of the second message and resend the second message in the next retransmission time period when the second message in the plurality of message page subsets fails to be transmitted.

[0125] In one or more embodiments, the attribute information further includes a message retransmission unique identifier, and the adjustment unit specifically includes:

[0126] The adjustment module is used to increase the number of retry transmissions of each of the second messages according to the message retransmission unique identifier of the second message, and retransmit the second message in the next transmission time period.

[0127] In one or more embodiments, the attribute information includes a retransmission flag, and the message processing device further includes:

[0128] The second updating unit is used to update the retransmission flag corresponding to the third message to stop retransmission when the number of retry transmissions of the third message in the plurality of message page subsets exceeds a first threshold.

[0129] In one or more embodiments, the message processing device further includes:

[0130] Configuration unit, used to configure retry service instances on multiple servers;

[0131] The selection unit is used to select a server that meets the target requirement to receive the retry service request.

[0132] According to another aspect of the embodiment of the present invention, an electronic device for implementing the above message processing method is also provided. The electronic device may be Fig. 9 The terminal device or server shown in the figure. This embodiment is described by taking the electronic device as a terminal as an example. Fig. 9 As shown, the electronic device includes a memory 902 and a processor 904. The memory 902 stores a computer program, and the processor 904 is configured to execute the steps in any of the above method embodiments through the computer program.

[0133] Optionally, in this embodiment, the electronic device may be located in at least one network device among a plurality of network devices of a computer network.

[0134] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:

[0135] S1, according to the received retry service request, store the attribute information of each message in the current message set that failed to be sent into the retry service database;

[0136] S2, obtaining a set of messages to be retransmitted that meet preset retransmission conditions based on the above attribute information;

[0137] S3, paging the message set to be resent based on snapshot paging to obtain multiple message paging subsets;

[0138] S4, resending the messages in the above-mentioned multiple message page subsets.

[0139] Alternatively, a person skilled in the art may understand that: Fig. 9 The structure shown is for illustration only, and the electronic device may also be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile Internet device (MID), a PAD, and other terminal devices. Fig. 9 The electronic device and the electronic equipment described above are not limited in structure. Fig. 9 More or fewer components (such as network interfaces, etc.) as shown in, or with Fig. 9 Different configurations shown.

[0140] Among them, the memory 902 can be used to store software programs and modules, such as program instructions / modules corresponding to the message processing method and device in the embodiment of the present invention. The processor 904 executes various functional applications and data processing by running the software programs and modules stored in the memory 902, that is, realizing the above-mentioned message processing method. The memory 902 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 902 may further include a memory remotely arranged relative to the processor 904, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned networks include but are not limited to the Internet, corporate intranets, local area networks, mobile communication networks and combinations thereof. Among them, the memory 902 can be specifically used, but not limited to, to store attribute information of failed messages. As an example, such as Fig. 9 As shown, the memory 902 may include but is not limited to the storage unit 802, acquisition unit 804, paging unit 806 and retransmission unit 808 in the message processing device. In addition, it may also include but is not limited to other module units in the message processing device, which will not be repeated in this example.

[0141] Optionally, the transmission device 906 is used to receive or send data via a network. Specific examples of the above-mentioned network may include a wired network and a wireless network. In one example, the transmission device 906 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices and routers via a network cable so as to communicate with the Internet or a local area network. In one example, the transmission device 906 is a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0142] In addition, the electronic device further comprises: a display 908 for displaying the processing result of the message of failed transmission; and a connection bus 910 for connecting various module components in the electronic device.

[0143] In other embodiments, the terminal device or server may be a node in a distributed system, wherein the distributed system may be a blockchain system, and the blockchain system may be a distributed system formed by connecting the multiple nodes through network communication. Among them, the nodes may form a peer-to-peer (P2P, Peer To Peer) network, and any form of computing device, such as a server, terminal and other electronic devices, may become a node in the blockchain system by joining the peer-to-peer network.

[0144] According to one aspect of the present application, a computer program product or computer program is provided, the computer program product or computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the above-mentioned message processing method, wherein the computer program is configured to execute the steps of any one of the above-mentioned method embodiments when it is run.

[0145] Optionally, in this embodiment, the computer-readable storage medium may be configured to store a computer program for performing the following steps:

[0146] S1, according to the received retry service request, store the attribute information of each message in the current message set that failed to be sent into the retry service database;

[0147] S2, obtaining a set of messages to be retransmitted that meet preset retransmission conditions based on the above attribute information;

[0148] S3, paging the message set to be resent based on snapshot paging to obtain multiple message paging subsets;

[0149] S4, resending the messages in the above-mentioned multiple message page subsets.

[0150] Optionally, in this embodiment, a person of ordinary skill in the art may understand that all or part of the steps in the various methods of the above embodiments may be completed by instructing hardware related to the terminal device through a program, and the program may be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc.

[0151] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0152] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage medium. Based on such understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling one or more computer devices (which can be personal computers, servers or network devices, etc.) to perform all or part of the steps of the methods of various embodiments of the present invention.

[0153] In the above embodiments of the present invention, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0154] In the several embodiments provided in the present application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are only schematic, for example, the division of units is only a logical function division, and there may be other division methods in actual implementation, for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0155] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0156] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0157] The above are only preferred embodiments of the present invention. It should be pointed out that, for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A message processing method, characterized in that: Applied to the Kafka system, the method includes: Use the load balancing component to configure retry service instances on multiple servers; select a server that meets the target requirements to receive the retry service request; When the message fails to be sent for the first time, the message is resent locally on the Kafka server. After the message fails to be sent continuously, the retry service stores the attribute information of each message in the current failed message set in the retry service database based on the received retry service request; the retry service is a service provided by a third-party library called locally, and the attribute information includes the number of retry transmissions and the transmission status; Acquire a set of messages to be resent that meet a preset resent condition based on the attribute information; Paging the message set to be resent based on snapshot paging to obtain multiple message paging subsets; Calling the application program interface of the Kafka system through a retry service to resend the messages in the plurality of message page subsets; When the first message in the plurality of message page subsets is sent successfully, updating the sending status of the first message to sent; When the sending of the second message in the plurality of message page subsets fails, the number of retries for sending the second message is increased and the second message is resent within a next resending time period.

2. The method according to claim 1, characterized in that The attribute information includes the creation time of the message that failed to be sent in the retry service database, and obtaining the set of messages to be resent that meet the preset resending conditions based on the attribute information includes: Determine the retransmission priority of each message in the set of messages that failed to be sent according to the creation time; A set of messages to be retransmitted that meet a preset retransmission condition is obtained according to the retransmission priority and based on the attribute information.

3. The method according to claim 1 or 2, characterized in that: Acquiring a set of messages to be retransmitted that meet a preset retransmission condition based on the attribute information includes: Get a set of messages to be resent that meet the preset resend conditions within each preset time interval.

4. The method according to claim 1 or 2, characterized in that: Acquiring a set of messages to be retransmitted that meet a preset retransmission condition based on the attribute information includes: Obtain a target message set that has not been successfully sent, whose number of retry sending times does not exceed a first threshold, and whose timeout period has not exceeded a preset timeout period; The target message set is determined as the message set to be resent.

5. The method according to claim 1, characterized in that: The attribute information also includes a message retransmission unique identifier, and the increasing the number of retry transmissions of the second message and retransmitting the second message within the next retransmission time period includes: According to the message retransmission unique identifier of the second message, the number of retry transmissions of each second message is increased, and the second message is retransmitted within the next transmission time period.

6. The method according to claim 1 or 5, characterized in that: The attribute information includes a retransmission mark, and the method further includes: When the number of retry transmissions of the third message in the plurality of message page subsets exceeds a first threshold, the retransmission flag corresponding to the third message is updated to stop retransmission.

7. A message processing device, characterized in that: Applied to Kafka system, including: Configuration unit, used to configure retry service instances on multiple servers using load balancing components; A selection unit, used for selecting a server that meets the target requirement to receive the retry service request; A storage unit is used to resend the message locally on the Kafka server when the message fails to be sent for the first time, and store the current failed message set and the attribute information of each message in the message set in a retry service database based on the received retry service request after the message fails to be sent continuously; the retry service is a service provided by a third-party library called locally, and the attribute information includes the number of retry transmissions and the transmission status; An acquisition unit, configured to acquire a set of messages to be retransmitted that meet a preset retransmission condition based on the attribute information; A paging unit, used for paging the message set to be resent based on snapshot paging to obtain multiple message paging subsets; A resending unit, configured to call the application program interface of the Kafka system through a retry service to resend the messages in the plurality of message page subsets; A first updating unit, configured to update the sending status of the first message to sent when the first message in the plurality of message page subsets is sent successfully; The adjusting unit is used to increase the number of retry transmissions of the second message and resend the second message in the next retransmission time period when the second message in the plurality of message page subsets fails to be transmitted.

8. An electronic device, comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 6 through the computer program.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein the program executes the method described in any one of claims 1 to 6 when executed.