Delay message sending method and device, computer equipment and storage medium

By introducing delay index messages into computer systems, and automatically querying and obtaining delay messages, the problem of inefficient delay message transmission in the prior art is solved, and more efficient and accurate delay message transmission is achieved.

CN120111022APending Publication Date: 2025-06-06SHENZHEN TAIHAI NETWORK TECH SERVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311667458.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-05
Publication Date
2025-06-06

AI Technical Summary

Technical Problem

In the prior art, the delay message transmission efficiency is low and requires a lot of manual processing, resulting in low efficiency.

Method used

By introducing a delay index message between the production end and the consumer end, the production end generates a delay index message and sends it to the consumer end. The consumer end queries based on the delay index message and sends the corresponding delay message to the message middleware.

Benefits of technology

It realizes automated query and acquisition of delayed messages, improves the efficiency and accuracy of delayed messages, and reduces the need for manual processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120111022A_ABST
    Figure CN120111022A_ABST
Patent Text Reader

Abstract

The invention relates to a delay message sending method and device, computer equipment, a storage medium and a computer program product, and can be applied to the technical field of computers. The method comprises the following steps: acquiring a delay index message; wherein the delay index message is generated by the production end, and the delay index message carries a message identifier of the delay message and delay time of the delay message; from the delay index messages, querying a delay index message which is carried by the delay index messages and has expired delay time, and taking the delay index message as a target delay index message; obtaining a delay message corresponding to a message identifier carried by the target delay index message as a target delay message; and sending the target delay message to the message middleware. By adopting the method, the delay message sending efficiency can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a delayed message sending method, apparatus, computer equipment, storage medium and computer program product. Background Art

[0002] With the development of computer technology, delayed messages have a wide range of usage scenarios in the field of computer technology. In practical applications, for message processing and delivery, it is sometimes necessary to delay the sending of messages to trigger subsequent application processing. Therefore, how to efficiently implement delayed message sending has become an important research direction.

[0003] Traditionally, delayed messages are usually sent manually by technicians according to the conditions for sending delayed messages; however, sending delayed messages in this way requires a lot of manual processing time, resulting in low efficiency in sending delayed messages. Summary of the invention

[0004] Based on this, it is necessary to provide a delayed message sending method, apparatus, computer equipment, computer-readable storage medium and computer program product that can improve the efficiency of delayed message sending in response to the above technical problems.

[0005] In a first aspect, the present application provides a delayed message sending method. Applied to a consumer end, the method comprises:

[0006] Obtain a delay index message; wherein the delay index message is generated by the production end, and the delay index message carries a message identifier of the delay message and a delay time of the delay message;

[0007] From the delay index message, query the delay index message with the delay time carried by the delay index message expired as the target delay index message;

[0008] Obtaining a delay message corresponding to the message identifier carried by the target delay index message as the target delay message;

[0009] The target delayed message is sent to the message middleware.

[0010] In one of the embodiments, after obtaining the delay index message, the method further includes:

[0011] Backing up the delayed index message according to a preset first time interval to obtain a backup index message;

[0012] Locally back up and store the backup index message;

[0013] After the system of the consumer end is restarted, the backup index message is stored in a local preset queue;

[0014] The step of searching the delay index message for a delay index message with a delay time expired carried by the delay index message as a target delay index message includes:

[0015] Obtain the delay index message or the backup index message from the local preset queue, query the delay index message with the delay time expired carried by the delay index message as the target delay index message, or query the backup index message with the delay time expired carried by the backup index message as the target index message.

[0016] In one of the embodiments, after obtaining the delay index message, the method further includes:

[0017] When the system of the consumer end is out of service, taking out the delayed index message from a local preset queue;

[0018] The delayed index message is sent to the message middleware.

[0019] In one of the embodiments, before obtaining the delay message corresponding to the message identifier carried by the target delay index message as the target delay message, the method further includes:

[0020] Taking out the target delay index message from the local preset queue;

[0021] Storing the target delay index message in the local task queue of the consumer end;

[0022] The target delay index message is taken out from the local task queue.

[0023] In one of the embodiments, the local preset queue is a local delay queue of the consumer end;

[0024] Before searching the delay index message for a delay index message with an expired delay time carried by the delay index message as the target delay index message, the method further includes:

[0025] The delay index message is stored in the local delay queue.

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

[0027] According to a preset second time interval, query the delayed messages that have not been obtained in the delayed message table, query the delayed messages whose corresponding delay time expires as the delayed messages to be sent; the delayed message table is used to store the delayed messages;

[0028] The delayed message to be sent is sent to the message middleware.

[0029] In a second aspect, the present application provides a delayed message sending method. Applied to a production end, the method comprises:

[0030] Get delayed messages;

[0031] Generate a delay index message corresponding to the delay message according to the message identifier of the delay message and the delay time of the delay message;

[0032] The delay index message is sent to the consumer end; the consumer end is used to obtain the delay index message, and from the delay index message, query the delay index message with the delay time carried by the delay index message as the target delay index message, obtain the delay message corresponding to the message identifier carried by the target delay index message as the target delay message, and send the target delay message to the message middleware.

[0033] In a third aspect, the present application further provides a delayed message sending device. Applied to a consumer end, the device comprises:

[0034] A first acquisition module is used to acquire a delay index message; wherein the delay index message is generated by the production end, and the delay index message carries a message identifier of the delay message and a delay time of the delay message;

[0035] A message query module, used to query the delay index message from the delay index message, and use the delay index message as the target delay index message;

[0036] A second acquisition module is used to acquire a delay message corresponding to the message identifier carried by the target delay index message as a target delay message;

[0037] The message sending module is used to send the target delayed message to the message middleware.

[0038] In a fourth aspect, the present application further provides a delayed message sending device. Applied to a production end, the device comprises:

[0039] The third acquisition module is used to obtain the delayed message;

[0040] A message generating module, used for generating a delay index message corresponding to the delay message according to the message identifier of the delay message and the delay time of the delay message;

[0041] An index sending module is used to send the delayed index message to the consumer end; the consumer end is used to obtain the delayed index message, query the delayed index message with the delay time carried by the delayed index message from the delayed index message, use it as the target delayed index message, obtain the delay message corresponding to the message identifier carried by the target delayed index message, use it as the target delayed message, and send the target delayed message to the message middleware.

[0042] In a fifth aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:

[0043] Obtain a delay index message; wherein the delay index message is generated by the production end, and the delay index message carries a message identifier of the delay message and a delay time of the delay message;

[0044] From the delay index message, query the delay index message with the delay time carried by the delay index message expired as the target delay index message;

[0045] Obtaining a delay message corresponding to the message identifier carried by the target delay index message as the target delay message;

[0046] The target delayed message is sent to the message middleware.

[0047] In a sixth aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:

[0048] Get delayed messages;

[0049] Generate a delay index message corresponding to the delay message according to the message identifier of the delay message and the delay time of the delay message;

[0050] The delay index message is sent to the consumer end; the consumer end is used to obtain the delay index message, and from the delay index message, query the delay index message with the delay time carried by the delay index message as the target delay index message, obtain the delay message corresponding to the message identifier carried by the target delay index message as the target delay message, and send the target delay message to the message middleware.

[0051] In a seventh aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:

[0052] Obtain a delay index message; wherein the delay index message is generated by the production end, and the delay index message carries a message identifier of the delay message and a delay time of the delay message;

[0053] From the delay index message, query the delay index message with the delay time carried by the delay index message expired as the target delay index message;

[0054] Obtaining a delay message corresponding to the message identifier carried by the target delay index message as the target delay message;

[0055] The target delayed message is sent to the message middleware.

[0056] In an eighth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:

[0057] Get delayed messages;

[0058] Generate a delay index message corresponding to the delay message according to the message identifier of the delay message and the delay time of the delay message;

[0059] The delay index message is sent to the consumer end; the consumer end is used to obtain the delay index message, and from the delay index message, query the delay index message with the delay time carried by the delay index message as the target delay index message, obtain the delay message corresponding to the message identifier carried by the target delay index message as the target delay message, and send the target delay message to the message middleware.

[0060] In a ninth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:

[0061] Obtain a delay index message; wherein the delay index message is generated by the production end, and the delay index message carries a message identifier of the delay message and a delay time of the delay message;

[0062] From the delay index message, query the delay index message with the delay time carried by the delay index message expired as the target delay index message;

[0063] Obtaining a delay message corresponding to the message identifier carried by the target delay index message as the target delay message;

[0064] The target delayed message is sent to the message middleware.

[0065] In a tenth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:

[0066] Get delayed messages;

[0067] Generate a delay index message corresponding to the delay message according to the message identifier of the delay message and the delay time of the delay message;

[0068] The delay index message is sent to the consumer end; the consumer end is used to obtain the delay index message, and from the delay index message, query the delay index message with the delay time carried by the delay index message as the target delay index message, obtain the delay message corresponding to the message identifier carried by the target delay index message as the target delay message, and send the target delay message to the message middleware.

[0069] The above-mentioned delayed message sending method, device, computer equipment, storage medium and computer program product obtain a delayed index message; wherein, the delayed index message is generated by the production end, and the delayed index message carries the message identifier of the delayed message and the delay time of the delayed message; from the delayed index message, query the delayed index message with the delay time carried by the delayed index message expired as the target delayed index message; obtain the delay message corresponding to the message identifier carried by the target delay index message as the target delayed message; send the target delayed message to the message middleware. The solution obtains the delayed message from the production end, generates a delayed index message corresponding to the delayed message according to the message identifier and delay time of the delayed message, and sends the delayed index message to the consumer end; the consumer end obtains the delayed index message generated by the production end, queries the delayed index message for the delayed index message with the delay time expired from the delayed index message, obtains the delayed message corresponding to the message identifier carried by the target delayed index message as the target delayed message, and sends the target delayed message to the message middleware; the consumer end automatically queries and obtains the delayed message based on the delayed index message and sends it to the message middleware, which is beneficial to improving the efficiency and accuracy of delay message sending. BRIEF DESCRIPTION OF THE DRAWINGS

[0070] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0071] Figure 1An application environment diagram of a delayed message sending method in an embodiment;

[0072] Figure 2 A schematic diagram of a flow chart of a delayed message sending method in one embodiment;

[0073] Figure 3 A schematic diagram of the architecture of a delayed message sending method in one embodiment;

[0074] Figure 4 A schematic diagram of a flow chart of a delayed message sending method in another embodiment;

[0075] Figure 5 is a structural block diagram of a delayed message sending device in an embodiment;

[0076] Figure 6 It is a structural block diagram of a delayed message sending device in another embodiment;

[0077] Figure 7 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0078] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0079] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.

[0080] Kafka (a high-throughput distributed publish-subscribe messaging system) is an open source messaging middleware that provides high-throughput performance and can be used as a standard component. However, it currently fails to provide the delayed message sending function like activemq (active message queue) and rocketmq (a distributed messaging middleware). For some specific scenarios that require delayed message sending to trigger execution actions, such as delayed order closing and incremental polling, it cannot provide good support and requires developers to perform certain manual processing to achieve delayed message sending. This can easily lead to duplicate construction of such public capabilities, high development costs, and difficult to ensure development quality, which is prone to production accidents. In this case, a delayed message sending method based on Kafka is needed to meet the needs of most scenarios.

[0081] Based on this, the present application provides a delayed message sending method, apparatus, computer equipment, storage medium and computer program product. First, the delayed message sending method provided by the present application is described.

[0082] The delayed message sending method provided in this application can be applied to Figure 1 In the application environment shown. The application scenario may include: a consumer end 101, a production end 102 and a message middleware 103, the consumer end 101 and the production end 102 can be connected in communication, the consumer end 101 and the message middleware 103 can be connected in communication, and the production end 102 and the message middleware 103 can be connected in communication. Specifically, the production end 102 obtains a delayed message, generates a delayed index message corresponding to the delayed message according to the message identifier and delay time of the delayed message, and sends the delayed index message to the consumer end 101; the consumer end 101 obtains the delayed index message generated by the production end 102, and from the delayed index message, queries the delayed index message with the delay time expired carried by the delayed index message as the target delayed index message, obtains the delayed message corresponding to the message identifier carried by the target delayed index message, and sends the target delayed message to the message middleware 103 as the target delayed message. Among them, the consumer end 101 can be implemented with an independent server or a server cluster composed of multiple servers; the production end 102 can be implemented with an independent server or a server cluster composed of multiple servers; the message middleware 103 can be a software component or service used for message transmission and communication in a distributed system, which can be implemented with an independent server or a server cluster composed of multiple servers.

[0083] In an exemplary embodiment, Figure 2 As shown, a delayed message sending method is provided. This embodiment takes the method applied to a consumer end as an example for illustration. The method includes the following steps:

[0084] Step S201, obtaining a delay index message.

[0085] The production end may refer to a system that can generate delayed messages and delayed index messages. For example, in a logistics scenario, the production end may refer to a logistics transportation system, and the delayed message may refer to a logistics message. The delayed index message is generated by the production end, and the delayed index message carries the message identifier of the delayed message and the delay time of the delayed message.

[0086] Among them, the consumer end can be a consumer end cluster composed of one or more consumer nodes.

[0087] Among them, the message middleware can be a message queue system, such as Kafka (a high-throughput distributed publish-subscribe messaging system), which is a software component or service used for messaging and communication in a distributed system. It acts as an intermediate layer between the production end (producer) and the consumption end (consumer), responsible for receiving, storing and delivering messages.

[0088] Among them, the delayed index message can be stored in the delayed index message queue. The delayed index message queue can be a specific message queue in the message middleware, which is used to store the delayed index messages sent by the production end. These delayed index messages contain the message identifier and delay time corresponding to the delayed message. For example, the delayed index message queue can be a delayed index message Topic (category or subject).

[0089] The delayed message table may be a public storage database, such as a MySQL (relational database management system) database, which is used to store the actual content of the delayed message.

[0090] The message identifier may be an identifier used to uniquely identify a message (delayed message), and may be the name of the message or other unique identifiers.

[0091] Optionally, the producer obtains the delayed message, generates a delayed index message corresponding to the delayed message based on the message identifier of the delayed message and the delay time of the delayed message, and provides or sends the delayed index message to the consumer; the consumer obtains the delayed index message generated by the producer.

[0092] For example, if Figure 3 As shown, the production end obtains the delayed message, stores the delayed message in the delayed message table, generates a delayed index message corresponding to the delayed message, and stores the delayed index message corresponding to the delayed message in the delayed index message queue of the message middleware; the consumer end obtains the delayed index message sent by the production end from the delayed index message queue of the message middleware.

[0093] Step S202: from the delay index message, search for a delay index message with an expired delay time carried by the delay index message as a target delay index message.

[0094] The target delay index message may be a delay index message whose delay time has expired and is retrieved from a delay index message queue, and includes a message identifier of a corresponding delay message.

[0095] Optionally, the consumer end obtains the delay time and start timestamp carried by the delay index message, calculates the time difference between the current time and the start timestamp, obtains the elapsed time, and determines whether the elapsed time reaches the delay time of the delay index message. If the elapsed time reaches the delay time of the delay index message, the delay index message is used as the target delay index message.

[0096] Step S203: Acquire a delay message corresponding to the message identifier carried by the target delay index message as the target delay message.

[0097] The target delayed message may be a delayed message obtained from the delayed message table and corresponding to the message identifier carried by the target delayed index message, and is the delayed message actually required to be sent.

[0098] Alternatively, if Figure 3 As shown, the consumer searches the delayed message table for a delayed message that matches the message identifier carried by the target delayed index message, obtains the matched delayed message from the delayed message table, and uses the matched delayed message as the target delayed message.

[0099] Step S204: Send the target delayed message to the message middleware.

[0100] The target object may be a receiver corresponding to the target delayed message, for example, the target object may be a final message queue (final message Topic) of the message middleware.

[0101] Alternatively, if Figure 3 As shown, the consumer determines the corresponding target object according to the target delay message and sends the target delay message to the corresponding target object.

[0102] In the above-mentioned delayed message sending method, a delayed index message is obtained from the delayed index message queue of the message middleware; wherein the delayed index message is generated by the production end, and the delayed index message carries the message identifier of the delayed message and the delay time of the delayed message; from the delayed index message, the delayed index message with the delay time carried by the delayed index message expires is queried as the target delayed index message; the delayed message corresponding to the message identifier carried by the target delayed index message is obtained as the target delayed message; and the target delayed message is sent to the message middleware. The solution obtains the delayed message from the production end, generates a delayed index message corresponding to the delayed message according to the message identifier and delay time of the delayed message, and sends the delayed index message to the consumer end; the consumer end obtains the delayed index message generated by the production end, queries the delayed index message for the delayed index message with the delay time expired from the delayed index message, obtains the delayed message corresponding to the message identifier carried by the target delayed index message as the target delayed message, and sends the target delayed message to the message middleware; the consumer end automatically queries and obtains the delayed message based on the delayed index message and sends it to the message middleware, which is beneficial to improving the efficiency and accuracy of delay message sending.

[0103] In an exemplary embodiment, after obtaining the delay index message, it also includes the following contents: backing up the delay index message according to a preset first time interval to obtain a backup index message; locally backing up and storing the backup index message; after the system at the consumer end is restarted, storing the backup index message in a local preset queue; from the delay index message, querying the delay index message with the delay time expired carried by the delay index message as the target delay index message, specifically including the following contents: obtaining the delay index message or the backup index message from the local preset queue, querying the delay index message with the delay time expired carried by the delay index message as the target delay index message, or querying the backup index message with the delay time expired carried by the backup index message as the target index message.

[0104] The preset first time interval may be a pre-set time interval for controlling the frequency of the backup operation and may be set according to specific requirements.

[0105] The backup index message may be a message copy obtained by backing up the delayed index message at time intervals, which is used for recovery and fault tolerance.

[0106] The local preset queue may be a queue in the memory of the consumer-end computer, which is used to temporarily store the delayed index message and the backup index message. For example, the local preset queue may be a local delayed queue.

[0107] The local delay queue may be a delay queue maintained locally at the consumer end, used to store received delay index messages. The local backup space may be a space or storage medium at the consumer end for storing delay index message backups (i.e., backup index messages), which may be a local disk, database, or other storage device.

[0108] Among them, the system restart can be an unexpected or planned restart operation of the consumer-side system at a certain point in time, which may be caused by system failure, upgrade or maintenance.

[0109] Alternatively, if Figure 3 As shown, the consumer end backs up the delayed index message according to the preset first time interval to obtain the backup index message corresponding to the delayed index message. The backup index message is locally backed up and stored, for example, the backup index message is stored in the storage area of ​​the local disk of the consumer end. After the system of the consumer end is restarted, the backup index message is stored in the local preset queue (local delay queue). Among them, the local delay queue can be implemented using the DelayQueue class, which is an unbounded blocking queue with a delay element. From the local preset queue, obtain the delayed index message or the backup index message, query the delayed index message, and the delayed index message with the delay time expired is carried, and the delayed index message with the delay time expired is used as the target delayed index message. Alternatively, query the backup index message with the delay time expired carried in the backup index message, and use the backup index message with the delay time expired as the target index message.

[0110] The technical solution provided in this embodiment helps to prevent message loss caused by system restart by backing up the delayed index message, ensures the integrity and reliability of the delayed index message, and thus helps to improve the accuracy of delayed message sending.

[0111] In an exemplary embodiment, after obtaining the delay index message, the following contents are also included: when the system at the consumer end is out of service, taking out the delay index message from the local preset queue; and sending the delay index message to the message middleware.

[0112] Among them, system outage may refer to the system on the consumer side ceasing to run or shutting down at a certain point in time, which may be caused by planned maintenance, upgrades or unplanned failures.

[0113] Optionally, when the system on the consumer side is shut down, the consumer side will take out the delay index message from the local delay queue to ensure that no delay message is lost during the system outage; the consumer side will send the retrieved delay index message to the delay index message queue in the message middleware so that other consumers can obtain the delay index message from the queue for processing.

[0114] The technical solution provided in this embodiment sends the delay index message to the message middleware when the system on the consumer side is out of service. In this way, during the period when the system on the consumer side is out of service, other consumer sides can still obtain and process the delay index message, which is beneficial to improving the accuracy of delay message sending.

[0115] In an exemplary embodiment, before obtaining the delay message corresponding to the message identifier carried by the target delay index message as the target delay message, it also includes the following contents: taking out the target delay index message from the local preset queue; storing the target delay index message in the local task queue of the consumer end; taking out the target delay index message from the local task queue.

[0116] Among them, the local task queue can be a queue in the consumer end for storing target delay index messages (expired delay index messages).

[0117] Alternatively, if Figure 3 As shown, the consumer end takes out the target delay index message from the delay index message in the local delay queue; stores the target delay index message in the local task queue of the consumer end; polls the messages in the local task queue, and when it is found that the target delay index message is stored in the local task queue, takes out the target delay index message from the local task queue.

[0118] The technical solution provided in this embodiment can more accurately distinguish delay index messages from target delay index messages by storing the target delay index message in the local task queue of the consumer end, which is conducive to accurately determining the target delay index message, thereby facilitating improving the accuracy of delay message sending.

[0119] In an exemplary embodiment, before searching the delay index message for a delay index message with an expired delay time carried by the delay index message as the target delay index message, the following content is also included: storing the delay index message in a local delay queue.

[0120] Among them, the local preset queue can be a local delayed queue at the consumer end.

[0121] Optionally, before the consumer searches for the delay index message with the delay time expired carried by the delay index message as the target delay index message, the consumer first stores the delay index message in a local delay queue.

[0122] The technical solution provided in this embodiment, by storing the delay index message in the local delay queue, is conducive to the subsequent efficient and accurate determination of the target delay index message, thereby facilitating the improvement of the efficiency and accuracy of delay message sending.

[0123] In an exemplary embodiment, the step of sending the delayed message to be sent to the message middleware is also included, which specifically includes the following contents: according to a preset second time interval, the delayed messages that have not been obtained in the delayed message table are queried, and the delayed messages with corresponding delay times expired are queried as the delayed messages to be sent; the delayed message table is used to store the delayed messages; and the delayed messages to be sent are sent to the message middleware.

[0124] The preset second time interval may be a pre-set time interval used to control the frequency of obtaining the delayed message to be sent from the delayed message table, and may be set according to specific requirements.

[0125] The unobtained delayed message may be a delayed message that has not been obtained or processed in the delayed message table.

[0126] The delayed message with expired delay time may be a delayed message in the delayed message table whose delay time has expired, that is, a delayed message that needs to be sent immediately.

[0127] Alternatively, if Figure 3 As shown, the consumer end filters out the unobtained delayed messages from the delayed message table according to the preset second time interval, and finds out the delayed messages whose delay time has expired as the delayed messages to be sent; the delayed messages to be sent are sent to the message middleware so that other objects can obtain and process the delayed messages.

[0128] The technical solution provided in this embodiment filters the delayed messages in the delayed message table according to the second time interval, which can reduce the situation where the delay time has expired but the corresponding delayed message has not been sent for a long time, which is beneficial to ensure the accurate sending of the delayed message, thereby improving the accuracy of the delayed message sending.

[0129] In an exemplary embodiment, Figure 4 As shown, a delayed message sending method is provided. This embodiment takes the method applied to the production end as an example for illustration. The method includes the following steps:

[0130] Step S401, obtaining a delayed message.

[0131] Optionally, the production end obtains the delayed message and stores the delayed message in a delayed message table.

[0132] Step S402: Generate a delay index message corresponding to the delayed message according to the message identifier of the delayed message and the delay time of the delayed message.

[0133] Optionally, the production end generates a delay index message corresponding to the delayed message according to the message identifier of the delayed message and the delay time of the delayed message, so that the delay index message carries the message identifier and delay time of the corresponding delayed message.

[0134] Step S403, sending the delay index message to the consumer end; the consumer end is used to obtain the delay index message, and from the delay index message, query the delay index message with the delay time expired carried by the delay index message as the target delay index message, obtain the delay message corresponding to the message identifier carried by the target delay index message as the target delay message, and send the target delay message to the message middleware.

[0135] Optionally, the production end generates a delay index message corresponding to the delayed message, and sends the delay index message to the consumer end. For example, the delay index message corresponding to the delay message is stored in the delay index message queue of the message middleware, so that the consumer end obtains the delay index message from the delay index message queue of the message middleware, queries the delay index message with the expiration of the delay time carried by the delay index message as the target delay index message, obtains the delay message corresponding to the message identifier carried by the target delay index message from the delay message table as the target delay message, and sends the target delay message to the corresponding target object.

[0136] In the above-mentioned delayed message sending method, a delayed index message is obtained; wherein, the delayed index message is generated by the production end, and the delayed index message carries the message identifier of the delayed message and the delay time of the delayed message; from the delayed index message, the delayed index message with the delay time carried by the delayed index message expires is queried as the target delayed index message; the delayed message corresponding to the message identifier carried by the target delayed index message is obtained as the target delayed message; and the target delayed message is sent to the message middleware. The solution obtains the delayed message from the production end, generates a delayed index message corresponding to the delayed message according to the message identifier and delay time of the delayed message, and sends the delayed index message to the consumer end; the consumer end obtains the delayed index message generated by the production end, queries the delayed index message for the delayed index message with the delay time expired from the delayed index message, obtains the delayed message corresponding to the message identifier carried by the target delayed index message as the target delayed message, and sends the target delayed message to the message middleware; the consumer end automatically queries and obtains the delayed message based on the delayed index message and sends it to the message middleware, which is beneficial to improving the efficiency and accuracy of delay message sending.

[0137] The following is an example of a delayed message sending method provided by the present application. This example is illustrated by applying the method to a consumer end and a producer end. The main steps include:

[0138] In the first step, the production end stores the delayed message in the delayed message table; stores the delayed index message corresponding to the delayed message in the delayed index message queue of the message middleware; the delayed index message carries the message identifier and delay time of the corresponding delayed message.

[0139] In the second step, the consumer side obtains the delayed index message of the producer side from the delayed index message queue of the message middleware.

[0140] In the third step, the consumer side stores the delayed index message in the local delayed queue of the consumer side.

[0141] In the fourth step, when the system at the consumer end is out of service, the consumer end takes out the delayed index message from the local delayed queue; sends the delayed index message to the delayed index message queue, so that other consumers obtain the delayed index message from the delayed index message queue.

[0142] In the fifth step, the consumer end backs up the delay index message in the local delay queue to the local backup space of the consumer end according to the preset first time interval; after the system of the consumer end is restarted, the delay index message in the local backup space is stored in the local delay queue.

[0143] In the sixth step, the consumer side searches the local delay queue for the delay index message with the expired delay time as the target delay index message.

[0144] In the seventh step, the consumer side takes out the target delay index message from the local delay queue; stores the target delay index message in the local task queue of the consumer side; and when it is found that the target delay index message is stored in the local task queue, takes out the target delay index message from the local task queue.

[0145] In the eighth step, the consumer obtains the delayed message corresponding to the message identifier carried by the target delayed index message from the delayed message table as the target delayed message.

[0146] In the ninth step, the consumer sends the target delayed message to the corresponding target object.

[0147] In the tenth step, the consumer end obtains the delayed message with the corresponding delayed time expired from the delayed messages not obtained in the delayed message table according to the preset second time interval as the delayed message to be sent; and sends the delayed message to be sent to the corresponding target object.

[0148] The technical solution provided by this embodiment is that the production end stores the delayed message in the delayed message table, and stores the delayed index message corresponding to the delayed message in the delayed index message queue of the message middleware; the consumer end obtains the delayed index message of the production end from the delayed index message queue of the message middleware, and queries the delayed index message whose delay time has expired from the obtained delay index message, and obtains the corresponding delayed message from the delay message table according to the message identifier carried by the target delay index message as the target delayed message, and sends the obtained target delayed message to the corresponding target object to complete the delayed message sending work; the consumer end automatically queries and obtains the delayed message based on the delayed index message and the delayed message table of the message middleware, and then sends it to the target object, which is beneficial to improve the efficiency and accuracy of delay message sending.

[0149] The following is an application example to illustrate the delayed message sending method provided by this application. This application example uses the method applied to the consumer end and the production end as an example. Figure 3 As shown, the main steps include:

[0150] In the first step, the production end sends the delayed message that needs to be delayed to the delayed index message queue, specifies the message message and delay time, and can use synchronous or asynchronous sending.

[0151] The format of the sent message is MSG (message, delay time), where MSG can represent the format prefix of the message.

[0152] In the second step, the production end saves the delayed message to the public storage (that is, the message is saved through the delayed message table, which is saved in the MySQL database by default and can be expanded to other types of storage), and assembles the message ID (identifier), delay start time, delay time, and the final queue name (target object) of the delayed message into a delayed index message (delay index record), and then sends the delayed index message to the delayed index message queue.

[0153] Among them, the message format of the delayed message saved in the public storage can be: MSG (message ID, final message queue name, delay time, message content, message status, start timestamp, message delay trigger timestamp, message queue additional information).

[0154] The message format sent to the delayed index message queue may be: MSG (message ID, final message queue name, start timestamp, message delay trigger timestamp). For example, the delayed index message may include the name of the delayed message, index identifier, delay start time, delay time, and message status.

[0155] Among them, the message status can be divided into: 0 for initial, 1 for delayed, and 2 for submitted. For example, when the message status is 0, it indicates the initial status, that is, the status when the delayed index message has just been sent to the delayed index message queue by the producer; when the message status is 1, it indicates the delayed status, that is, the delayed index message has been received in the local delay queue and is waiting for the delay time to expire; when the message status is 2, it indicates the submitted status, that is, the delay time of the delayed index message has expired, the delayed index message has been taken out of the local delay queue and submitted to the local task queue. The message status can be used to identify the changing status of the delayed index message / delay message at different stages of delayed processing. By recording and tracking the message status, it can be clear at what stage the delayed index message / delay message is currently in the delayed processing flow.

[0156] In the third step, the receiving threads of multiple consumer nodes on the consumer side (delay index message receiving threads) receive the delayed index message in the delayed index message queue (that is, the consumer side receives the delayed index message), and put the message into the local delay queue. Here, the DelayQueue class provided by the Java (a general object-oriented programming language) development toolkit can be used to implement the local delay queue. The local delay can also be implemented using the open source scheduling component quartz (open source task scheduler) .

[0157] In the fourth step, the delayed task acceptance thread in the consumer process polls the local delay queue. After the delay time of the delayed index message expires, the delayed index message is taken out from the local delay queue and placed in the local task queue (final task memory queue).

[0158] In the fifth step, the sending final task thread in the consumer end polls the messages in the local task queue, takes out the delayed index message, and then takes out the actual delayed message content from the public storage (obtains the message content), assembles it and sends it to the final message queue.

[0159] Exemplarily, in order to ensure that the delayed message or delayed index message retained in the memory of the local node (for example, the local node can be represented as a consumer in the consumer cluster) is not lost, the following three measures can be taken to solve the problem:

[0160] First, because the DelayQueue class implements a local delay queue and cannot guarantee that messages will not be lost, once the system is restarted, the memory messages will be lost. To prevent this from happening, the consumer end also starts a thread locally (the thread that saves the scheduled memory queue snapshot) to quickly save the message snapshots in the queue locally at regular intervals (usually N seconds, where N can be a set number). For example, the consumer end saves the scheduled thread through the memory queue snapshot, and regularly backs up the delay index messages in the local delay queue to the local backup space of the consumer end at a preset first time interval. After the system on the consumer end is restarted, the delay index messages in the local backup space are stored in the local delay queue (this can be done by direct memory writing, which is beneficial to improving writing efficiency), thereby ensuring that the delay index messages will not be lost.

[0161] Second, when the system on the consumer side is shut down normally, the consumer side sends the message of the local delay queue back to the delay index message queue, and other consumer sides can continue to receive the delay index message for processing. Among them, normal shutdown can refer to planned maintenance shutdown (for example, shutdown due to maintenance and upgrades).

[0162] Third, the consumer end also provides a delayed message expiration processing schedule (delayed message expiration processing compensation schedule), which can query the delayed messages in the delayed message table that have expired but not sent out every M minutes (M can be a set number), and put them into the final message queue (that is, the target object) (that is, send the message to the final message queue), to ensure that the delayed processing process continues to flow under extreme circumstances.

[0163] Among them, the overall idea of ​​this application example is that the production end sends the delayed message to be sent to the delayed index message queue, and then each consumer cluster node receives the delayed index message, and each performs a delayed action based on the node locally, and then sends it to the actual node (final message queue) after reaching the delay time point.

[0164] Among them, this application instance reserves extension points to support subsequent expansion: the public storage component uses the MySQL database, and for high-concurrency write scenarios, the LSM (tree-structured database model) structure database can be considered. At the same time, the public component implementation adopts an interface method to support future expansion implementation solutions.

[0165] The technical solution provided by this application example can realize the delay of messages with second-level accuracy support; the synchronous sending method can ensure that the delayed messages are not lost, and the asynchronous method can ensure the sending of delayed messages through compensation scheduling to ensure that the messages are not lost; because only delayed index messages are saved in the memory, the delayed index messages have few definition fields, and a large number of delayed index messages can be stored in a small amount of memory, which can support the delayed sending of millions of messages; it can provide the ability to send delayed messages under Kafka-based components, support the delayed sending of millions of messages, and support horizontal expansion, with message reliability, to ensure that delayed messages are not lost, only need to introduce dependencies for configuration and use, simple and efficient development, form common components, avoid repeated development of delay components, reduce development and use costs; improve the efficiency and accuracy of delayed message sending.

[0166] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0167] Based on the same inventive concept, the embodiment of the present application also provides a delayed message sending device for implementing the delayed message sending method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more delayed message sending device embodiments provided below can refer to the limitations of the delayed message sending method above, and will not be repeated here.

[0168] In an exemplary embodiment, Figure 5 As shown, a delayed message sending device is provided, which is applied to a consumer end. The device 500 may include:

[0169] The first acquisition module 501 is used to acquire a delayed index message; wherein the delayed index message is generated by the production end, and the delayed index message carries a message identifier of the delayed message and a delay time of the delayed message;

[0170] The message query module 502 is used to query the delay index message from the delay index message, and the delay index message with the delay time expired carried by the delay index message is used as the target delay index message;

[0171] A second acquisition module 503 is used to acquire a delay message corresponding to the message identifier carried by the target delay index message as the target delay message;

[0172] The message sending module 504 is used to send the target delayed message to the message middleware.

[0173] In an exemplary embodiment, the device 500 also includes: a message backup module, which is used to back up the delayed index message according to a preset first time interval to obtain a backup index message; locally back up and store the backup index message; after the system at the consumer end is restarted, store the backup index message in a local preset queue; a message query module 502, which is also used to obtain the delayed index message or the backup index message from the local preset queue, query the delayed index message with the delay time expired carried by the delayed index message as the target delayed index message, or query the backup index message with the delay time expired carried by the backup index message as the target index message.

[0174] In an exemplary embodiment, the device 500 further includes: a first fetching module, configured to fetch the delayed index message from a local preset queue when the system at the consumer end is out of service; and send the delayed index message to the message middleware.

[0175] In an exemplary embodiment, the device 500 also includes: a second retrieval module, used to retrieve the target delay index message from the local preset queue; store the target delay index message in the local task queue of the consumer end; and retrieve the target delay index message from the local task queue.

[0176] In an exemplary embodiment, the local preset queue is a local delay queue of the consumer end; the device 500 also includes: an index storage module, which is used to store the delay index message in the local delay queue.

[0177] In an exemplary embodiment, the device 500 also includes: a message determination module, which is used to query the delayed messages that have not been acquired in the delayed message table according to a preset second time interval, and query the delayed messages with corresponding delay times expired as delayed messages to be sent; the delayed message table is used to store delayed messages; and the delayed messages to be sent are sent to the message middleware.

[0178] In an exemplary embodiment, Figure 6 As shown, a delayed message sending device is provided, which is applied to a production end. The device 600 may include:

[0179] The third acquisition module 601 is used to acquire the delayed message;

[0180] The message generating module 602 is used to generate a delay index message corresponding to the delay message according to the message identifier of the delay message and the delay time of the delay message;

[0181] The index sending module 603 is used to send the delayed index message to the consumer end; the consumer end is used to obtain the delayed index message, and from the delayed index message, query the delayed index message with the expired delay time carried by the delayed index message as the target delayed index message, obtain the delay message corresponding to the message identifier carried by the target delayed index message as the target delayed message, and send the target delayed message to the message middleware.

[0182] Each module in the above-mentioned delayed message sending device can be implemented in whole or in part by software, hardware and a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module above.

[0183] In an exemplary embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. Figure 7 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store delayed index messages and other data related to delayed message sending. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a delayed message sending method is implemented.

[0184] Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0185] In an exemplary embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above-mentioned method embodiments when executing the computer program.

[0186] In an exemplary embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.

[0187] In an exemplary embodiment, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps in the above method embodiments are implemented.

[0188] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.

[0189] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0190] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A delayed message sending method, It is characterized in that Applied to the consumer end, the method includes: Obtain a delay index message; wherein the delay index message is generated by the production end, and the delay index message carries a message identifier of the delay message and a delay time of the delay message; From the delay index message, query the delay index message with the delay time carried by the delay index message expired as the target delay index message; Obtaining a delay message corresponding to the message identifier carried by the target delay index message as the target delay message; The target delayed message is sent to the message middleware.

2. The method according to claim 1, It is characterized in that After acquiring the delay index message, the method further includes: Backing up the delayed index message according to a preset first time interval to obtain a backup index message; Locally back up and store the backup index message; After the system of the consumer end is restarted, the backup index message is stored in a local preset queue; The step of searching the delay index message for a delay index message with a delay time expired carried by the delay index message as a target delay index message includes: Obtain the delay index message or the backup index message from the local preset queue, query the delay index message with the delay time expired carried by the delay index message as the target delay index message, or query the backup index message with the delay time expired carried by the backup index message as the target index message.

3. The method according to claim 1, It is characterized in that After acquiring the delay index message, the method further includes: When the system of the consumer end is out of service, taking out the delayed index message from a local preset queue; The delayed index message is sent to the message middleware.

4. The method according to claim 1, It is characterized in that Before obtaining a delay message corresponding to the message identifier carried by the target delay index message as the target delay message, the method further includes: Taking out the target delay index message from the local preset queue; Storing the target delay index message in the local task queue of the consumer end; The target delay index message is taken out from the local task queue.

5. The method according to any one of claims 2 to 4, It is characterized in that The local preset queue is the local delay queue of the consumer end; Before searching the delay index message for a delay index message with an expired delay time carried by the delay index message as the target delay index message, the method further includes: The delay index message is stored in the local delay queue.

6. The method according to claim 1, It is characterized in that The method further comprises: According to a preset second time interval, query the delayed messages that have not been obtained in the delayed message table, query the delayed messages whose corresponding delay time expires as the delayed messages to be sent; the delayed message table is used to store the delayed messages; The delayed message to be sent is sent to the message middleware.

7. A delayed message sending method, It is characterized in that Applied to the production end, the method includes: Get delayed messages; Generate a delay index message corresponding to the delay message according to the message identifier of the delay message and the delay time of the delay message; The delay index message is sent to the consumer end; the consumer end is used to obtain the delay index message, and from the delay index message, query the delay index message with the delay time carried by the delay index message as the target delay index message, obtain the delay message corresponding to the message identifier carried by the target delay index message as the target delay message, and send the target delay message to the message middleware.

8. A delayed message sending device, It is characterized in that Applied to the consumer end, the device comprises: A first acquisition module is used to acquire a delay index message; wherein the delay index message is generated by the production end, and the delay index message carries a message identifier of the delay message and a delay time of the delay message; A message query module, used to query the delay index message from the delay index message, and use the delay index message as the target delay index message; A second acquisition module is used to acquire a delay message corresponding to the message identifier carried by the target delay index message as a target delay message; The message sending module is used to send the target delayed message to the message middleware.

9. A delayed message sending device, It is characterized in that Applied to the production end, the device includes: The third acquisition module is used to obtain the delayed message; A message generating module, used for generating a delay index message corresponding to the delay message according to the message identifier of the delay message and the delay time of the delay message; An index sending module is used to send the delayed index message to the consumer end; the consumer end is used to obtain the delayed index message, query the delayed index message with the delay time carried by the delayed index message from the delayed index message, use it as the target delayed index message, obtain the delay message corresponding to the message identifier carried by the target delayed index message, use it as the target delayed message, and send the target delayed message to the message middleware.

10. A computer device comprising a memory and a processor, wherein the memory stores a computer program. It is characterized in that When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

11. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

12. A computer program product comprising a computer program, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.