A message processing method and apparatus

By building an independent message processing system based on MQ cluster, kafka and redis queues, the problem of message sending failure is solved, and data consistency and user experience are improved.

CN113064740BActive Publication Date: 2025-06-13BEIJING JINGDONG TUOXIAN TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202110363448.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-04-02
Publication Date
2025-06-13
Estimated Expiration
2041-04-02

AI Technical Summary

Technical Problem

In multi-party backend interaction scenarios, messages may still fail when multiple messages are sent, resulting in orders not being completed on time.

Method used

By combining MQ cluster, kafka architecture and redis queues, an independent message processing system is built to ensure the successful message transmission and reduce the coupling with the business side.

Benefits of technology

It realizes the guarantee of data consistency and successful message sending, reduces the development complexity of the business side, improves scalability and adaptability, and improves user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113064740B_ABST
    Figure CN113064740B_ABST
Patent Text Reader

Abstract

The present invention discloses a message processing method and apparatus, relating to the field of computer technology. The specific implementation of the method includes: receiving one or more messages to be processed sent by a service end; for each of the messages to be processed: constructing a plurality of first tasks corresponding to a plurality of message processing times corresponding to the message to be processed according to the message to be processed and a plurality of timers; the plurality of timers respectively indicate the plurality of message processing times; executing the first tasks according to the message processing times so as to send the processing results of the first tasks to a subscription end. This implementation can ensure data consistency, ensure successful message sending, is independent of the service end, reduces the coupling with the service end, has extremely strong scalability and adaptability, can be applied to various scenarios, and improves the user experience.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] In the scenario of message passing, there will be backend interactions among multiple parties. For example, for a payment order, the first backend that receives the order to be paid needs to monitor the payment status of the order. When the payment times out, it sends a message to cancel the order to the second backend corresponding to the service provider, or sends a payment success message to the second backend after the order payment is successful.

[0003] In the prior art, the above messages may fail to be sent. For example, when the first backend notifies the third backend of the message after the order payment is successful, there may be a situation where it still fails after multiple attempts, which may cause the order to not be completed on time. Summary of the Invention

[0004] In view of this, embodiments of the present invention provide a message processing method and apparatus, which can ensure data consistency, ensure successful message sending, are independent of the business side, reduce the coupling with the business side, have extremely strong scalability and adaptability, can be applied to various scenarios, and improve the user experience.

[0005] Furthermore, it enables the business side to focus on the development of its own business logic, improves its development efficiency, and can implement auxiliary functions such as message storage, notification status recording, retry strategy, event replay, and alarm.

[0006] Even further, it supports cross-platform and cross-language calls and calls of protocols such as HTTP and JSF, with strong flexibility.

[0007] To achieve the above object, according to one aspect of the embodiments of the present invention, a message processing method is provided, including:

[0008] Receiving one or more messages to be processed sent by a business side;

[0009] For each of the messages to be processed:

[0010] According to the message to be processed and multiple timers, constructing multiple first tasks corresponding to multiple message processing times of the message to be processed; the multiple timers respectively indicate the multiple message processing times;

[0011] According to the message processing time, executing the first task to send the processing result of the first task to a subscription side.

[0012] Optionally, the step of according to the message processing time, executing the first task and sending the processing result of the first task to a subscription side includes:

[0013] For the multiple first tasks, perform the following:

[0014] A: Determine the target message processing time that is closest to the current time among the multiple message processing times;

[0015] When the time indicated by the timer reaches the target message processing time, execute the target task corresponding to the target message processing time;

[0016] In response to a negative feedback from the subscriber for the target task, execute step A; in response to a positive feedback from the subscriber for the target task, determine that the message processing is successful.

[0017] Optionally, receive the message to be processed through an MQ cluster;

[0018] Through the first thread of the kafka cluster, generate one or more second tasks corresponding to the one or more messages to be processed respectively according to the message to be processed, and store the one or more second tasks in a first queue;

[0019] Through the second thread of the kafka cluster, extract the second tasks from the first queue according to a preset period, and generate multiple first tasks corresponding to the extracted second tasks.

[0020] Optionally, further include:

[0021] Pre-configure multiple groups of timers, each group of timers includes multiple timers, and the starting times corresponding to different groups of timers are different;

[0022] The generating of multiple first tasks corresponding to the extracted second tasks includes:

[0023] Determine the timer group corresponding to the second task according to the type of the message to be processed corresponding to the second task;

[0024] Generate multiple first tasks corresponding to the second task according to the multiple timers in the determined timer group.

[0025] Optionally, further include:

[0026] Receive the current message sent by the service end;

[0027] Determine whether there is a target task with the same identifier as the current message among the first task and the second task;

[0028] If so, delete the target task and generate a second task corresponding to the current message.

[0029] Optionally, it further includes:

[0030] In response to the negative feedback of the subscription end to the last target task among the multiple first tasks, store the message to be processed in the second queue;

[0031] When the total number of messages in the second queue is greater than a preset threshold, send a message about processing failure to the service end.

[0032] Optionally, it further includes:

[0033] In response to the message sent by the service end about re-executing the message to be processed, extract the message to be processed from the second queue, and construct multiple first tasks according to the message to be processed and multiple timers.

[0034] Optionally, when there are at least two timers among the multiple timers that indicate the same message processing time,

[0035] Set a lock for the at least two timers corresponding to the same message processing time, so that among the at least two first tasks respectively corresponding to the at least two timers at the same message processing time, only one first task is executed.

[0036] Optionally, the executed first task is a task with normal operation of the timer.

[0037] According to another aspect of the embodiments of the present invention, there is provided a message processing device, including:

[0038] A receiving module, configured to receive one or more messages to be processed sent by the service end;

[0039] A task construction module, configured to, for each of the messages to be processed:

[0040] Construct multiple first tasks respectively corresponding to multiple message processing times of the message to be processed according to the message to be processed and multiple timers; the multiple timers respectively indicate the multiple message processing times;

[0041] A task execution module, configured to execute the first task according to the message processing time, so as to send the processing result of the first task to the subscription end.

[0042] According to another aspect of the embodiments of the present invention, there is provided a message processing system, including:

[0043] A service end, a message processing end, and a subscription end;

[0044] The service end sends one or more messages to be processed to the message processing end;

[0045] After the message processing end receives the one or more messages to be processed, for each of the messages to be processed:

[0046] According to the message to be processed and multiple timers, construct multiple first tasks corresponding to multiple message processing times of the message to be processed; the multiple timers respectively indicate the multiple message processing times;

[0047] The message processing end also executes the first task according to the message processing time, so as to send the processing result of the first task to the subscription end.

[0048] According to still another aspect of the embodiments of the present invention, there is provided a message processing electronic device, including:

[0049] One or more processors;

[0050] A storage device for storing one or more programs,

[0051] When the one or more programs are executed by the one or more processors, the one or more processors implement the message processing method provided by the present invention.

[0052] According to still another aspect of the embodiments of the present invention, there is provided a computer-readable medium, on which a computer program is stored, and when the program is executed by a processor, the message processing method provided by the present invention is implemented.

[0053] One embodiment of the above invention has the following advantages or beneficial effects: Because the technical means of constructing an independent message processing system based on the combination of the MQ cluster, kafka architecture and redis queue is adopted, the technical problem that multiple back-end interactions may still fail after multiple transmissions, resulting in the business not being completed on time, is overcome. Furthermore, the technical effects of ensuring data consistency, ensuring successful message sending, being independent of the service end, reducing the coupling with the service end, having extremely strong scalability and adaptability, being applicable to various scenarios, and improving the user experience are achieved.

[0054] The further effects of the above non-conventional optional methods will be described in combination with specific embodiments below. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] The drawings are used to better understand the present invention and do not constitute an improper limitation to the present invention. Among them:

[0056] Figure 1 is an exemplary system architecture diagram suitable for applying the message processing method or message processing device of the embodiments of the present invention;

[0057] Figure 2 is a schematic diagram of the main process of the message processing method according to the embodiments of the present invention;

[0058] Figure 3 It is a schematic diagram of the main modules of the message processing device according to an embodiment of the present invention;

[0059] Fig. 4(a) is a schematic diagram of the message processing system according to an embodiment of the present invention Figure 1 ;

[0060] Fig. 4(b) is a schematic diagram of the message processing system according to an embodiment of the present invention Figure 2 ;

[0061] Figure 5 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing the embodiment of the present invention. Detailed implementation manners

[0062] The following describes exemplary embodiments of the present invention with reference to the accompanying drawings. Various details of the embodiments of the present invention are included to facilitate understanding, and they should be considered merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.

[0063] Figure 1 It shows an exemplary system architecture diagram suitable for applying to the message processing method or message processing device according to an embodiment of the present invention. As Figure 1 shown, the exemplary system architecture of the message processing method or message processing device according to an embodiment of the present invention includes:

[0064] As Figure 1 shown, the system architecture 100 may include a first server 101, a second server 102, third servers 103, 104, 105, and a network 106. The network 106 is used to provide a medium for communication links between the first server 101 and the second server 102, and between the first server 101 and the third servers 103, 104, 105. The network 106 may include various connection types, such as wired, wireless communication links, or fiber optic cables, etc.

[0065] The first server 101 receives the message to be processed sent by the second server 102, constructs a task according to the message to be processed, and sends the task to the third servers 103, 104, 105, so that the third servers 103, 104, 105 execute the task.

[0066] The first server 101 may be a server that provides various services, such as a background management server that provides support for processing the to-be-processed messages sent by the second server 102. The background management server may analyze and process data such as the received to-be-processed message requests, and feedback the processing results (such as whether the third servers 103, 104, and 105 have processed successfully) to the second server 102.

[0067] It should be noted that the message processing method provided by the embodiments of the present invention is generally executed by the server 101. Correspondingly, the message processing device is generally arranged in the server 101.

[0068] It should be understood that Figure 1 the numbers of the first server, the second server, the third server, and the network in

[0069] Figure 2 is a schematic diagram of the main process of the message processing method according to the embodiments of the present invention. As Figure 2 shown, the message processing method of the present invention includes:

[0070] Step S201, receiving one or more to-be-processed messages sent by the service side.

[0071] In a scenario of multi-party backend interaction, for example, in an effort delivery scenario, the subscription side receives the message of canceling the order sent by the service side and returns the result of whether the order is canceled successfully; or, the subscription side receives the message of notifying the payment result sent by the service side and returns the result of whether the notification is successful. However, there may be a situation where the message is still sent unsuccessfully after being sent multiple times. In order to obtain data consistency during message processing in the effort delivery scenario and ensure the successful sending of the message, the message processing method of the present invention can be used to receive one or more to-be-processed messages sent by the service side through the MQ cluster, and establish an execution task, so that the subscription side can receive the processing result of the task and use a retry mechanism for the negatively feedback processing result to ensure the successful sending of the message. The MQ cluster can process asynchronously to achieve traffic buffering and balance the pressure of subsequent process processing.

[0072] Step S202, for each of the to-be-processed messages: constructing a plurality of first tasks corresponding to a plurality of message processing times corresponding to the to-be-processed message according to the to-be-processed message and a plurality of timers; the plurality of timers respectively indicate the plurality of message processing times.

[0073] After receiving one or more messages to be processed sent by the service end, multiple timers are set for each message to be processed, and each timer corresponds to a message processing time. The multiple timers respectively indicate multiple message processing times. According to each message to be processed and its corresponding multiple message processing times, multiple first tasks corresponding to each received message to be processed are constructed; wherein, each first task includes the message to be processed and its corresponding message processing time.

[0074] Specifically, it includes:

[0075] The message processing method of the present invention is based on the kafka architecture. Therefore, when constructing the first task, through the first thread of the kafka cluster, according to one or more messages to be processed sent by the service end, one or more second tasks corresponding to the one or more messages to be processed are generated, and the one or more second tasks are stored in the first queue; wherein, each message to be processed may include one second task or multiple second tasks.

[0076] Through the second thread of the kafka cluster, multiple groups of timers are pre-configured. Each group of timers includes multiple timers, and the starting times corresponding to different groups of timers are different. According to the pre-configured multiple groups of timers, every preset period, the second tasks are extracted from the first queue; wherein, the execution time of the message to be processed corresponding to the second task is later than the current time.

[0077] According to the type of the message to be processed corresponding to the second task, the timer group corresponding to the second task is determined; wherein, the type of the message to be processed may include types such as immediate execution, periodic execution, or delayed execution, etc. Correspondingly, the starting time of the timer group corresponding to the message to be processed with immediate execution may be the current time, the timer group corresponding to the message to be processed with periodic execution may include multiple starting times, and the starting time of the timer group corresponding to the message to be processed with delayed execution may be a certain time greater than the current time.

[0078] According to the second task and the multiple message processing times in the determined timer group corresponding to the second task, multiple first tasks corresponding to the second task are generated.

[0079] Exemplarily, the same message processing time may include multiple identical first tasks. Each first task corresponds to a timer. A distributed lock is set for the multiple identical first tasks corresponding to the same message processing time, so that only one first task among the multiple identical first tasks is executed at the same message processing time, and the executed first task is the task for which the timer runs normally.

[0080] Exemplarily, to ensure the accuracy of the message sending result, prevent resource waste caused by repeated processing and possible result conflicts, after receiving the current message sent by the service end, scan the first task and the second task to determine whether there is a target task corresponding to the same service identifier as the current message. If so, delete the target task and generate a second task corresponding to the current message, or feedback the result of publishing conflict to the service end so that the service end can determine how to perform the next operation, etc.; if not, generate one or more second tasks corresponding to the current message and store the one or more second tasks in the first queue.

[0081] Step S203: Execute the first task according to the message processing time to send the processing result of the first task to the subscriber.

[0082] According to the message processing times respectively corresponding to multiple first tasks, execute the first tasks through the second thread of the kafka cluster, and send the processing results of the first tasks to the subscribers subscribing to the pending messages corresponding to the multiple first tasks.

[0083] Specifically, it includes:

[0084] For the constructed multiple first tasks, determine the target message processing time that is the closest to the current time among the multiple message processing times; when the time indicated by the timer reaches the target message processing time, execute the target task corresponding to the target message processing time, and send the processing result of the task to the subscriber subscribing to the pending message corresponding to the target task. Receive the feedback result from the subscriber. If the feedback result of the subscriber for the target task is negative feedback (such as: failure / time out), use the message processing time that is the closest to the target message processing time as the target message processing time and continue to execute; if the feedback result of the subscriber for the target task is positive feedback (such as: success), determine that the message processing is successful.

[0085] If the feedback result of the last target task among the multiple first tasks corresponding to the pending message received from the subscriber is negative feedback, store the pending message corresponding to the multiple first tasks in the second queue. The second thread of the kafka cluster regularly scans the second queue. When the total number of messages in the second queue is greater than the second preset length, send a message about processing failure to the service end, receive the message from the service end about re - executing the pending message, extract the pending message from the second queue, and regenerate one or more second tasks corresponding to the pending message through the first thread of the kafka cluster; or, receive the message from the service end about deleting the pending message and delete the pending message from the second queue.

[0086] In an embodiment of the present invention, by receiving one or more messages to be processed sent by a service end; for each of the messages to be processed: constructing a plurality of first tasks corresponding to a plurality of message processing times corresponding to the message to be processed according to the message to be processed and a plurality of timers; executing the first tasks according to the message processing times, and sending the processing results of the first tasks to a subscription end and other steps, data consistency can be ensured, the message sending can be ensured to be successful, and it is independent of the service end, with extremely strong scalability and adaptability, can be applied to various scenarios, and the user experience can be improved.

[0087] Figure 3 It is a schematic diagram of the main modules of a message processing device according to an embodiment of the present invention, as Figure 3 shown, the message processing device 300 of the present invention includes:

[0088] A receiving module 301, configured to receive one or more messages to be processed sent by a service end.

[0089] In order to obtain data consistency during message processing in an effort delivery scenario and ensure successful message sending, through the message processing method of the present invention, the receiving module 301 receives one or more messages to be processed sent by the service end through an MQ cluster, and establishes an execution task, so that the subscription end can receive the processing results of the task, and uses a retry mechanism for the processed results of negative feedback to ensure successful message sending. The MQ cluster can process asynchronously to achieve traffic buffering and balance the pressure of subsequent process processing.

[0090] A task construction module 302, configured to, for each of the messages to be processed: construct a plurality of first tasks corresponding to a plurality of message processing times corresponding to the message to be processed according to the message to be processed and a plurality of timers; the plurality of timers respectively indicate the plurality of message processing times.

[0091] After the receiving module 301 receives one or more messages to be processed sent by the service end, a plurality of timers are set for each message to be processed, each timer corresponds to a message processing time, and the plurality of timers respectively indicate a plurality of message processing times. The task construction module 302 constructs a plurality of first tasks corresponding to each received message to be processed according to each message to be processed and its corresponding plurality of message processing times; wherein, each first task includes the message to be processed and its corresponding message processing time.

[0092] A task processing module 303, configured to execute the first tasks according to the message processing times, so as to send the processing results of the first tasks to a subscription end.

[0093] The task processing module 303 executes the first tasks through the second thread of the kafka cluster according to the message processing times respectively corresponding to the multiple first tasks, and sends the processing results of the first tasks to the subscriber that subscribes to the to-be-processed messages corresponding to the multiple first tasks.

[0094] In the embodiment of the present invention, through modules such as the receiving module, the task construction module, and the task processing module, data consistency can be guaranteed, message sending can be ensured to be successful, and it is independent of the service side, reducing the coupling with the service side, and having extremely strong scalability and adaptability. It can be applied to various scenarios to improve the user experience.

[0095] FIG. 4(a) is a schematic diagram of a message processing system according to an embodiment of the present invention Figure 1 , FIG. 4(b) is a schematic diagram of a message processing system according to an embodiment of the present invention Figure 2 , as shown in FIGS. 4(a) and (b), the message processing system of the present invention includes:

[0096] A service side, a message processing side, and a subscriber side. By using the message processing method based on the combination of the MQ cluster, the kafka cluster, and the redis queue of the present invention, message sending can be ensured to be successful.

[0097] The service side applies for an access token to the message processing side, configures the callback address of the subscriber side, the retry policy, the consumption QPS (Query Per Second, an index used to measure service performance, which calculates how much traffic a specific query server processes within a specified time, and the formula is QPS = concurrent volume / average response time), etc., and reports the data of the to-be-processed messages to the message processing side through the publish service.

[0098] When the message processing side receives one or more to-be-processed messages sent by the service side, the broker in the first thread of the kafka cluster listens to one or more to-be-processed messages corresponding to the message topic subscribed by the subscriber side according to the message topic subscribed by the subscriber side. One or more producers receive one or more to-be-processed messages and synchronously send them to the MQ cluster. After success, it returns a publish success status to the service side. The MQ cluster is a message middleware that can be used for asynchronous processing to decouple from the service side, enabling the service side to focus on its own logical business development. As long as the to-be-processed messages are sent, the MQ cluster performs asynchronous processing after receiving the to-be-processed messages, achieving the effect of traffic peak shaving, buffering the impact of instantaneous or huge traffic, and reducing the write pressure on the storage middleware.

[0099] The MQ cluster receives one or more messages to be processed. After peak shaving, it pushes one or more messages to be processed to the message bucket of the Kafka cluster through the push mode or any other mode. The message bucket selects the MongoDB storage middleware and saves one or more messages to be processed as one or more second tasks according to the business identifier. For example, the business identifier can be b1, b2, bn, etc.; the business identifier and its corresponding message to be processed can be preset as needed. For example, the business identifier b001 is for payment, and the business identifier b002 is for sending text messages. Each message to be processed corresponds to an independent collection. Utilizing the automatic partitioning feature of MongoDB storage, it supports large - volume storage, and later, the storage middleware can be switched to any storage.

[0100] The consumer in the second thread of the Kafka cluster scans the second tasks in the message bucket regularly through the timer in it, and extracts one or more second tasks whose execution time (execTime) is within a preset time period after the current time from the second tasks; after the timer extracts the second tasks, it sets multiple timers for one or more second tasks and constructs multiple first tasks according to the second tasks and multiple timers. The first task represents processing the message at the message processing time indicated by the timer. For example, the task identifier of the first task can be b1_timer_1, b1_timer_2, b1_timer_n, b2_timer_1, b2_timer_n, etc.; among them, each second task sets multiple timers at the same time. For example, the task identifier of the corresponding first task can be b1_timer_1_1, b1_timer_1_2, b1_timer_1_n, etc. to prevent the single - point failure problem of a single timer, resulting in the failure of processing at that time, and a distributed lock lock is set to ensure that only one timer works / executes at the same time.

[0101] After constructing the first task, the timer puts multiple first tasks into the first queue and records the offset of this scan (for example, business identifier + timestamp); among them, the first queue can be the readyqueue of the redis-based list service, which is used to store messages in the preparation stage; each message to be processed corresponds to a redis queue, and each queue starts an independent redis client for listening. For example, the task identifiers in the ready queue can be b1_queue, b2_queue, etc. Multiple first tasks in the ready queue dequeue when their timer times arrive, create asynchronous consumption threads to execute the first tasks, and notify the subscription end of the execution results of the first tasks. Before the timer extracts the messages to be processed by scanning the message bucket, it needs to detect whether the queue length of the first queue exceeds the first preset length. If so, it returns and waits for the next scan; if not, it extracts the messages to be processed.

[0102] When the asynchronous consumption thread executes the first task, according to the task identifier of the first task, query the callback addresses of one or more subscription ends subscribed to the corresponding task identifier, and call the notification service to notify the subscription end of the execution result of the first task according to the callback addresses of the subscription ends; among them, when sending notifications to one or more subscription ends, throttling can be performed through the incr service of redis to further ensure the normal sending of notifications.

[0103] Receive the feedback result from the subscription end. If the feedback result is a positive return, call the log service to record, and delete the set data of the corresponding message to be processed in mongodb according to the business identifier of the message to be processed; if the feedback result is a negative feedback, call the log service to record, increment the retry count of the message to be processed, and determine whether the retry count exceeds the preset retry count. If so, store the message to be processed in the second queue, where the second queue can be a private message queue; if not, update the retry count and retry time of the message to be processed in mongodb and save it, so that the consumer can extract the message to be processed again.

[0104] After storing the message to be processed with a negative feedback result in the second queue, the consumer periodically scans the second queue to determine whether the length of the second queue exceeds the second preset length. If so, trigger the alarm service to alarm the business end, so that the business end can choose to re-push the message to be processed corresponding to the second queue to further ensure the successful sending of the message and ensure data consistency; or, the business end can choose to delete and re-send the message to be processed corresponding to the second queue to further ensure the successful sending of the message and ensure data consistency.

[0105] In the embodiments of the present invention, through the message processing system, data consistency can be ensured, message sending can be guaranteed to be successful, and it is independent of the service side, reducing the coupling with the service side, and having extremely strong scalability and adaptability. It can be applied to various scenarios to improve the user experience.

[0106] Figure 5 It is a schematic structural diagram of a computer system of a terminal device suitable for implementing the embodiments of the present invention. As Figure 5 shown, the computer system 500 of the terminal device in the embodiments of the present invention includes:

[0107] A central processing unit (CPU) 501, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 502 or the program loaded from the storage section 508 into the random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the system 500 are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0108] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc. and a speaker, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, a modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as required. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as required so that the computer program read from it can be installed into the storage section 508 as required.

[0109] Specifically, according to the embodiments disclosed in the present invention, 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 invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes program codes for performing the methods shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication section 509, and / or installed from the removable medium 511. When the computer program is executed by the central processing unit (CPU) 501, the above functions defined in the system of the present invention are executed.

[0110] It should be noted that the computer-readable medium shown in the present invention can be a computer-readable signal medium, a computer-readable storage medium, or any combination of the above two. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of a computer-readable storage medium can 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), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium can be any tangible medium that contains or stores a program, and this program can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present invention, a computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, in which computer-readable program code is carried. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, and this computer-readable medium can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on a computer-readable medium can be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0111] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagram can represent a module, a program segment, or a part of code, and the above module, program segment, or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram or flowchart, and the combination of blocks in the block diagram or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.

[0112] The modules involved in the embodiments of the present invention can be implemented in software or in hardware. The described modules can also be provided in a processor. For example, it can be described as: a processor includes a receiving module, a task construction module, and a task execution module. Among them, the names of these modules do not constitute a limitation to the module itself in some cases. For example, the receiving module can also be described as "the module for receiving the messages to be processed sent by the service end".

[0113] As another aspect, the present invention also provides a computer-readable medium, which can be included in the device described in the above embodiments; or can exist alone without being assembled into the device. The above computer-readable medium carries one or more programs. When the one or more programs are executed by the device, the device includes: receiving one or more messages to be processed sent by the service end; for each of the messages to be processed: constructing, according to the message to be processed and multiple timers, multiple first tasks corresponding to multiple message processing times respectively corresponding to the message to be processed; the multiple timers respectively indicating the multiple message processing times; executing the first tasks according to the message processing times to send the processing results of the first tasks to the subscription end.

[0114] According to the technical solution of the embodiments of the present invention, it can ensure data consistency, ensure successful message sending, be independent of the service end, reduce the coupling with the service end, have extremely strong scalability and adaptability, can be applied to various scenarios, and improve the user experience.

[0115] Furthermore, it enables the service end to focus on the development of its own business logic, improves its development efficiency, and can implement auxiliary functions such as message storage, notification status recording, retry strategy, event replay, and alarm.

[0116] Furthermore, it supports cross-platform and cross-language calls and calls of protocols such as HTTP and JSF, and has strong flexibility.

[0117] The above specific embodiments do not constitute a limitation to the protection scope of the present invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A message processing method, characterized in that, it includes: Receiving one or more messages to be processed sent by the service end; For each of the messages to be processed: Setting multiple timers, each timer corresponding to a message processing time; According to the message to be processed and the multiple timers, constructing multiple first tasks corresponding to the multiple message processing times respectively corresponding to the message to be processed; the multiple timers respectively indicate the multiple message processing times; Specifically, according to the message to be processed, generating one or more second tasks respectively corresponding to the one or more messages to be processed, and storing the one or more second tasks in a first queue; According to a preset period, extracting the second tasks from the first queue, and generating multiple first tasks corresponding to the extracted second tasks; According to the message processing time, executing the first task to send the processing result of the first task to the subscription end; Pre-configuring multiple groups of timers, each group of timers including multiple timers, and the starting times corresponding to different groups of timers being different; The generating multiple first tasks corresponding to the extracted second tasks includes: Determining the timer group corresponding to the second task according to the type of the message to be processed corresponding to the second task; Generating multiple first tasks corresponding to the second task according to the multiple timers in the determined timer group.

2. The method according to claim 1, characterized in that, The executing the first task according to the message processing time and sending the processing result of the first task to the subscription end includes: For the multiple first tasks, performing: A: Determining the target message processing time closest to the current time among the multiple message processing times; When the time indicated by the timer reaches the target message processing time, executing the target task corresponding to the target message processing time; In response to a negative feedback from the subscription end for the target task, performing step A; in response to a positive feedback from the subscription end for the target task, determining that the message processing is successful.

3. The method according to claim 1, characterized in that, Receiving the message to be processed through an MQ cluster; Through the first thread of a kafka cluster, generating one or more second tasks respectively corresponding to the one or more messages to be processed according to the message to be processed, and storing the one or more second tasks in a first queue; Through the second thread of the kafka cluster, extracting the second tasks from the first queue according to a preset period, and generating multiple first tasks corresponding to the extracted second tasks.

4. The method according to claim 3, characterized in that, It further includes: Receiving the current message sent by the service end; Determining whether there is a target task corresponding to the same identifier as the current message among the first task and the second task; If so, deleting the target task and generating a second task corresponding to the current message.

5. The method according to claim 2, characterized in that, It further includes: In response to the negative feedback of the subscription end to the last target task among the multiple first tasks, store the message to be processed in the second queue; When the total number of messages in the second queue is greater than a preset threshold, send a message indicating processing failure to the service end.

6. The method according to claim 5, wherein, further comprising: In response to the message sent by the service end to re-execute the message to be processed, extract the message to be processed from the second queue, and construct multiple first tasks according to the message to be processed and multiple timers.

7. The method according to claim 1, wherein, when there are at least two timers among the multiple timers that indicate the same message processing time, set a lock for the at least two timers corresponding to the same message processing time, so that among the at least two first tasks respectively corresponding to the at least two timers at the same message processing time, only one first task is executed.

8. The method according to claim 7, wherein, the executed first task is a task with normal operation of the timer.

9. A message processing device, wherein, comprising: a receiving module, configured to receive one or more messages to be processed sent by the service end; a task construction module, configured to, for each of the messages to be processed: set multiple timers, each timer corresponding to a message processing time; construct multiple first tasks corresponding to the multiple message processing times respectively corresponding to the message to be processed according to the message to be processed and the multiple timers; the multiple timers respectively indicate the multiple message processing times; specifically, generate one or more second tasks respectively corresponding to the one or more messages to be processed according to the message to be processed, and store the one or more second tasks in the first queue; extract the second task from the first queue according to a preset period, and generate multiple first tasks corresponding to the extracted second task; a task execution module, configured to execute the first task according to the message processing time, so as to send the processing result of the first task to the subscription end; pre-configure multiple groups of timers, each group of timers including multiple timers, and the start times corresponding to different groups of timers are different; the task construction module is further configured to: determine the timer group corresponding to the second task according to the type of the message to be processed corresponding to the second task; generate multiple first tasks corresponding to the second task according to the multiple timers in the determined timer group.

10. A message processing system, wherein, comprising: a service end, a message processing end and a subscription end; the service end sends one or more messages to be processed to the message processing end; after receiving the one or more messages to be processed, the message processing end, for each of the one or more messages to be processed: set multiple timers, each timer corresponding to a message processing time; Construct a plurality of first tasks corresponding to the respective message processing times of the message to be processed according to the message to be processed and a plurality of timers; the plurality of timers respectively indicate the plurality of message processing times; Specifically, generate one or more second tasks corresponding to the one or more messages to be processed according to the message to be processed, and store the one or more second tasks in a first queue; Extract the second tasks from the first queue according to a preset period, and generate a plurality of first tasks corresponding to the extracted second tasks; The message processing end further executes the first tasks according to the message processing times to send the processing results of the first tasks to the subscription end; The message processing end further determines a timer group corresponding to the second task according to the type of the message to be processed corresponding to the second task; and generates a plurality of first tasks corresponding to the second task according to the plurality of timers in the determined timer group.

11. A message processing electronic device, Characterized in that, Comprising: One or more processors; A storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1-8.

12. A computer-readable medium having a computer program stored thereon, Characterized in that, The program, when executed by a processor, implements the method according to any one of claims 1-8.

Citation Information

Patent Citations

  • Business data processing method and device

    CN111367688A