A method and apparatus for consuming delayed messages

CN114936100BActive Publication Date: 2026-08-14BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-23
Publication Date
2026-08-14

AI Technical Summary

Technical Problem

[0004]延时时长通常在生产端配置,不同消费端得到的消息的延时时长相同,无法根据自身需求配置延时时长,导致消费端的对延时消息的消费时间较不灵活;且延时消息通常需要根据不同的延时时长在服务端占用额外的存储空间,耗费了一些用于存储的资源和时间,从而降低了消费的稳定性

Benefits of technology

[0040]上述发明中的一个实施例具有如下优点或有益效果:能够从起始位点确定目标延时消息,并根据自身设置的延时消费时长对已到期的目标延时消息进行消费,由此,不同消费端可以根据需求配置不同的延时消费时长,对延时消息进行消费,使得对延时消息的消费时间更加灵活,提高了消费端对延时消息消费的可定制性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114936100B_ABST
    Figure CN114936100B_ABST
Patent Text Reader

Abstract

This invention discloses a method and apparatus for consuming delayed messages, relating to the field of computer technology. One specific embodiment of the method includes: receiving a consumption instruction, the consumption instruction including a delayed consumption duration and a starting point; determining one or more target delayed messages from the starting point; determining one or more expired target delayed messages based on the production time corresponding to each of the one or more target delayed messages and the delayed consumption duration; and consuming the one or more expired target delayed messages. This embodiment allows different consumers to configure different delayed consumption durations according to their needs, making the consumption time of delayed messages more flexible and improving the customizability of delayed message consumption by the consumer.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a method and apparatus for consuming delayed messages. Background Technology

[0002] Currently, delayed messages are typically generated by the production end, which configures the delay duration and sends the delayed messages to the server. The server stores the delayed messages according to different delay durations. When delivering delayed messages, the server delivers the expired delayed messages to the consumer end for consumption, based on the different delay durations.

[0003] In the process of realizing this invention, the inventors discovered at least the following problems in the prior art:

[0004] Delay duration is usually configured on the production side. Different consumers receive messages with the same delay duration, making it impossible to configure the delay duration according to their own needs. This results in less flexible consumption time for delayed messages by the consumers. Furthermore, delayed messages usually require additional storage space on the server side depending on the different delay durations, consuming some storage resources and time, thereby reducing the stability of consumption. Summary of the Invention

[0005] In view of this, embodiments of the present invention provide a method and apparatus for consuming delayed messages, which can determine the target delayed message from the starting point and consume the expired target delayed message according to its own set delayed consumption duration. Thus, different consumers can configure different delayed consumption durations according to their needs to consume delayed messages, making the consumption time of delayed messages more flexible and improving the customizability of delayed message consumption by the consumer.

[0006] Furthermore, since the delay duration is set on the consumer side, the server can store delayed messages based on their production time, eliminating the need for additional storage based on the delay duration set on the production side. This saves storage resources and time, thereby improving the stability and efficiency of consumption.

[0007] To achieve the above objectives, according to a first aspect of the present invention, a method for consuming delayed messages is provided, comprising:

[0008] Receive a consumption instruction, the consumption instruction including a delayed consumption duration and a start point;

[0009] One or more target delayed messages are determined from the starting point;

[0010] Based on the production time corresponding to the one or more target delayed messages and the delayed consumption duration, determine one or more target delayed messages that have expired;

[0011] Consume the one or more target delayed messages that have expired.

[0012] Optionally, determining one or more target delayed messages from the starting point includes:

[0013] Retrieve one or more delayed messages from the starting point;

[0014] Determine the message location and message type of the delayed message;

[0015] The delayed message whose message position is not less than the starting position and whose message type is non-control type is used as the target delayed message.

[0016] Optionally, the consumption instruction further includes an end point and / or a message quantity, and the step of pulling one or more delayed messages from the start point includes:

[0017] The delayed message is retrieved from the starting point based on the ending point and / or the number of messages.

[0018] Optionally, if it is determined that the difference between the end point and the start point is greater than the number of messages, after consuming one or more expired target delayed messages, the method further includes:

[0019] Determine the metadata corresponding to the retrieved delayed message;

[0020] In the metadata, determine the origin point corresponding to the last expired target delayed message;

[0021] The original position is incremented, and the incremented original position is used as the starting position for the next message retrieval, and the starting position is sent to the server.

[0022] Optionally, consuming one or more expired target delayed messages includes:

[0023] The one or more expired target delayed messages are consumed according to the order of the message positions corresponding to the one or more expired target delayed messages.

[0024] Optionally, if it is determined that the target delayed message has not expired, the method further includes:

[0025] Stop consuming the target delayed message and use the message position of the unexpired target delayed message as the starting position for the next message retrieval.

[0026] Optionally, based on the production time of the one or more target delayed messages and the delayed consumption duration, one or more expired target delayed messages are determined, including:

[0027] If the difference between the current time and the production time corresponding to the target delayed message is greater than or equal to the delayed consumption duration, it is determined that the target delayed message has expired.

[0028] According to a second aspect of the present invention, a consumer of delayed messages is provided, comprising: a receiving module, a determining module, and a consuming module; wherein,

[0029] The receiving module is used to receive a consumption instruction, which includes a delayed consumption duration and a starting point.

[0030] The determining module is configured to determine one or more target delayed messages from the starting point; and determine one or more expired target delayed messages based on the production time of the one or more target delayed messages and the delayed consumption duration.

[0031] The consumption module is used to consume the one or more expired target delayed messages.

[0032] According to a second aspect of the present invention, a delayed message consumption system is provided, characterized in that it includes: a consumer end, a producer end, and a server end as described in the foregoing technical solution; wherein,

[0033] The production end is used to generate one or more delayed messages and send the delayed messages to the server.

[0034] The server is used to store the delayed messages sent by the producer and the starting point for the next message retrieval returned by the consumer.

[0035] According to a fourth aspect of the present invention, an electronic device is provided, comprising:

[0036] One or more processors;

[0037] Storage device for storing one or more programs.

[0038] When the one or more programs are executed by the one or more processors, the one or more processors implement any of the methods described in the delayed message consumption method provided in the first aspect above.

[0039] According to a fifth aspect of the present invention, a computer-readable medium is provided having a computer program stored thereon, which, when executed by a processor, implements any of the methods described in the method for consuming a delayed message provided in the first aspect above.

[0040] One embodiment of the above invention has the following advantages or beneficial effects: it can determine the target delayed message from the starting point and consume the expired target delayed message according to its own set delayed consumption duration. Thus, different consumers can configure different delayed consumption durations according to their needs to consume delayed messages, making the consumption time of delayed messages more flexible and improving the customizability of delayed message consumption by the consumer.

[0041] Furthermore, since the delay duration is set on the consumer side, the server can store delayed messages based on their production time, eliminating the need for additional storage based on different delay durations set on the production side. This saves storage resources and time, thereby improving the stability and efficiency of consumption.

[0042] The further effects of the aforementioned unconventional alternative methods will be explained below in conjunction with specific implementation methods. Attached Figure Description

[0043] The accompanying drawings are provided to better understand the invention and are not intended to unduly limit the scope of the invention. Wherein:

[0044] Figure 1 This is a flowchart illustrating a delayed message consumption method according to an embodiment of the present invention;

[0045] Figure 2 This is a schematic diagram illustrating the retrieval of delayed messages according to another embodiment of the present invention;

[0046] Figure 3 This is a schematic diagram of retrieving delayed messages according to another embodiment of the present invention;

[0047] Figure 4 This is a flowchart illustrating a delayed message consumption method according to another embodiment of the present invention;

[0048] Figure 5 This is a schematic diagram of the structure of a consumer terminal for delayed messages provided in one embodiment of the present invention;

[0049] Figure 6 This is a schematic diagram of the structure of a delayed message consumption system provided in one embodiment of the present invention;

[0050] Figure 7 This is an exemplary system architecture diagram in which embodiments of the present invention can be applied;

[0051] Figure 8 This is a schematic diagram of the structure of a computer system suitable for implementing terminal devices or servers of the present invention. Detailed Implementation

[0052] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of the present invention, including various details to aid understanding. These details should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the invention. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0053] It should be noted that, unless otherwise specified, the embodiments of the present invention and the technical features thereof can be combined with each other.

[0054] like Figure 1 As shown, this embodiment of the invention provides a method for consuming delayed messages, which may include the following steps S101 to S104:

[0055] Step S101: Receive a consumption instruction, which includes a delayed consumption duration and a starting point.

[0056] Step S102: Determine one or more target delayed messages from the starting point.

[0057] Step S103: Based on the production time corresponding to the one or more target delayed messages and the delayed consumption duration, determine one or more target delayed messages that have expired.

[0058] Step S104: Consume the one or more expired target delayed messages.

[0059] One application scenario of this invention is the consumption of delayed messages in a Kafka cluster. Multiple consumers in the Kafka cluster can continuously pull messages from multiple message shards stored on the server for consumption according to their own application needs, and return the position information of the consumed delayed messages to the server for storage.

[0060] The messages can be delayed or instant. Taking delayed messages as an example, a delay consumption period can be set to determine a specific time after the message's production time before consumption. Multiple consumers can set different delay consumption periods according to their application's consumption speed, and then pull expired delayed messages for consumption based on the specified delay consumption period.

[0061] It is understandable that the production end typically produces one or more delayed messages based on application requirements and sends these delayed messages to the server for storage; while the consumer end typically receives a consumption instruction and retrieves delayed messages for consumption according to the instruction. In one embodiment of the present invention, the consumption instruction includes a delayed consumption duration to determine which delayed messages among the retrieved messages have expired, and the consumption instruction also includes a start point. The start point can be read from the server and is saved to the server by the consumer after the previous consumption. The previous consumption can be the previous consumption of the same consumer retrieved this time, or the previous consumption of another consumer before the current retrieval.

[0062] Once the starting point is determined, the starting position for message retrieval is established. When stored on the server side of a Kafka cluster, different consumers can pull delayed messages from different consumption shards in parallel for consumption. The message shards corresponding to multiple consumers pulling messages in parallel are all different. Therefore, the starting point represents the starting address of a partition and the offset of the initial delayed message to be pulled within that partition.

[0063] Next, the target delayed message can be determined using the following method provided in an embodiment of the present invention: pull one or more delayed messages from the starting point; determine the message position and message type of the delayed message; and take the delayed message whose message position is not less than the starting point and whose message type is non-control type as the target delayed message.

[0064] When retrieving one or more delayed messages from the starting point, the following method provided in the embodiments of the present invention can be used: retrieving the delayed messages from the starting point according to the ending point and / or the number of messages.

[0065] You can retrieve multiple delayed messages corresponding to the number of messages at the starting point at once. For example, you can retrieve 100 delayed messages at once; or you can retrieve all delayed messages from the starting point to the ending point at once.

[0066] To retrieve each delayed message, first determine the message position of each delayed message, i.e., its offset within the partition. Then, check if the message position of each delayed message is greater than or equal to the starting position. If it is, the delayed message is a normal delayed message; if it is less, it is an abnormal delayed message. For example, if the starting position offset is 3, and a delayed message has an offset of 4, then that delayed message is normal; if another delayed message has an offset of 2, then that delayed message is abnormal. Additionally, some delayed messages may be control type messages. For example, when using transactional messages, control type messages can be used to allow the consumer to filter out aborted transactional messages. In this case, the control type message can be 0, indicating that the transactional message is in an aborted state, or 1, indicating that the transactional message is in a committed state.

[0067] It is understandable that, among one or more delayed messages retrieved, delayed messages whose message position is normal (i.e., the message position is not less than the starting position) and are not of the control type are selected as target delayed messages.

[0068] After identifying one or more target delayed messages, the following method provided by the embodiments of the present invention can be used to determine whether these target delayed messages have expired, that is, whether the consumption time determined by the delayed consumption duration has arrived: if the difference between the current time and the production time corresponding to the target delayed message is greater than or equal to the delayed consumption duration, it is determined that the target delayed message has expired.

[0069] For example, for each target delayed message, the time difference between the timestamp (i.e., production time) of the target delayed message and the current time can be determined. Then, it can be determined whether the time difference is greater than or equal to the delayed consumption duration in the consumption instruction. If it is greater than or equal to, the target delayed message has expired; if it is less than, the target delayed message has not expired.

[0070] For expired target delayed messages, the following method provided in the embodiments of the present invention can be used for consumption: the expired target delayed messages are consumed according to the order of the message positions corresponding to the one or more expired target delayed messages.

[0071] Understandably, multiple target delayed messages can be stored sequentially according to their respective production times. In other words, the message positions of the retrieved target delayed messages are sequentially incremented according to their production times. When consuming multiple expired target delayed messages, they can be consumed sequentially according to the order of their message positions. When consuming multiple expired target delayed messages, a consumption position flag can be set. After consuming each target delayed message, the consumption position flag is incremented by 1, moving the flag to the next target delayed message for verification of its expiration. Figure 2 and Figure 3 In this system, each delayed message has an offset (message position) and a timestamp (representing the production time). For example, the offset can be 1, 2, 3, 4, 5, 6, 7, or 8, while the timestamp can be xxx, yyy, zzz, www, aaa, bbb, ccc, or ddd. The consumption position marker is incremented after each delayed message is consumed, pointing to the next delayed message.

[0072] In one embodiment of the present invention, for abnormal delayed messages (i.e., messages whose position is less than the starting position) or control-type delayed messages, these messages can be ignored directly and not consumed. The consumption position mark will still be incremented by 1 so as to move to the next target delayed message.

[0073] For target delayed messages that have not yet expired, the following method provided in this embodiment of the invention can be used for processing: stop consuming the target delayed message and use the message position of the target delayed message that has not yet expired as the starting position for the next message retrieval.

[0074] Since delayed messages can be stored sequentially according to their production time, if a target delayed message is determined to be unexpired, then all subsequent target delayed messages are also unexpired. At this point, processing of subsequent target delayed messages can be stopped. The consumption position marker is not incremented by 1 and remains at the message position of the unexpired delayed message. The message position of the currently unexpired target delayed message can be used as the starting point for the next message retrieval, and the starting point for the next retrieval is returned to the server for storage, so as to serve as the starting point for the next retrieval operation by the consumer.

[0075] In a Kafka cluster, there can be compact topics and non-compact topics. For non-compact topics, the positions of multiple delayed messages fetched are consecutive, such as... Figure 2 The message offsets for multiple messages in message batch 1 or message batch 2 are retrieved from the middle. For compact topics, multiple delayed messages are stored after updating and overwriting based on their key values; that is, they are stored after a compaction operation. For multiple delayed messages with the same key, only the latest delayed message is retained. Therefore, the message positions of the retrieved delayed messages are not contiguous; that is, the message position (offset) could be 1, 3, 9, 20, etc. Figure 3 The offsets corresponding to multiple messages in compact message batch 1 or multiple messages in compact message batch 2.

[0076] After all the expired target delayed messages retrieved in this batch have been consumed, for non-compact topics, the current consumption position marker may be at the boundary between expired and unexpired delayed messages in the current batch of delayed messages, that is, at the message position of the first unexpired target delayed message. In this case, the current consumption position marker can be directly used as the starting point for the next message retrieval.

[0077] After all expired target delayed messages retrieved this time have been consumed, for compact topics, since the message positions of multiple delayed messages are not consecutive, the offset indicated by the current consumption position marker may not be the starting point for the next message retrieval. Therefore, the starting point for the next message retrieval needs to be updated. Otherwise, the starting point for the next retrieval may not correspond to the actual unexpired message positions, causing the next retrieval to start from a message position that has already been retrieved, resulting in duplicate retrieval of some delayed messages and reducing consumption efficiency. To avoid duplicate retrieval and improve retrieval efficiency, in one embodiment of the present invention, when consuming delayed messages corresponding to compact topics in a Kafka cluster, the following method can be adopted: First, determine that the difference between the end position and the start position is greater than the number of messages, then determine the metadata corresponding to the retrieved delayed messages; in the metadata, determine the original position corresponding to the last expired target delayed message; increment the original position, use the incremented original position as the starting point for the next message retrieval, and send the starting position to the server.

[0078] Understandably, the way to distinguish whether the current topic is of the compact type is to determine the difference between the end point and the start point in the consumption instruction. If the difference is equal to the number of messages, then the offsets of multiple delayed messages are continuous, and it is a non-compact topic. If the difference is greater than the number of messages, then the offsets of multiple delayed messages are not continuous and there are gaps, and it is a compact topic.

[0079] When it's determined that the currently fetched topic is of the compact type, the metadata corresponding to the currently fetched batch of delayed messages can be identified. This is the metadata prior to the compaction operation. It can be understood that the offsets in the metadata are continuous. Within the metadata, the origin point corresponding to the last expired target delayed message can be determined. For example... Figure 3 In the compact message batch 1, the offset of the last target delayed message 20 is 20, while the offset of the first message 25 in the compact message batch 2 is 25. After the consumption of message 20 is completed, the original position (i.e. the original offset) of message 20 in the metadata can be determined. Then, the original position is incremented and the incremented original position is used as the starting position of the next message retrieval. Figure 3 The origin of message 20 can be 24. Adding 1 to 24 gives 25, which means the starting point of the next message retrieval is 25, corresponding to the offset of message 25. Therefore, by updating the starting point of the next message retrieval after consuming a compact topic, the accuracy of determining the next message retrieval can be improved, thus increasing consumption efficiency.

[0080] The following example uses the consumer side of a Kafka cluster to consume delayed messages, combined with... Figure 2 , Figure 3 and Figure 4 This paper provides a detailed description of a delayed message consumption method provided by an embodiment of the present invention. Figure 4 This is a flowchart illustrating a delayed message consumption method according to another embodiment of the present invention, the steps of which include S401 to S416:

[0081] Step S401: Start fetching and retrieve multiple messages.

[0082] That is, it retrieves a specified number of delayed messages from the starting point. These delayed messages can be composed of multiple batches, for example, Figure 2 Message batch 1 includes message 1, message 2, message 3 and message 4, or message batch 2 includes message 5, message 6, message 7 and message 8. Figure 3Compact message batch 1, including messages 1, 3, 9 and 20, or compact message batch 2, including messages 25, 36, 47 and 58.

[0083] Step S402: Determine if the messages in the current batch have been processed. If yes, proceed to step S408; otherwise, proceed to step S403.

[0084] The judgment here can also determine whether the fetched message is empty. It's possible that none of the messages have expired, so the consumer executes an empty fetch operation. For example... Figure 2 This can be used to determine if the retrieved messages are empty before they expire, or to check if all retrieved messages have been consumed.

[0085] Step S403: Obtain a single message.

[0086] Process individual delayed messages.

[0087] Step S404: Determine if the message position is greater than or equal to the starting position. If yes, proceed to step S405; otherwise, proceed to step S407.

[0088] That is, whether the current single delayed message is normal or abnormal.

[0089] Step S405: Determine whether the message type is a control type. If yes, proceed to step S407; otherwise, proceed to step S406.

[0090] Step S406: Return a single message.

[0091] The single message returned is the target delayed message.

[0092] Step S407: Skip the current message and retrieve the next message.

[0093] If the message is an abnormal delay message or a control type delay message, skip the message, increment the consumption position flag by 1, and return to step S401.

[0094] Step S408: Determine if this is the last batch of messages. If yes, proceed to step S410; otherwise, proceed to step S409.

[0095] Step S409: Get the next batch of messages.

[0096] Several delayed messages have not yet been consumed; please retrieve subsequent delayed messages.

[0097] Step S410: Determine if it is a compact message. If yes, proceed to step S411; otherwise, proceed to step S412.

[0098] Step S411: Update the starting point for the next fetch.

[0099] All messages retrieved this time have been consumed. For compact delayed messages (i.e., delayed messages corresponding to compact topics), the origin point corresponding to the last target delayed message needs to be found based on the corresponding metadata. This origin point is incremented by 1 and sent to the server as the starting point for the next message retrieval. The server saves this starting point. The next time a consumption command is initiated, the starting point will be retrieved from the server and sent to the consumer to ensure that the consumer can continue retrieval from the first unexpired target delayed message in this batch, avoiding missed or duplicate message retrieval. Figure 3 In this fetch of delayed messages, the expired delayed messages are messages 1, 3, 9 and 20, and the starting point for the next fetch will be message 25.

[0100] Step S412: Return an empty result.

[0101] If it is a delayed message of a non-compact type, no additional update operation is required.

[0102] Step S413: Return the result.

[0103] Step S414: Determine if the result is empty. If yes, end the current consumption process. If no, proceed to step S415.

[0104] An empty result indicates that the delayed messages that have been processed are the last batch of delayed messages, and the process can be terminated.

[0105] Step S415: Determine if the message has expired. If yes, proceed to step S416; otherwise, end the process.

[0106] In other words, it determines whether the difference between the current time and the production time of the delayed message is greater than or equal to the delayed consumption duration. If so, the delayed message has expired and can be consumed directly. If not, the delayed message has not expired, and none of the subsequent delayed messages have expired either, then the current consumption process is stopped, and the process ends. The message position of the delayed message is returned to the server as the starting point for the next message retrieval and saved. Figure 2 In this case, the expired target delayed messages consumed this time are messages 1 and 2, while messages 3 and 4 have not yet expired. Therefore, the message position to be fetched next time will be the offset of message 3, which has not yet expired, with an offset of 3.

[0107] Step S416: Consume the current message.

[0108] After consuming a single delayed message, increment the consumption position marker by 1, move to the next delayed message, and then return to execute S402 and subsequent steps.

[0109] After the current message retrieval ends, the next message retrieval will involve re-executing steps S401 to S416.

[0110] According to an embodiment of the present invention, a method for consuming delayed messages can determine the target delayed message from the starting point and consume the expired target delayed message according to its own set delayed consumption duration. Thus, different consumers can configure different delayed consumption durations according to their needs to consume delayed messages, making the consumption time of delayed messages more flexible and improving the customizability of delayed message consumption by the consumer.

[0111] Furthermore, since the delay duration is set on the consumer side, the server can store delayed messages based on their production time, eliminating the need for additional storage based on the delay duration set on the production side. This saves storage resources and time, thereby improving the stability and efficiency of consumption.

[0112] like Figure 5 As shown, this embodiment of the invention provides a consumer 500 for delayed messages, including: a receiving module 501, a determining module 502, and a consuming module 503; wherein,

[0113] The receiving module 501 is used to receive a consumption instruction, which includes a delayed consumption duration and a starting point.

[0114] The determining module 502 is used to determine one or more target delayed messages from the starting point; and to determine one or more expired target delayed messages based on the production time of the one or more target delayed messages and the delay consumption duration.

[0115] The consumption module 503 is used to consume the one or more expired target delayed messages.

[0116] In one embodiment of the present invention, the determining module 502 is configured to retrieve one or more delayed messages from the starting point; determine the message position and message type of the delayed message; and select the delayed message whose message position is not less than the starting point and whose message type is non-control type as the target delayed message.

[0117] In one embodiment of the present invention, the determining module 502 is used to retrieve the delayed message from the starting point based on the end point and / or message quantity, as the consumption instruction further includes an end point and / or message quantity.

[0118] In one embodiment of the present invention, the determining module 502 is configured to, when determining that the difference between the end point and the start point is greater than the number of messages, determine the metadata corresponding to the retrieved delayed messages after consuming one or more expired target delayed messages; determine the original point corresponding to the last expired target delayed message in the metadata; use the incremented original point as the starting point for the next message retrieval, and send the starting point to the server.

[0119] In one embodiment of the present invention, the determining module 502 is used to stop consuming the target delayed message when it is determined that the target delayed message has not expired, and to use the message position of the unexpired target delayed message as the starting position for the next message retrieval.

[0120] In one embodiment of the present invention, the determining module 502 is used to determine that the target delayed message has expired if the difference between the current time and the production time corresponding to the target delayed message is greater than or equal to the delayed consumption duration.

[0121] In one embodiment of the present invention, the consumption module 503 is configured to consume the one or more expired target delayed messages according to the order of the message positions corresponding to the one or more expired target delayed messages.

[0122] like Figure 6 As shown, this embodiment of the invention provides a delayed message consumption system 600, including: a consumer end 500, a producer end 601, and a server end 602 as provided in any of the above embodiments; wherein,

[0123] The production terminal 601 is used to produce one or more delayed messages and send the delayed messages to the server.

[0124] The server 602 is used to store the delayed messages sent by the producer and to store the starting point of the next message retrieval returned by the consumer.

[0125] According to an embodiment of the present invention, a delayed message consumption system can determine the target delayed message from the starting point and consume the expired target delayed message according to its own set delayed consumption duration. Thus, different consumers can configure different delayed consumption durations according to their needs to consume delayed messages, making the consumption time of delayed messages more flexible and improving the customizability of delayed message consumption by the consumer.

[0126] Furthermore, since the delay duration is set on the consumer side, the server can store delayed messages based on their production time, eliminating the need for additional storage based on the delay duration set on the production side. This saves storage resources and time, thereby improving the stability and efficiency of consumption.

[0127] Figure 7 An exemplary system architecture 700 is shown, which can be applied to a delayed message consumption method or a delayed message consumption system according to embodiments of the present invention.

[0128] like Figure 7 As shown, system architecture 700 may include terminal devices 701, 702, and 703, network 704, and servers 705 and 706. Network 704 serves as the medium for providing communication links between terminal devices 701, 702, and 703 and servers 705 and 706. Network 704 may include various connection types, such as wired or wireless communication links or fiber optic cables, etc.

[0129] Users can use terminal devices 701, 702, and 703 to interact with servers 705 and 706 via network 704 to receive or send messages, etc.

[0130] Terminal devices 701, 702, and 703 can be various electronic devices with displays that support information browsing, including but not limited to smartphones, tablets, laptops, and desktop computers.

[0131] Servers 705 and 706 can be servers that provide various services, such as providing delayed messages to users via terminal devices 701, 702, and 703. Servers 705 and 706 can process delayed messages by producing, storing, and consuming them, and then feed the processing results back to the terminal devices.

[0132] It should be understood that Figure 7 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.

[0133] The following is for reference. Figure 8 It shows a schematic diagram of the structure of a computer system 800 suitable for implementing a terminal device of the present invention. Figure 8 The terminal device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.

[0134] like Figure 8As shown, the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 802 or programs loaded from storage section 808 into random access memory (RAM) 803. The RAM 803 also stores various programs and data required for the operation of the system 800. The CPU 801, ROM 802, and RAM 803 are interconnected via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0135] The following components are connected to I / O interface 805: an input section 806 including a keyboard, mouse, etc.; an output section 807 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to I / O interface 805 as needed. A removable medium 811, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 810 as needed so that computer programs read from it can be installed into storage section 808 as needed.

[0136] In particular, according to the embodiments disclosed in this invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 809, and / or installed from removable medium 811. When the computer program is executed by central processing unit (CPU) 801, it performs the functions defined above in the system of this invention.

[0137] It should be noted that the computer-readable medium shown in this invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.

[0138] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0139] The modules described in the embodiments of the present invention can be implemented in software or hardware. The described modules can also be housed in a processor; for example, a processor can be described as including a receiving module, a determining module, and a consuming module. The names of these modules do not necessarily limit the module itself; for example, the determining module can also be described as "a module for determining a target delayed message".

[0140] In another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or it may exist independently and not assembled into the device. The computer-readable medium carries one or more programs that, when executed by the device, cause the device to: receive a consumption instruction, the consumption instruction including a delayed consumption duration and a start point; determine one or more target delayed messages from the start point; determine one or more expired target delayed messages based on the production time corresponding to each of the one or more target delayed messages and the delayed consumption duration; and consume the one or more expired target delayed messages.

[0141] According to the technical solution of the present invention, the target delayed message can be determined from the starting point, and the expired target delayed message can be consumed according to the delayed consumption duration set by itself. Thus, different consumers can configure different delayed consumption durations according to their needs to consume delayed messages, making the consumption time of delayed messages more flexible and improving the customizability of delayed message consumption by the consumer.

[0142] Furthermore, since the delay duration is set on the consumer side, the server can store delayed messages based on their production time, eliminating the need for additional storage based on the delay duration set on the production side. This saves storage resources and time, thereby improving the stability and efficiency of consumption.

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

Claims

1. A method for consuming delayed messages, characterized in that, For consumer applications, including: Receive a consumption instruction, the consumption instruction including a delayed consumption duration and a start point; One or more target delayed messages are determined from the starting point; Based on the production time corresponding to the one or more target delayed messages and the delayed consumption duration, determine one or more target delayed messages that have expired; Consume the one or more expired target delayed messages; Determining one or more target delayed messages from the starting point includes: Retrieve one or more delayed messages from the starting point; Determine the message location and message type of the delayed message; The delayed message whose message position is not less than the starting position and whose message type is non-control type is used as the target delayed message.

2. The method according to claim 1, characterized in that, The consumption instruction also includes an end point and / or a message quantity, and the step of pulling one or more delayed messages from the start point includes: The delayed message is retrieved from the starting point based on the ending point and / or the number of messages.

3. The method according to claim 2, characterized in that, If the difference between the end point and the start point is determined to be greater than the number of messages, after consuming one or more expired target delayed messages, the method further includes: Determine the metadata corresponding to the retrieved delayed message; In the metadata, determine the offset corresponding to the last expired target delayed message; The offset is incremented, and the incremented offset is used as the starting point for the next message retrieval, and the starting point is sent to the server.

4. The method according to claim 1, characterized in that, The consumption of the one or more expired target delayed messages includes: The one or more expired target delayed messages are consumed according to the order of the message positions corresponding to the one or more expired target delayed messages.

5. The method according to claim 4, characterized in that, If it is determined that the target delayed message has not expired, the method further includes: Stop consuming the target delayed message and use the message position of the unexpired target delayed message as the starting position for the next message retrieval.

6. The method according to any one of claims 1 to 5, characterized in that, The step of determining one or more expired target delayed messages based on the production time of the one or more target delayed messages and the delayed consumption duration includes: If the difference between the current time and the production time corresponding to the target delayed message is greater than or equal to the delayed consumption duration, it is determined that the target delayed message has expired.

7. A consumer terminal for delayed messages, characterized in that, include: The module consists of a receiving module, a determining module, and a consuming module; among which, The receiving module is used to receive a consumption instruction, which includes a delayed consumption duration and a starting point. The determining module is configured to determine one or more target delayed messages from the starting point; and determine one or more expired target delayed messages based on the production time of the one or more target delayed messages and the delayed consumption duration. The consumption module is used to consume the one or more expired target delayed messages; The determining module is also used for: Retrieve one or more delayed messages from the starting point; Determine the message location and message type of the delayed message; The delayed message whose message position is not less than the starting position and whose message type is non-control type is used as the target delayed message.

8. A delayed message consumption system, characterized in that, include: The consumer end, production end, and service end as described in claim 7; wherein, The production end is used to generate one or more delayed messages and send the delayed messages to the server. The server is used to store the delayed messages sent by the producer and the starting point for the next message retrieval returned by the consumer.

9. An electronic device, characterized in that, include: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-6.

10. A computer-readable medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-6.

Citation Information

Patent Citations

  • Commodity pre-purchasing system

    CN103854213A

  • Producer-Side Prioritization of Message Processing

    US20190324828A1