Message event delay processing method and device, computer device, and storage medium
Patent Information
- Application Number
- CN202211582644.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-09
- Publication Date
- 2026-10-09
- Estimated Expiration
- 2042-12-09
AI Technical Summary
[0003]对于这种延时任务,现在的方案是采用定时器完成,或者借助第三方消息中间件(如消息队列)的延迟消费能力来达到目标,这样做的好处是无需关注其任务调度的具体实现逻辑,只用关注自身的业务本身,但是会带来以下问题:1、需要依赖第三方开源包,出现问题时需要翻阅第三方代码,定位较为麻烦,且当项目框架选型不兼容第三方开源包,将无法使用;2、一个项目往往需要处理很多业务逻辑,待执行的事件(即延时处理的任务)类型也比较多,如执行频率不同的事件等,不同的任务对处理时间的要求是不同的,所需要的资源也不一样,而现有的技术方案还没有实现对不同的延时任务采用不同的处理方案,这会造成系统资源的浪费,降低系统处理延时任务的效率
[0039] Compared with the prior art, the embodiments of this application have the following advantages: This application parses the acquired message event information and encapsulates it according to a preset message format to obtain the message event's delay processing time and the formatting parameters of the business logic function. Then, it selects different message event storage modes according to the message event's delay processing time and stores them accordingly. When the delay processing time is reached, the message event storage mode reads the formatting parameters and passes them to the event executor to call the corresponding business logic function for execution. This achieves the processing of the corresponding message event without relying on third-party message middleware or resource packages. In the same system, different message event storage modes are used for message events with different delay processing times, which can meet the different resource requirements for processing different message events. This not only improves the system's flexibility and reliability but also saves resources. Furthermore, the different business processing logics of different message events are executed through a unified event executor, which improves the versatility of message event business processing, reduces resource consumption, and thus improves the system's efficiency in processing delayed task events.
Smart Images

Figure CN115794439B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of software development technology, and in particular to methods, apparatus, computer devices, and readable storage media for delayed processing of message events. Background Technology
[0002] With the rapid development of internet businesses, many applications have developed business needs such as automatically processing task B after a delay in performing a pre-task A, or performing a certain task at a future point in time. These are called delayed tasks. For example, in the financial management or insurance field, in order to attract customers in the early stages of the launch of financial management or insurance products, a one-week free trial is offered. Before the end of the trial period, users need to be actively reminded to convert the trial product to commercial use.
[0003] For such delayed tasks, current solutions involve using timers or leveraging the delayed consumption capabilities of third-party message middleware (such as message queues). The advantage of this approach is that it eliminates the need to focus on the specific implementation logic of task scheduling, allowing attention solely to the core business logic. However, this approach introduces the following problems: 1. It relies on third-party open-source packages, requiring extensive research into their code to pinpoint issues, which is cumbersome. Furthermore, if the project framework is incompatible with these packages, they cannot be used. 2. A project often handles numerous business logics, resulting in a variety of events (i.e., delayed tasks) with varying execution frequencies. Different tasks have different processing time requirements and resource needs. Existing technical solutions do not yet implement different processing methods for different delayed tasks, leading to wasted system resources and reduced efficiency in handling delayed tasks. Summary of the Invention
[0004] The purpose of this application is to provide a method, apparatus, computer device, and readable storage medium for delaying message events, which can adopt different delay processing schemes for different message event delay tasks, save system resources, and improve the efficiency of the system in processing delay tasks.
[0005] To address the aforementioned technical problems, this application provides a method for delaying message events, employing the following technical solution:
[0006] Retrieve message event information;
[0007] The message time information is parsed to obtain the parsed message event information;
[0008] The parsed message event information is encapsulated according to a preset message format to obtain formatting parameters, which include delay processing time and business logic functions.
[0009] Obtain a preset message event storage mode corresponding to the delay processing time of the message event, and store the formatting parameters of the message event based on the message event storage mode;
[0010] When the delay time for the message event is reached, the event executor is invoked, and the business logic function is executed according to the event executor to process the corresponding message event.
[0011] Furthermore, the step of obtaining a preset message event storage mode corresponding to the delay processing time of the message event includes:
[0012] Confirm the preset delay time level to which the delay processing time belongs. The preset delay time level includes low delay time level, medium delay time level and high delay time level.
[0013] If the delay processing time of the message event is in the low latency level, the first message event storage mode shall be selected first.
[0014] If the delay processing time of the message event is in the medium delay time level, the second message event storage mode shall be selected first.
[0015] If the delay processing time of the message event is in the high latency level, the third message event storage mode shall be selected first.
[0016] Furthermore, the first message event storage mode is a linked list-based memory mode, where the linked list includes a preset number of memory nodes, and the formatting parameters for storing the message event based on the selected message event storage mode include:
[0017] If the first message event storage mode is selected, the delay processing time of the message event is moduloed and remaindered based on the number of memory nodes in its linked list to obtain the corresponding operation result;
[0018] The position of the formatting parameters of the message event in the linked list of the first message event storage mode is determined based on the operation result and then stored.
[0019] Furthermore, the formatting parameters for storing the message event based on the message event storage mode also include:
[0020] If the second message event storage mode is selected, the formatting parameters of the message event will be stored after expiration monitoring through the Redis cache database.
[0021] Furthermore, the formatting parameters for storing the message event based on the message event storage mode also include:
[0022] If the third message event storage mode is selected, the formatting parameters of the message event are persistently stored through an external database.
[0023] Furthermore, the step of obtaining a preset message event storage mode corresponding to the delay processing time of the message event also includes:
[0024] If the formatting parameters of the message event also include the importance level of the message event, then the third message event storage mode, the second message event storage mode, and the first message event storage mode are selected in sequence according to the importance level.
[0025] Furthermore, the step of invoking the event executor and executing the business logic function according to the event executor to process the corresponding message event when the delay processing time of the message event is reached includes:
[0026] When the delay processing time of a message event is reached, the message event storage mode retrieves the formatting parameters of the corresponding message event and sends the formatting parameters of the message event to the event executor.
[0027] The event executor parses the formatting parameters of the message event and calls the business logic function;
[0028] The business logic function is executed to process the corresponding message event.
[0029] To address the aforementioned technical problems, embodiments of this application also provide a message event delay processing apparatus, comprising:
[0030] The acquisition module is used to obtain message event information;
[0031] The parsing module is used to parse the message time information to obtain the parsed message event information;
[0032] The encapsulation module is used to encapsulate the parsed message event information according to a preset message format to obtain formatting parameters, which include delay processing time and business logic functions.
[0033] The storage module is used to obtain a preset message event storage mode corresponding to the delay processing time of the message event, and to store the formatting parameters of the message event based on the message event storage mode;
[0034] The execution module is used to call the event executor when the delay processing time of the message event is reached, and execute the business logic function according to the event executor to realize the processing of the corresponding message event.
[0035] To address the aforementioned technical problems, this application also provides a computer device that employs the following technical solution:
[0036] The computer device includes a memory and a processor. The memory stores computer-readable instructions, and the processor executes the computer-readable instructions to implement the steps of the delayed processing method for the message event.
[0037] To address the aforementioned technical problems, this application also provides a computer-readable storage medium, employing the technical solution described below:
[0038] The computer-readable storage medium stores computer-readable instructions, which, when executed by a processor, implement the steps of the delayed message event processing method.
[0039] Compared with the prior art, the embodiments of this application have the following advantages: This application parses the acquired message event information and encapsulates it according to a preset message format to obtain the message event's delay processing time and the formatting parameters of the business logic function. Then, it selects different message event storage modes according to the message event's delay processing time and stores them accordingly. When the delay processing time is reached, the message event storage mode reads the formatting parameters and passes them to the event executor to call the corresponding business logic function for execution. This achieves the processing of the corresponding message event without relying on third-party message middleware or resource packages. In the same system, different message event storage modes are used for message events with different delay processing times, which can meet the different resource requirements for processing different message events. This not only improves the system's flexibility and reliability but also saves resources. Furthermore, the different business processing logics of different message events are executed through a unified event executor, which improves the versatility of message event business processing, reduces resource consumption, and thus improves the system's efficiency in processing delayed task events. Attached Figure Description
[0040] To more clearly illustrate the solutions in this application, the accompanying drawings used in the description of the embodiments of this application will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0041] Figure 1 This is an exemplary system architecture diagram to which this application can be applied;
[0042] Figure 2 This is a flowchart of an embodiment of the message event delay processing method according to this application;
[0043] Figure 3This is a schematic diagram of a structure according to an embodiment of the first message event storage mode of this application;
[0044] Figure 4 This is a schematic diagram of the structure of an embodiment of the message event delay processing apparatus according to this application;
[0045] Figure 5 This is a schematic diagram of the structure of one embodiment of the computer device according to this application. Detailed Implementation
[0046] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains; the terminology used herein in the specification of the application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application; the terms "comprising" and "having," and any variations thereof, in the specification, claims, and foregoing drawings of this application, are intended to cover non-exclusive inclusion. The terms "first," "second," etc., in the specification, claims, or foregoing drawings of this application are used to distinguish different objects, not to describe a particular order.
[0047] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0048] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings.
[0049] like Figure 1 As shown, system architecture 100 may include terminal devices 101, 102, and 103, a network 104, and a server 105. Network 104 serves as the medium for providing communication links between terminal devices 101, 102, and 103 and server 105. Network 104 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.
[0050] Users can use terminal devices 101, 102, and 103 to interact with server 105 via network 104 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 101, 102, and 103, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social media platform software, etc.
[0051] Terminal devices 101, 102, and 103 can be various electronic devices with displays and support web browsing, including but not limited to smartphones, tablets, e-book readers, MP3 players (pertsGroup Audio Layer III, Dynamic Picture Experts Compression Standard Audio Layer 3), MP4 players (perts Group Audio Layer IV, Dynamic Picture Experts Compression Standard Audio Layer 4), laptops, and desktop computers, etc.
[0052] Server 105 can be a server that provides various services, such as a backend server that supports the pages displayed on terminal devices 101, 102, and 103.
[0053] It should be noted that the message event delay processing method provided in the embodiments of this application is generally executed by the server / terminal device, and correspondingly, the message event delay processing device is generally set in the server / terminal device.
[0054] It should be understood that Figure 1 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.
[0055] Continue to refer to Figure 2 The diagram illustrates a flowchart of an embodiment of a method for delaying message events according to this application. The method for delaying message events includes the following steps:
[0056] Step 201: Obtain message event information.
[0057] In this embodiment, the message event delay processing method runs on an electronic device (e.g., Figure 1 The server / terminal device shown can receive user-input message events or message events sent by other events (or tasks) via wired or wireless connections. It should be noted that the aforementioned wireless connection methods may include, but are not limited to, 3G / 4G / 5G connections, WiFi connections, Bluetooth connections, WiMAX, Zigbee connections, UWB (ultrawideband) connections, and other currently known or future wireless connection methods.
[0058] Step 202: Parse the message time information to obtain the parsed message event information;
[0059] Step 203: Encapsulate the parsed message event information according to a preset message format to obtain formatting parameters, which include delay processing time and business logic functions.
[0060] In this embodiment, the aforementioned message event information can be input by the user through a front-end or other means, and sent to a remote or local device running the delayed processing method for the aforementioned message event via a network or local interface. Examples include event information generated by a scheduled email sending task, or event information sent when events within a system trigger each other, such as an order cancellation event triggered by a user placing an order but not paying within a certain period in an ordering system. The aforementioned front-end includes, but is not limited to, web page front-ends, application programs (APPs), and web-based applications. Specifically, the aforementioned message event information includes data such as event ID (event identifier), event name, delayed processing time, importance level, user data, and business logic function (i.e., the interface that executes the event). This data is then extracted from the original message event information and encapsulated according to a preset message format, such as encapsulating this data into key-value pairs in JSON format: {eventId:1000, eventName:“Cancel Order”, delayTime:2000, data:{}, importanceLevel:2, executeType:“invoke”}.
[0061] Step 204: Obtain a preset message event storage mode corresponding to the delay processing time of the message event, and store the formatting parameters of the message event based on the message event storage mode.
[0062] In this embodiment, when the business logic being processed includes a variety of event types, such as events with long delays and low execution frequency, tasks with short delays, large numbers, and high execution frequency, as well as other events that fall between the two types mentioned above, different processing schemes need to be adopted according to the delay processing time, frequency, and importance requirements of different events and tasks. Different system resources need to be called accordingly in order to effectively improve the system's processing capacity and save system resources.
[0063] Furthermore, the step of obtaining a preset message event storage mode corresponding to the delay processing time of the message event includes:
[0064] Confirm the preset delay time level to which the delay processing time belongs, the preset delay time level includes low delay time level, medium delay time level and high delay time level;
[0065] If the delay processing time of the message event is in the low latency level, the first message event storage mode shall be selected first.
[0066] If the delay processing time of the message event is in the medium delay time level, the second message event storage mode shall be selected first.
[0067] If the delay processing time of the message event is in the high latency level, the third message event storage mode shall be selected first.
[0068] In this embodiment of the invention, a delay level parameter delayLevel can be preset according to the actual needs of the project business. This parameter is used to divide the delay processing time level of business events, such as three levels: 0, 1, and 2, which correspond to low delay level, medium delay level, high delay level, etc. The higher the level, the longer the delay processing time of the event. Specifically, the low delay level can represent a delay level of seconds to minutes, the medium delay level can represent a delay level of minutes to hours, and the high delay level can represent a delay level of hours to days. Of course, the delay level can be divided and further subdivided as needed; this is just an illustration. Different delay levels require different resources and require different processing methods. Therefore, it is necessary to first determine the delay level parameter `delayLevel` to which the delay time of the aforementioned message event belongs, and then select different processing schemes based on `delayLevel`. That is, for message events with low delay times, the first message event storage mode based on memory is preferred; for message events with medium delay times, the second message event storage mode based on caching is preferred; and for message events with high delay times, the third message event storage mode based on database is preferred. In this embodiment, three schemes are designed for the above three delay levels `delayLevel` to meet the processing speed and resource requirements of different delayed message events. Different processing schemes are adopted for different delayed events without relying on third-party message middleware, thereby improving the efficiency of the system in handling delayed tasks.
[0069] Furthermore, the first message event storage mode is a linked list-based memory mode, where the linked list includes a preset number of memory nodes, and the formatting parameters for storing the message event based on the selected message event storage mode include:
[0070] If the first message event storage mode is selected, the delay processing time of the message event is moduloed and remaindered based on the number of memory nodes in its linked list to obtain the corresponding operation result;
[0071] The position of the formatting parameters of the message event in the linked list of the first message event storage mode is determined based on the operation result and then stored.
[0072] In this embodiment, the aforementioned memory-based first message event storage mode can be implemented using a linked list data structure. Specifically, it can be implemented using a singly linked circular list with its head and tail connected, a doubly linked (circular) list, etc., and its specific structure is as follows: Figure 3 As shown, the linked list includes multiple (60 in this embodiment) randomly allocated memory nodes (memory blocks), that is, the number of memory nodes is 60. The memory nodes are connected end to end to form a linked list loop of length 60 and are sequentially marked as 0, 1, 2...59. The memory nodes contain address segments pointing to the upper and lower nodes and data segments storing the formatted parameters of the aforementioned message events (i.e., Figure 3 In this context, the data segment can store specific parameter data or store the addresses of parameter data in the form of an array. Specifically, when the first message event storage mode is selected, the delay processing time of the message event is divided by the number of memory nodes in the above linked list, and then modulo and remainder calculations are performed. The modulo result is used as the storage location of the message event in the above linked list (i.e., which node), and the remainder result is used as the storage location of the message event in the node. For example, if the delay processing time of the message event is 5.5 seconds, the modulo result of 5.5 divided by 60 is 0, and the remainder result, after removing the decimal point, is 9. Therefore, the storage location of the message event in the above linked list is the index. A node is denoted as 0 (node 0), and its data segment is 9 or the ninth position in the array. For example, if the message event's delay is 61 seconds, the modulo of 61 to 60 is 1, and the remainder (after removing the decimal point) is 10. Therefore, the message event's storage location in the linked list is the node denoted as 1 (node 1), and its data segment is 10 or the tenth position in the array. After determining the message event's storage location in the linked list based on the above steps, the message event's formatting parameters are directly written into the corresponding memory space. Then, a scanning thread can scan the linked list of the 60 memory nodes at regular intervals, such as 1 second. When the delay time of a certain event is reached, the node containing the event is scanned to obtain the specific storage location of the event at that node, and then the event's formatting parameters are directly read from the corresponding memory. Therefore, the above-mentioned linked list-based first message event storage mode saves and retrieves data by reading and writing memory, which can speed up data processing and is beneficial for the rapid processing of short-delay, high-frequency message events.
[0073] Furthermore, the formatting parameters for storing the message event based on the message event storage mode also include:
[0074] If the second message event storage mode is selected, the formatting parameters of the message event will be stored after expiration monitoring through the Redis cache database.
[0075] In this embodiment of the invention, when the delay processing time of the aforementioned message event is at the medium delay level, such as 85 minutes, the second message event storage mode based on Redis caching is preferentially selected. Specifically, it is implemented based on Redis's expiration monitoring method, that is, the formatting parameters of the message event to be delayed are encapsulated and stored in the Redis cache database, and its expiration time is set to the delay processing time of the message event. The message event is monitored through the Redis expiration event monitoring mechanism. When a Redis expiration event processing notification is received, the execution of the expired message event is automatically triggered. When Redis is unavailable or there are too many pending events causing its efficiency to be low, the message event can also be transferred to the aforementioned first message event storage mode, thereby realizing safe and fast processing of message events at the medium delay level.
[0076] Furthermore, the formatting parameters for storing the message event based on the message event storage mode also include:
[0077] If the third message event storage mode is selected, the formatting parameters of the message event are persistently stored through an external database.
[0078] In this embodiment of the invention, when the delay processing time of the aforementioned message event belongs to the high latency level, such as a delay processing time of 25 hours, the second message event storage mode based on an external database is preferentially selected. Specifically, the aforementioned message events are persistently saved, that is, the formatting parameters of the message events in memory are written to the database for permanent storage through snapshots or recording data operation logs. Then, a scanning program is started to poll and traverse the database, and the formatting parameters of the message events that have reached their execution time are read out and processed subsequently. For example, a resident scanning thread can be started in the background to query the database every second to determine whether there are message events in the database table whose delay processing time exceeds the current time. If there are, the message event is retrieved and handed over to the subsequent executor for execution; otherwise, the above operation is continued in the next second. The aforementioned second message event storage mode based on an external database can store message events with long delay processing times and low execution frequency for a long time, ensuring that message events will not be lost due to system crashes, and has high security.
[0079] It should be noted that the step of obtaining the preset message event storage mode corresponding to the delay processing time of the message event further includes:
[0080] If the formatting parameters of the message event also include the importance level of the message event, then the third message event storage mode, the second message event storage mode, and the first message event storage mode are selected in sequence according to the importance level.
[0081] In this embodiment of the invention, the formatting parameters of the message events may also include the importance level of the message events, which can be manually set or automatically set by the program. This importance level can be represented by numbers 0, 1, 2, etc. Higher numbers indicate higher importance and require a certain level of security, such as for emails or express delivery orders. If the formatting parameters of the obtained message events also include an importance level, the message event storage mode is selected based on the importance level. Message events with high importance levels preferentially select the third message event storage mode, which offers higher security. Message events with low importance levels can select the second message event storage mode based on caching and / or the first message event storage mode based on memory. This allows for a comprehensive consideration of the message event's latency and importance level, selecting the most suitable storage method based on the nature of different events to meet the needs of different task event processing, thereby improving the system's flexibility and reliability.
[0082] Step 205: When the delay processing time of the message event is reached, the event executor is invoked, and the business logic function is executed according to the event executor to realize the processing of the corresponding message event.
[0083] Furthermore, the step of invoking the event executor and executing the business logic function according to the event executor to process the corresponding message event when the delay processing time of the message event is reached includes:
[0084] When the delay processing time of a message event is reached, the message event storage mode retrieves the formatting parameters of the corresponding message event and sends the formatting parameters of the message event to the event executor.
[0085] The event executor parses the formatting parameters of the message event and calls the business logic function;
[0086] The business logic function is executed to process the corresponding message event.
[0087] In this embodiment, regardless of which of the three message event storage modes is selected to store the formatting parameters of the message event, when the message event's delay processing time is reached, the message event storage mode will read the corresponding message event's formatting parameters from memory, cache, or database, and send the message event's formatting parameters to an independent event executor that is independent of the storage mode. After being parsed by the event executor, the corresponding business logic function is called to execute the subsequent business logic. Specifically, after the event executor receives the relevant parameters of a message event, it generates a corresponding entity class using the reflection principle of Java programs to override the invoke method of the event executor interface class. This method initiates the event handling program content, i.e., the business logic function that handles subsequent transactions, which is the interface for executing the event in the executeType parameter of the message event. When executing an event, the event executor obtains the specific event ID from the format parameters of the message event and passes the user data (i.e., data:{} in the format parameters) to the invoke method of the aforementioned business logic function. Then, it calls the invoke method of the business logic function to execute the task specified by the event ID, thus executing the specific business logic and realizing the processing of the corresponding message event. This allows for different business processing logics for different message events without needing to concern themselves with the storage mode (i.e., regardless of which storage mode is selected), improving the versatility of message event business processing, reducing resource consumption, and further improving system efficiency.
[0088] In summary, this application parses the acquired message event information and encapsulates it according to a preset message format to obtain the message event's delay processing time and the formatting parameters of the business logic function. Then, it selects different message event storage modes based on the message event's delay processing time and stores them accordingly. When the delay processing time is reached, the message event storage mode reads the formatting parameters and passes them to the event executor to call the corresponding business logic function for execution. This achieves the processing of corresponding message events without relying on third-party message middleware or resource packages. By using different message event storage modes for message events with different delay processing times within the same system, it can meet the different resource requirements for processing different message events, improving the system's flexibility and reliability while saving resources. Furthermore, the different business processing logics for different message events are uniformly executed through an independent event executor, improving the versatility of message event business processing, reducing resource consumption, and thus improving the system's efficiency in processing delayed task events.
[0089] The embodiments of this application can acquire and process relevant data based on artificial intelligence technology. Artificial intelligence (AI) refers to the theories, methods, technologies, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to obtain optimal results.
[0090] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by instructing related hardware through computer-readable instructions. These computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above methods. The aforementioned storage medium can be a non-volatile storage medium such as a magnetic disk, optical disk, or read-only memory (ROM), or random access memory (RAM).
[0091] It should be understood that although the steps in the flowcharts of the accompanying figures are shown sequentially as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the accompanying figures may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.
[0092] Further reference Figure 4 As a response to the above Figure 2 The implementation of the method shown in this application provides an embodiment of a message event delay processing device, which is similar to... Figure 2 Corresponding to the method embodiments shown, this device can be specifically applied to various electronic devices.
[0093] like Figure 4 As shown, the message event delay processing device 400 described in this embodiment includes:
[0094] Module 401 is used to obtain message event information;
[0095] The parsing module 402 is used to parse the message time information to obtain parsed message event information;
[0096] The encapsulation module 403 is used to encapsulate the parsed message event information according to a preset message format to obtain formatting parameters, the formatting parameters including delay processing time and business logic functions;
[0097] Storage module 404 is used to obtain a preset message event storage mode corresponding to the delay processing time of the message event, and store the formatting parameters of the message event based on the message event storage mode;
[0098] The execution module 405 is used to call the event executor when the delay processing time of the message event is reached, and execute the business logic function according to the event executor to realize the processing of the corresponding message event.
[0099] To address the aforementioned technical problems, embodiments of this application also provide a computer device. Please refer to [link / reference needed]. Figure 5 , Figure 5 This is a basic structural block diagram of the computer device in this embodiment.
[0100] The computer device 5 includes a memory 51, a processor 52, and a network interface 53 that are interconnected via a system bus. It should be noted that only the computer device 5 with components 51-53 is shown in the figure; however, it should be understood that it is not required to implement all the shown components, and more or fewer components can be implemented alternatively. Those skilled in the art will understand that the computer device described here is a device capable of automatically performing numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes, but is not limited to, microprocessors, application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), digital signal processors (DSPs), embedded devices, etc.
[0101] The computer device can be a desktop computer, laptop, handheld computer, or cloud server, etc. The computer device can interact with the user via a keyboard, mouse, remote control, touchpad, or voice control.
[0102] The memory 51 includes at least one type of readable storage medium, including flash memory, hard disk, multimedia card, card-type memory (e.g., SD card), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 51 may be an internal storage unit of the computer device 5, such as the hard disk or memory of the computer device 5. In other embodiments, the memory 51 may also be an external storage device of the computer device 5, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the computer device 5. Of course, the memory 51 may include both the internal storage unit and its external storage device of the computer device 5. In this embodiment, the memory 51 is typically used to store the operating system and various application software installed on the computer device 5, such as computer-readable instructions for delayed processing methods of message events. In addition, the memory 51 can also be used to temporarily store various types of data that have been output or will be output.
[0103] In some embodiments, the processor 52 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip. The processor 52 is typically used to control the overall operation of the computer device 5. In this embodiment, the processor 52 is used to execute computer-readable instructions stored in the memory 51 or to process data, such as computer-readable instructions for executing a delayed processing method for the message event.
[0104] The network interface 53 may include a wireless network interface or a wired network interface, which is typically used to establish communication connections between the computer device 5 and other electronic devices.
[0105] This application also provides another embodiment, namely, providing a computer-readable storage medium storing computer-readable instructions that can be executed by at least one processor to cause the at least one processor to perform the steps of the message event delay processing method described above.
[0106] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0107] Obviously, the embodiments described above are only some embodiments of this application, not all embodiments. The accompanying drawings show preferred embodiments of this application, but do not limit the patent scope of this application. This application can be implemented in many different forms; rather, the purpose of providing these embodiments is to provide a more thorough and comprehensive understanding of the disclosure of this application. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing specific embodiments, or make equivalent substitutions for some of the technical features. Any equivalent structures made using the content of this application's specification and drawings, directly or indirectly applied to other related technical fields, are similarly within the scope of patent protection of this application.
Claims
1. A method for delaying message events, characterized in that, Includes the following steps: Get message event information; The message event information is parsed to obtain the parsed message event information; The parsed message event information is encapsulated according to a preset message format to obtain formatting parameters, which include delay processing time and business logic functions. Obtain a preset message event storage mode corresponding to the delay processing time of the message event, and store the formatting parameters of the message event based on the message event storage mode; When the delay processing time of the message event is reached, the event executor is invoked, and the business logic function is executed according to the event executor to realize the processing of the corresponding message event; The step of obtaining a preset message event storage mode corresponding to the delay processing time of the message event includes: Confirm the preset delay time level to which the delay processing time belongs. The preset delay time level includes low delay time level, medium delay time level and high delay time level. If the delay processing time of the message event is in the low latency level, the first message event storage mode shall be selected first. If the delay processing time of the message event is in the medium delay time level, the second message event storage mode shall be selected first. If the delay processing time of the message event is in the high latency level, the third message event storage mode shall be selected first. The first message event storage mode is a linked list-based memory mode, where the linked list includes a preset number of memory nodes. The formatting parameters for storing the message event based on the selected message event storage mode include: If the first message event storage mode is selected, the delay processing time of the message event is moduloed and remaindered based on the number of memory nodes in its linked list to obtain the corresponding operation result; The position of the formatting parameters of the message event in the linked list of the first message event storage mode is determined based on the operation result and then stored. Among them, the memory-based first message event storage mode mentioned above uses a singly linked circular list or a doubly linked circular list connected end to end.
2. The message event delay processing method according to claim 1, characterized in that, The formatting parameters for storing the message event based on the message event storage mode also include: If the second message event storage mode is selected, the formatting parameters of the message event will be stored after expiration monitoring through the Redis cache database.
3. The message event delay processing method according to claim 1, characterized in that, The formatting parameters for storing the message event based on the message event storage mode also include: If the third message event storage mode is selected, the formatting parameters of the message event are persistently stored through an external database.
4. The method for delaying message events according to any one of claims 2-3, characterized in that, The step of obtaining the preset message event storage mode corresponding to the delay processing time of the message event further includes: If the formatting parameters of the message event also include the importance level of the message event, then the third message event storage mode, the second message event storage mode, and the first message event storage mode are selected in sequence according to the importance level.
5. The message event delay processing method according to claim 4, characterized in that, The steps of invoking the event executor and executing the business logic function according to the event executor to process the corresponding message event when the delay processing time of the message event is reached include: When the delay processing time of a message event is reached, the message event storage mode retrieves the formatting parameters of the corresponding message event and sends the formatting parameters of the message event to the event executor. The event executor parses the formatting parameters of the message event and calls the business logic function; The business logic function is executed to process the corresponding message event.
6. A delay processing device for message events, characterized in that, include: The acquisition module is used to obtain message event information; The parsing module is used to parse the message event information to obtain the parsed message event information; The encapsulation module is used to encapsulate the parsed message event information according to a preset message format to obtain formatting parameters, which include delay processing time and business logic functions. The storage module is used to obtain a preset message event storage mode corresponding to the delay processing time of the message event, and to store the formatting parameters of the message event based on the message event storage mode; The execution module is used to call the event executor when the delay processing time of the message event is reached, and execute the business logic function according to the event executor to realize the processing of the corresponding message event; Specifically, the storage module is used to determine the preset delay time level to which the delay processing time belongs. The preset delay time level includes a low delay time level, a medium delay time level, and a high delay time level. If the delay processing time of the message event belongs to the low delay time level, the first message event storage mode is selected first. If the delay processing time of the message event belongs to the medium delay time level, the second message event storage mode is selected first. If the delay processing time of the message event belongs to the high delay time level, the third message event storage mode is selected first. The first message event storage mode is a linked list-based memory mode, where the linked list includes a preset number of memory nodes. Storing the formatting parameters of the message event based on the selected message event storage mode includes: if the first message event storage mode is selected, performing modulo and remainder operations on the delay processing time of the message event based on the number of memory nodes in its linked list to obtain the corresponding operation result; determining and storing the position of the formatting parameters of the message event in the linked list of the first message event storage mode based on the operation result. Among them, the memory-based first message event storage mode mentioned above uses a singly linked circular list or a doubly linked circular list connected end to end.
7. A computer device comprising a memory and a processor, wherein the memory stores computer-readable instructions, and the processor, when executing the computer-readable instructions, implements the steps of the delayed processing method for message events as described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-readable instructions, which, when executed by a processor, implement the steps of the delayed processing method for message events as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Task scheduling method, system and equipment and storage medium
CN113157426A