Message push method and system

By using message queues and consumer interfaces in the message push system to respond to time-consuming feedback and dynamically adjust message distribution and flow control, the problems of message backlog and delivery delay are solved, and efficient message delivery is achieved.

CN116319649BActive Publication Date: 2025-09-16BAIWANG CLOUD TECHNOLOGY (BEIJING) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310300542.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-24
Publication Date
2025-09-16
Estimated Expiration
2043-03-24

AI Technical Summary

Technical Problem

Existing message push systems are prone to message backlogs, loss, and delivery delays when faced with traffic peaks and inconsistent response speeds of consumer interfaces, and are unable to effectively control the message delivery rate.

Method used

By responding to time-consuming feedback through message queues and consumer interfaces, we dynamically adjust message distribution to the corresponding fast, medium, and slow queues. We combine the current limiting strategy to control the message delivery rate to ensure that fast consumers are not slowed down by slow consumers.

Benefits of technology

It improves the message delivery efficiency, avoids the delivery delay caused by the mutual influence between consumers, and ensures the efficient delivery of fast consumers and the timeliness of messages.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116319649B_ABST
    Figure CN116319649B_ABST
Patent Text Reader

Abstract

The present application discloses a message push method and system, which includes the following steps: receiving messages from message producers, and sending the messages to the first-level topic of the message queue; periodically updating the statistical result data of the push time consumption of all consumers, determining the target consumer of the message through message routing, judging the fast, medium and slow intervals to which the target consumer belongs based on the statistical result of the push time consumption of the target consumer, and dynamically distributing the messages in the first-level topic to the second-level topic corresponding to the fast, medium and slow intervals in the message queue; delivering the messages in the second-level topic to the target consumer, and periodically counting and storing the push time consumption of each consumer. The embodiment of the present application sends messages to the corresponding message queue, which can avoid delivery delays caused by mutual influence between consumers, ensure that the delivery rate of fast consumers is not slowed down by slow consumers, and thus improve the delivery efficiency of messages.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of computer technology, and specifically relates to a message push method and system. Background Art

[0002] In complex business scenarios and technical architectures, a unified message push system is often provided to meet inter-service message push requirements. As a unified message entry and exit for multiple message producers and consumers, the message push system is responsible for pushing messages from different producers to their respective target consumers.

[0003] However, push systems often face traffic spikes on the producer side. Suddenly, a flood of requests can cause message backlogs, hindering timely responses to producers and potentially leading to system crashes and message loss. When delivering messages to consumers, push systems can face varying response speeds from different consumer interfaces, impacting the timely delivery of other messages queued behind them. Some consumer interfaces may also be unable to handle high traffic volumes due to performance issues, requiring the push system to control the message delivery rate.

[0004] Application Contents

[0005] The purpose of the embodiments of the present application is to provide a message push method and system to solve the defects of the existing message push system in terms of poor timeliness, as well as the problems of message routing and push flow limiting.

[0006] In order to solve the above technical problems, this application is implemented as follows:

[0007] In a first aspect, a message push method is provided, comprising the following steps:

[0008] Receive messages from message producers and send the messages to the first-level topic of the message queue;

[0009] Periodically update the push time statistics for all consumers, determine the target consumer of the message through message routing, and judge the fast, medium and slow intervals of the target consumer based on the push time statistics of the target consumer. Dynamically distribute the messages in the first-level topic to the second-level topics corresponding to the fast, medium and slow intervals in the message queue;

[0010] The messages in the second-level topic are delivered to the target consumers. The push time of each consumer is periodically counted and stored, and the message delivery rate is controlled according to the current limiting strategy.

[0011] In a second aspect, a message push system is provided, comprising:

[0012] A message receiving service is used to receive messages from message producers and send the messages to the first-level topic of the message queue;

[0013] The message distribution agent service is used to periodically update the statistical results of push time consumption for all consumers, determine the target consumer of the message through message routing, and judge the fast, medium and slow intervals of the target consumer based on the statistical results of push time consumption for the target consumer. The messages in the first-level topic are dynamically distributed to the second-level topics corresponding to the fast, medium and slow intervals in the message queue;

[0014] The message delivery agent service is used to consume messages in the second-level topic and deliver them to the target consumer. It periodically counts and stores the push time for each consumer and controls the message delivery rate according to the current limiting strategy.

[0015] The embodiment of the present application sends messages to the corresponding message queues based on the average time it takes to deliver messages to the target consumers. Messages in different message queues are consumed by different thread pools of the second-level server nodes, which can avoid delivery delays caused by mutual influence between consumers and ensure that consumers with fast consumption speeds always consume quickly without being slowed down by slow consumers, thereby improving the delivery efficiency of messages. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 This is a flow chart of a message push method provided by an embodiment of the present application;

[0017] Figure 2 This is a structural diagram of a message push system provided by an embodiment of the present application;

[0018] Figure 3 This is a specific implementation diagram of the message push system provided in the embodiment of the present application;

[0019] Figure 4 This is a schematic diagram of message routing distribution provided by an embodiment of the present application;

[0020] Figure 5 This is a schematic diagram of the message delivery time consumption feedback adaptive adjustment queue provided in an embodiment of the present application. DETAILED DESCRIPTION

[0021] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0022] In the process of delivering messages to consumers, the push system will face the problem of different consumer interfaces responding at different speeds, which will affect the timeliness of the delivery of other messages waiting to be delivered. Some consumer interfaces may not be able to handle large traffic requests due to performance reasons and require the push system to control the rate of message delivery to them. The message push system must also have message routing and filtering capabilities to ensure the accuracy of message delivery, thereby avoiding misdelivery or missed messages.

[0023] Based on the above problems and needs, the embodiments of the present application provide a push system message delivery method, which solves the peak shaving of received message traffic through message queues (Message Queue, abbreviated as: MQ); adaptively adjusts the fast, medium and slow queues of messages to be pushed through consumer interface response time feedback, and solves the mutual influence problem caused by the different speeds of different interfaces; actively limits the flow of push interfaces through partitioned messages; and realizes accurate routing and filtering of messages through message routing matching conditions.

[0024] The message push method provided by the embodiment of the present application is described in detail below with reference to the accompanying drawings through specific embodiments and their application scenarios.

[0025] like Figure 1 FIG. 1 is a flow chart of a message push method provided in an embodiment of the present application, and the method includes the following steps:

[0026] Step 101: Receive a message from a message producer and send the message to a first-level topic in a message queue.

[0027] The first-level topic of the message queue may be route_topic, which is used to store messages from message producers.

[0028] Step 102: Periodically update the push time statistics for all consumers, determine the target consumer of the message through message routing, judge the fast, medium and slow intervals to which the target consumer belongs based on the push time statistics for the target consumer, and dynamically distribute the messages in the first-level topic to the second-level topics corresponding to the fast, medium and slow intervals in the message queue.

[0029] Specifically, the message event code and event matching condition specified by the message producer may be used as conditions to search for a target consumer that matches the message. If no target consumer is matched, the message is discarded.

[0030] The second-level topic may be one of fast_topic, normal_topic, and slow_topic, and is used to store messages to be pushed between the message distribution service and the message delivery agent service.

[0031] Step 103: consuming messages in the second-level topic and delivering them to the target consumer. Periodically counting and storing the push time for each consumer, and controlling the message delivery rate according to the current limiting strategy.

[0032] In this embodiment, after the message is delivered to the target consumer by starting the server node corresponding to the second-level topic, the average time consumed in delivering the message to the target consumer may be periodically counted according to the interface address dimension.

[0033] In addition, before delivering the message to the target consumer by starting the server node corresponding to the second-level topic, you can also specify the partition key corresponding to the message. The partition key is an identifier used to control the consumption physical partition. Messages corresponding to the same partition key are stored in the same partition and delivered to the corresponding consumer by the same server node.

[0034] Before delivering the message to the target consumer by starting the server node corresponding to the second-level topic, it is also possible to check whether the target consumer has enabled current limiting control. If current limiting control is enabled, if the number of concurrent threads pushing the message at the same time reaches a threshold, the message will be put back into the second-level topic of the message queue and pushed again after waiting for a preset time.

[0035] The embodiment of the present application sends messages to the corresponding message queue based on the average time it takes to deliver messages to the target consumer, which can avoid delivery delays caused by mutual influence between consumers, ensure that fast consumers are not slowed down by slow consumers, and thus improve the delivery efficiency of messages.

[0036] like Figure 2 FIG. 1 is a schematic diagram of a message push system according to an embodiment of the present application, including:

[0037] The message receiving service 210 is used to receive messages from message producers and send the messages to the first-level topic of the message queue.

[0038] The message distribution agent service 220 is used to periodically update the statistical results of the push time of all consumers, determine the target consumer of the message through message routing, judge the fast, medium and slow intervals to which the target consumer belongs based on the statistical results of the push time of the target consumer, and dynamically distribute the messages in the first-level topic to the second-level topic corresponding to the fast, medium and slow intervals in the message queue.

[0039] Specifically, the message distribution agent service 220 is specifically configured to use the message event code and event matching condition specified by the message producer as conditions to search for a target consumer that matches the message, and discard the message if no target consumer is matched.

[0040] In this embodiment, the message distribution agent service 220 is also used to specify the partition key corresponding to the message. The partition key is an identifier used to control the consumption physical partition. Messages corresponding to the same partition key are stored in the same partition and delivered to the corresponding consumers by the same server node.

[0041] The message delivery agent service 230 is used to consume the messages in the second-level topic and deliver them to the target consumer, periodically count and store the push time of each consumer, and control the message delivery rate according to the current limiting strategy.

[0042] In this embodiment, the message delivery agent service 230 is further configured to periodically calculate the average time taken to deliver a message to the target consumer according to the interface address dimension.

[0043] In addition, the message delivery agent service 230 is also used to check whether the target consumer has enabled flow control; when flow control is enabled, if the number of concurrent threads that push the message at the same time reaches a threshold, the message will be put back into the second-level topic of the message queue, and the message will be pushed again after waiting for a preset time.

[0044] The embodiment of the present application sends messages to the corresponding message queue based on the average time it takes to deliver messages to the target consumer, which can avoid delivery delays caused by mutual influence between consumers, ensure that fast consumers are not slowed down by slow consumers, and thus improve the delivery efficiency of messages.

[0045] In an embodiment of the present application, the message routing and filtering strategy in the message delivery process distributes a message to 0 or N consumers; when delivering messages to message consumers, the queue of subsequent messages can be dynamically adjusted according to the response time of the consumer interface to prevent slow consumers from affecting other faster consumers, so that fast consumers can receive messages with less delay, and the number of concurrent requests can be controlled through the current limiting strategy in the message delivery process to avoid overwhelming consumer services.

[0046] Specifically, the message receiving service is used to receive producer messages through the http service interface. The producer assembles the push request message according to the data format required by the push system. After receiving the message, the message receiving service returns a response message to confirm that the message is received successfully, and at the same time sends the message to the queue MQ (queue name: route_topic) for asynchronous processing of the push. Figure 3 shown.

[0047] The message distribution agent service consumes messages from the MQ queue (queue name: route_topic), routes messages to the target consumer based on the push rules configured by the push system, and then dynamically and adaptively sends messages to the MQ fast, medium, and slow topics based on the average delivery time to the target recipient. The push rule configuration parameters specify whether to limit the flow of messages to MQ. If this is required, the message partition key is set to the current interface ID.

[0048] The message delivery agent service starts three consumer groups to consume fast, medium and slow topic messages from the MQ queue respectively (if the message distribution agent service specifies a message partition key, the partition key message will only be consumed by the same server within the same period of time), delivers the message to the interface of the target recipient system, and periodically calculates the average delivery time based on the interface address dimension. If the message has a flow limit threshold set, the flow limit control is enabled. If it is detected that the threshold is exceeded before the message is delivered, the message will be returned to the queue MQ and wait for retry later.

[0049] The push system requires two levels of queue topics. The first level topic (queue name: route_topic) is used between the message receiving service and the message distribution service to store producer messages and reduce traffic peaks. The second level topic (queue names: fast_topic, normal_topic, slow_topic) is used between the message distribution service and the message delivery agent service to store fast, medium, and slow messages to be pushed after push time feedback.

[0050] The message push system in the embodiment of the present application can achieve the following functions:

[0051] Message routing filtering function: The producer registers the event code code in the push system to uniquely identify the pushed message, and then configures the message routing rules. The routing rule parameters set the associated event code code, event matching condition routeKeys, message consumer interface address url, and concurrent flow limit threshold limitNum. The producer must specify the code when sending a message, and specify routeKeys as needed. The message distribution service uses the code + routeKeys as the condition to find the target consumer that matches the message. According to the message routing rule configuration, a message sent by the producer may match 0 or N consumers, such as Figure 4 As shown, when the number of matches is 0, it means that the message has no consumer and can be filtered out.

[0052] Adaptive message queuing function with consumption time feedback: The message delivery agent service uses the receiving system interface URL as the statistical dimension, and saves the total time and total number of calls to each interface within a time period N (for example, 30 seconds as a period). After the end of this statistical period, the average time of each interface is calculated, and the fast, medium, and slow queue names are bound to the interface based on the average time, and then statistics are restarted in the next time period. The message distribution agent service randomly selects a queue name based on the queue name bound to the interface feedback from the delivery agent service if the bound queue is not found, and then sends the message to the MQ queue to dynamically adjust the message in the fast, medium, and slow queues according to the fluctuation of the message delivery time, ensuring that the fast queue delivers messages with short delivery time, and the slow queue delivers messages with long delivery time. The fast message channel will not be affected by the slow interface and slow down the delivery efficiency.

[0053] Consumer interface current limiting function: The message delivery service adopts a push method, calling the consumer interface URL through an http request and synchronously waiting for the response. The message distribution agent service specifies the partition key shadingKey when sending messages to MQ. ShadingKey is the identifier used by the message queue to control the consumption physical partition. Messages with the same shadingKey will be stored in the same partition. When the message delivery agent service consumes from MQ, each node consumes messages in a fixed number of partitions. Before pushing the message, it checks whether the current consumer URL has current limiting enabled. If current limiting is enabled, the number of concurrent threads pushing the message at the same time is controlled. When the threshold is reached, the message is put back into the queue MQ and waits for a period of time before trying to deliver again.

[0054] Specifically, the adaptive message queuing function with consumption time feedback is implemented as follows:

[0055] 1. Create three topics in the message queue MQ: fast_topic is the fast message queue, normal_topic is the normal message queue, and slow_topic is the slow message queue. The three queues themselves only have different names. Fast, medium, and slow are a division of the message push system.

[0056] 2. Use cache middleware (such as redis) as a shared storage medium for periodic statistical results of consumption time, for data sharing between message distribution agent service and message delivery service, such as Figure 5 shown.

[0057] 3. In the message delivery agent service, a scheduled task is started with an execution cycle of every N seconds. The start time of each message is recorded before it is delivered to the receiving system. After the interface responds, the push time (in milliseconds) is calculated and added to the total time consumed by the interface in this cycle (totalTime) and the total number of times (totalCount). When the scheduled task is executed, the average time consumed (in milliseconds) is calculated: avgTime = totalTime / totalCount. The queue name corresponding to the interface is determined based on the average time consumed. The mapping relationship between different time consumption ranges and queue names is as follows:

[0058] fast_topic: time range [0 <avgTime<200]

[0059] normal_topic: time range [200 <= avgTime < 500]

[0060] slow_topic: time consumption range [500 <= avgTime]

[0061] The time consumption ranges for fast, medium, and slow queues can be divided into different ranges, and parameter settings can be modified. After calculating the relationship between each interface and queue name, the data is reported to the cache middleware for storage. The data format example is: [{"topic":"fast_topic","url":"http: / / demo.url"},{"topic":"slow_topic","url":"http: / / demo1.url"}]

[0062] 4. A scheduled task is started in the message distribution agent service, executed every N seconds. During each execution, the data stored in the cache middleware is read into local memory. Each time a message is distributed, a matching topic is searched based on the message receiver interface URL. If the URL is not found in the reported data, a topic is randomly selected from the fast, medium, or slow queues, and the message is then sent to MQ.

[0063] 5. The message delivery agent service and the distribution agent service repeat steps 3 and 4 in each statistical period, so that the message distribution service can achieve the effect of continuous dynamic adaptive adjustment based on the time-consuming statistical data.

[0064] The specific implementation method of the consumer interface current limiting function is as follows: the message delivery agent service consumes messages from some partitions on each node in the cluster. Before pushing the message, it checks whether the current consumer URL has current limiting enabled. If current limiting is enabled, it controls the number of concurrent threads that push the message at the same time. When the threshold is reached, the message is put back into the queue MQ and waits for a while before trying to deliver it again.

[0065] When using the technical solution of the embodiment of the present application for message delivery, it can effectively avoid the impact of some slow interfaces that cause the timeliness of delivery of other receiving system interfaces to be slowed down, and can ensure that messages with fast response speeds are delivered efficiently. At the same time, it can also actively control the delivery rate of different consumers.

[0066] The present application also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the various processes of the above-mentioned message push method embodiment are implemented and can achieve the same technical effect. To avoid repetition, the details are not described here. The computer-readable storage medium is, for example, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0067] It should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or apparatus comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or apparatus comprising the element.

[0068] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.

[0069] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of this application, ordinary technicians in this field can also make many forms without departing from the purpose of this application and the scope of protection of the claims, all of which are within the protection of this application.

Claims

1. A message push method, characterized in that: The following steps are involved: Receive messages from message producers and send the messages to the first-level topic of the message queue; Periodically update the push time statistics for all consumers, determine the target consumer of the message through message routing, judge the fast, medium and slow interval of the target consumer based on the push time statistics of the target consumer, and dynamically distribute the messages in the first-level topic to the second-level topic corresponding to the fast, medium and slow interval in the message queue; Messages in the second-level topic are delivered to the target consumers. The push time for each consumer is periodically counted and stored, and the message delivery rate is controlled according to the current limiting strategy. After the message in the second-level consumption topic is delivered to the target consumer, the following steps are also included: Periodically calculate the average time it takes to deliver messages to the target consumer based on the interface address dimension; Before the message in the second-level consumption topic is delivered to the target consumer, the following steps are also included: Specify the partition key corresponding to the message. The partition key is an identifier used to control the physical partition of consumption. Messages corresponding to the same partition key are stored in the same partition and delivered to the corresponding consumer by the same server node. Before the message in the second-level consumption topic is delivered to the target consumer, the following steps are also included: Check whether the target consumer has enabled current limiting control; When current limiting control is enabled, if the number of concurrent threads pushing the message reaches the threshold, the message will be put back into the second-level topic of the message queue and pushed again after waiting for a preset time. Determining the target consumer of the message through message routing specifically includes: The message event code and event matching condition specified by the message producer are used as conditions to find a target consumer that matches the message. If no target consumer is matched, the message is discarded.

2. A message push system, characterized in that: include: A message receiving service is used to receive messages from message producers and send the messages to the first-level topic of the message queue; The message distribution agent service is used to periodically update the statistical results of push time consumption for all consumers, determine the target consumer of the message through message routing, and judge the fast, medium and slow intervals of the target consumer based on the statistical results of push time consumption for the target consumer. The messages in the first-level topic are dynamically distributed to the second-level topics corresponding to the fast, medium and slow intervals in the message queue; Message delivery agent service, which consumes messages from the second-level topic and delivers them to the target consumer. It periodically counts and stores the push time for each consumer and controls the message delivery rate according to the current limiting strategy. The message delivery agent service is further used to periodically calculate the average time it takes to deliver messages to the target consumer according to the interface address dimension; The message distribution agent service is further used to specify a partition key corresponding to the message. The partition key is an identifier used to control the physical partition for consumption. Messages corresponding to the same partition key are stored in the same partition and delivered to the corresponding consumer by the same server node. The message delivery agent service is further configured to check whether the target consumer has enabled rate limiting control; if rate limiting control is enabled, if the number of concurrent threads simultaneously pushing the message reaches a threshold, the message is placed back into the second-level topic of the message queue and the message is pushed again after a preset waiting time. The message distribution agent service is specifically used to use the message event code and event matching condition specified by the message producer as conditions to find a target consumer that matches the message, and discard the message if no target consumer is matched.

Citation Information

Patent Citations

  • Method used for message distribution and consumption and apparatus thereof, and system used for message processing

    CN104935622A

  • Unified message pushing method, system and device and computer readable storage medium

    CN112565405A