A method for resolving message accumulation
By controlling the message receiving and sending frequency using the token bucket pattern and combining it with disk storage to handle message backlog, the problem of message backlog in distributed systems is solved, achieving stable system operation and high-efficiency message processing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD
- Filing Date
- 2025-02-07
- Publication Date
- 2026-06-09
Smart Images

Figure CN120034495B_ABST
Abstract
Description
Technical Field
[0001] This invention discloses a method for solving message backlog, relating to the field of message sending management. Background Technology
[0002] In complex distributed systems, different services or components are often tightly coupled. When one service needs to call another, they typically establish direct communication. However, this direct communication makes the system complex and difficult to maintain. Furthermore, when message production exceeds consumption, a large number of messages accumulate within the message service over time. Similarly, functional issues in the message consumer logic or excessively long message consumption times can also lead to message backlog in the queue. Message backlog consumes significant amounts of memory, disk space, and network resources. Excessive message backlog negatively impacts server performance, slowing down processing and potentially exhausting system resources. Summary of the Invention
[0003] This invention addresses the problems of existing technologies by providing a method to solve message backlog, which uses a token bucket to control message reception and to convert messages to disk storage when they accumulate, thereby alleviating system pressure.
[0004] The specific solution proposed in this invention is as follows:
[0005] This invention provides a method for resolving message backlog, comprising:
[0006] Step 1: Configure the parameters in the message processing flow. These parameters include: message type, message queue length, message priority, message flow control ratio, message backlog ratio, maximum message lifespan, and message consumption timeout.
[0007] Step 2: Monitor the production and consumption rates of different message types, the resource usage of message consumers, and the response status after messages are consumed.
[0008] Step 3: Implement message flow control based on message monitoring data to limit the frequency of message reception and transmission.
[0009] Specifically, message flow control is implemented using a token bucket model:
[0010] Create two token buckets for each message type: a message sending token bucket and a message receiving token bucket, and preset the maximum capacity for each.
[0011] For message reception, when the percentage of a certain type of message queue used exceeds the message flow control ratio, the reception rate of this type of message is limited: tokens are added to the message reception token bucket at a fixed rate until the number of tokens in the message reception token bucket reaches the maximum capacity, and then the addition of tokens stops; messages are prioritized and it is determined whether there are still tokens for high-priority messages in the message reception token bucket. If so, the high-priority messages are transferred to the message queue; otherwise, the message sending request is rejected.
[0012] For message sending, when the message consumer resource utilization rate continues to increase, the message sending frequency is limited: tokens are added to the message sending token bucket at a fixed rate until the number of tokens in the message sending token bucket reaches the maximum capacity, and then the addition of tokens stops; messages are prioritized and it is determined whether there are still tokens for high-priority messages in the message sending token bucket. If so, the high-priority messages are sent to the message consumer; otherwise, they are not sent.
[0013] Step 4: Handling Message Backlog: Refer to the message backlog ratio to obtain the current message queue backlog status. When the message queue is about to fill up, continuously reduce the number of tokens generated per unit time for message receiving token buckets that are already in a backlog state; perform deduplication operations on unforwarded messages; store backlogged messages on disk, and clear the token count in the message receiving token buckets of backlogged messages, no longer receiving messages of this type.
[0014] Furthermore, in step 1 of the method for resolving message backlog, message types are configured to distinguish different types of messages;
[0015] Configure message queue length to identify the maximum number of messages of a certain type that can be stored in the system;
[0016] Configure message priority to control the order in which tokens are obtained from the token bucket during the message flow control phase;
[0017] Configure message flow control ratio, which represents the percentage of the number of messages received in the message queue to the total number of queues when message reception flow control is applied;
[0018] Configure message backlog ratio. Message backlog ratio refers to the percentage of the maximum number of messages stored in the message queue to the total number of messages in the message queue. When the total number of messages of a certain type exceeds the message backlog ratio, it indicates that the queue for this type of message is about to be filled.
[0019] Configure the maximum message lifespan. The maximum message lifespan refers to the maximum time a message of a certain type can live in the message queue. Once the maximum message lifespan is exceeded, the message is considered outdated.
[0020] Configure message consumption timeout, which indicates the maximum processing time for this type of message that the consumer is expected to set.
[0021] Furthermore, in step 2 of the method for resolving message backlog, resource reporting requests from message consumers are periodically received, the CPU utilization and memory utilization of the consumers are recorded, and the message consumer's past resource utilization data is used to infer whether the message consumer has the capacity to process messages that need to be consumed. At the same time, a normal consumption status submission request from the message consumer is received. Upon receiving the normal consumption status request from the message consumer, message flow control is canceled according to the message type for which the consumption status is requested, and the data of this message type stored on the disk is read and the message is filled into the message queue of this type to ensure that the message consumer processes unconsumed messages in a timely manner.
[0022] Furthermore, in step 2 of the method for resolving message backlog, the consumer response time of each message is monitored in real time, and the response request is fed back to the message middleware. Messages that have not received a consumer response are polled, and the message consumption timeout time for this type of message is obtained according to the message type. If the difference between the current time and the time when message consumption begins exceeds the consumption timeout time, it indicates that the consumer cannot process the message, the connection with the message consumer will be disconnected, and message forwarding for this type of message will be stopped.
[0023] Furthermore, in step 4 of the method for resolving message backlog, the unforwarded messages are retrieved and deduplicated. This includes: traversing all existing messages in the message queue, determining whether the message's timestamp is in the consumed message timestamp list, and if so, deleting the message from the message queue. Simultaneously, the message's existence time in the message queue is checked. If the message's existence time exceeds the maximum message lifespan, the message is determined to be an expired message and is deleted from the message queue.
[0024] The present invention also provides an apparatus for solving message backlog, comprising a message configuration module, a message monitoring module, a message flow control module, and a message backlog processing module.
[0025] The message configuration module configures the parameter information in the message processing flow. These parameters include: message type, message queue length, message priority, message flow control ratio, message backlog ratio, maximum message lifespan, and message consumption timeout.
[0026] The message monitoring module monitors the production and consumption rates of different message types, the resource usage of message consumers, and the response status after messages are consumed.
[0027] The message flow control module performs message flow control based on message monitoring, limiting the frequency of message reception and transmission.
[0028] Specifically, message flow control is implemented using a token bucket model:
[0029] Create two token buckets for each message type: a message sending token bucket and a message receiving token bucket, and preset the maximum capacity for each.
[0030] For message reception, when the percentage of a certain type of message queue used exceeds the message flow control ratio, the reception rate of this type of message is limited: tokens are added to the message reception token bucket at a fixed rate until the number of tokens in the message reception token bucket reaches the maximum capacity, and then the addition of tokens stops; messages are prioritized and it is determined whether there are still tokens for high-priority messages in the message reception token bucket. If so, the high-priority messages are transferred to the message queue; otherwise, the message sending request is rejected.
[0031] For message sending, when the message consumer resource utilization rate continues to increase, the message sending frequency is limited: tokens are added to the message sending token bucket at a fixed rate until the number of tokens in the message sending token bucket reaches the maximum capacity, and then the addition of tokens stops; messages are prioritized and it is determined whether there are still tokens for high-priority messages in the message sending token bucket. If so, the high-priority messages are sent to the message consumer; otherwise, they are not sent.
[0032] The message backlog processing module handles message backlog: it obtains the current message queue backlog status based on the message backlog ratio, and when the message queue is about to fill up, it continuously reduces the number of tokens generated per unit time for messages that are already in a backlog state; it performs a deduplication operation on unforwarded messages; it stores backlogged messages on disk, and clears the token count in the message receiving token bucket of backlogged messages, no longer receiving messages of this type.
[0033] Furthermore, the message configuration module of the device for resolving message backlog configures message types to distinguish different types of messages;
[0034] Configure message queue length to identify the maximum number of messages of a certain type that can be stored in the system;
[0035] Configure message priority to control the order in which tokens are obtained from the token bucket during the message flow control phase;
[0036] Configure message flow control ratio, which represents the percentage of the number of messages received in the message queue to the total number of queues when message reception flow control is applied;
[0037] Configure message backlog ratio. Message backlog ratio refers to the percentage of the maximum number of messages stored in the message queue to the total number of messages in the message queue. When the total number of messages of a certain type exceeds the message backlog ratio, it indicates that the queue for this type of message is about to be filled.
[0038] Configure the maximum message lifespan. The maximum message lifespan refers to the maximum time a message of a certain type can live in the message queue. Once the maximum message lifespan is exceeded, the message is considered outdated.
[0039] Configure message consumption timeout, which indicates the maximum processing time for this type of message that the consumer is expected to set.
[0040] Furthermore, the message monitoring module of the aforementioned device for resolving message backlog also periodically receives resource reporting requests from message consumers, records the CPU utilization and memory utilization of consumers, and, in conjunction with the message consumers' past resource utilization data, infers whether the message consumers are capable of processing messages that need to be consumed; simultaneously, it receives normal consumption status submission requests from message consumers. Upon receiving a normal consumption status request from a message consumer, it cancels message flow control according to the message type for which the consumption status is requested, reads the data of this message type stored on the disk, and fills the message into the message queue of this type, ensuring that message consumers process unconsumed messages in a timely manner.
[0041] Furthermore, the message monitoring module of the device for resolving message backlog monitors the consumer response time of each message in real time and feeds back the response request to the message middleware. It polls messages that have not received a consumer response, obtains the message consumption timeout time for this type of message according to the message type, and if the difference between the current time and the time when message consumption begins exceeds the consumption timeout time, it indicates that the consumer cannot process the message, disconnects from the message consumer, and stops message forwarding for this type of message.
[0042] Furthermore, the message backlog processing module of the aforementioned device for resolving message backlog performs a retrieval and deduplication operation on unforwarded messages, including: traversing all existing messages in the message queue, determining whether the message's timestamp is in the consumed message timestamp list, if so, indicating that the message has been consumed, deleting the message from the message queue, and simultaneously detecting the message's existing time in the message queue; if the message's existing time exceeds the message's maximum lifespan, determining that the message is an expired message, and deleting the message from the message queue.
[0043] The advantages of this invention are:
[0044] Using the token bucket pattern to control the message receiving mechanism can stabilize the message receiving frequency and prevent system crashes caused by a sudden increase in message load. When the message consumer server is under excessive load, the token bucket pattern limits the number of messages forwarded to the message consumer, reducing the load on the consumer server and ensuring its normal operation.
[0045] It can obtain performance information of all message consumers in real time, making it easier for administrators to understand the message processing capabilities of message consumers;
[0046] For messages that are piling up, the message queue is switched to disk storage to reduce the pressure on the message middleware. After the message consumer repairs its consumption logic, the messages on disk are then switched back to the message queue to ensure that no messages are lost. Attached Figure Description
[0047] Figure 1 This is a schematic diagram of the application process of the method of the present invention. Detailed Implementation
[0048] The present invention will be further described below with reference to the accompanying drawings and specific embodiments, so that those skilled in the art can better understand and implement the present invention. However, the embodiments described are not intended to limit the present invention.
[0049] Example 1
[0050] This invention provides a method for resolving message backlog, comprising:
[0051] Step 1: Configure the parameter information in the message processing flow. The parameters include: message type, message queue length, message priority, message flow control ratio, message backlog ratio, maximum message lifespan and message consumption timeout.
[0052] The message type is used to distinguish different types of messages. For a certain type of message, when the message consumer function is blocked, the message middleware will no longer forward messages of this type to the message consumer until the message consumer actively confirms that the blocking problem of this type of message has been resolved.
[0053] Message queue length is used to identify the maximum number of messages of a certain type that can be stored in the system.
[0054] Message priority is used to control the order in which tokens are obtained from the token bucket during the message flow control phase. Message producers automatically generate message priority information when generating messages.
[0055] The message flow control ratio represents the percentage of received messages in the message queue to the total number of queues when message reception flow control is applied. When the percentage of received messages to the total number of queues exceeds the flow control ratio, the reception of this type of message will be restricted.
[0056] The message backlog ratio is the percentage of the maximum number of messages stored in the message queue to the total number of messages in the queue. When the total number of messages of a certain type exceeds the message backlog ratio, it indicates that the queue for that type of message is about to be full.
[0057] Configure the maximum message lifespan. The maximum message lifespan refers to the maximum time a message of a certain type can live in the message queue. Once the maximum message lifespan is exceeded, the message is considered outdated.
[0058] Configure message consumption timeout, which indicates the maximum processing time for this type of message that the consumer is expected to set.
[0059] Step 2: Monitor the production speed and consumption speed of different message types, the resource usage of message consumers, and the response status after messages are consumed.
[0060] Step 2 also periodically receives resource reporting requests from message consumers, records the consumer's CPU utilization and memory utilization, and, combined with the message consumer's past resource utilization data, infers whether the message consumer has the capacity to process messages that need to be consumed. At the same time, it receives normal consumption status submission requests from message consumers. Upon receiving a normal consumption status request from a message consumer, it cancels message flow control according to the message type for which the consumption status is requested, reads the data of this message type stored on disk, and fills the message into the message queue of this type to ensure that the message consumer processes unconsumed messages in a timely manner.
[0061] When the message middleware forwards a message to the consumer, step 2 can also store the message's timestamp information in the consumed message list of the corresponding message type. This information can be used to filter out duplicate messages caused by network latency or the message producer's message retry generation mechanism during subsequent message backlog processing.
[0062] Step 2 also monitors the consumer response time for each message in real time and feeds back the response request to the message middleware. It polls messages that have not received a consumer response and obtains the message consumption timeout for this type of message based on the message type. If the difference between the current time and the time when message consumption begins exceeds the consumption timeout, it indicates that the consumer cannot process the message, disconnects from the message consumer, and stops forwarding messages of this type.
[0063] Step 3: Implement message flow control based on message monitoring data to limit message reception and sending frequencies. For message reception, when the usage percentage of a certain type of message queue does not exceed the message flow control ratio, the message middleware will receive all messages sent by producers of that type of message by default. When the usage percentage of a certain type of message queue exceeds the message flow control ratio, the message reception function will be intervened in the flow control process to limit the message reception speed. For message sending, when monitoring reveals excessive CPU and memory usage of the message consumer's system resources, the message sending function will be intervened in the flow control process. By limiting the message sending frequency, the stability of the message consumer's system resource usage will be ensured, preventing issues such as system resource exhaustion due to the message consumer processing a large number of messages.
[0064] Specifically, message flow control is implemented using a token bucket model:
[0065] Create two token buckets for each message type: a message sending token bucket and a message receiving token bucket, and preset the maximum capacity for each.
[0066] For message reception, when the percentage of a certain type of message queue used exceeds the message flow control ratio, the reception rate of this type of message is limited: tokens are added to the message reception token bucket at a fixed rate until the number of tokens in the message reception token bucket reaches the maximum capacity, and then the addition of tokens stops; messages are prioritized and it is determined whether there are still tokens for high-priority messages in the message reception token bucket. If so, the high-priority messages are transferred to the message queue; otherwise, the message sending request is rejected.
[0067] For message sending, when the message consumer resource utilization rate continues to increase, the message sending frequency is limited: tokens are added to the message sending token bucket at a fixed rate until the number of tokens in the message sending token bucket reaches the maximum capacity, at which point the addition of tokens stops; messages are prioritized, and it is determined whether there are still tokens for high-priority messages in the message sending token bucket. If so, the high-priority messages are sent to the message consumer; otherwise, they are not sent. By controlling the number of tokens in the token bucket, the frequency of message consumption is stabilized.
[0068] Step 4: Handling Message Backlog: Refer to the message backlog ratio to obtain the current message queue backlog status. When the message queue is about to fill up, continuously reduce the number of tokens generated per unit time for message receiving token buckets that are already in a backlog state; perform deduplication operations on unforwarded messages; store backlogged messages on disk, and clear the token count in the message receiving token buckets of backlogged messages, no longer receiving messages of this type.
[0069] Step 4, which involves retrieving and deduplicating unforwarded messages, may include: traversing all existing messages in the message queue, determining whether the message's timestamp is in the consumed message timestamp list, and if so, deleting the message from the message queue; simultaneously, checking the message's existing time in the message queue, and if the message's existing time exceeds the maximum message lifespan, determining the message as expired and deleting it from the message queue.
[0070] Example 2
[0071] The present invention also provides an apparatus for solving message backlog, comprising a message configuration module, a message monitoring module, a message flow control module, and a message backlog processing module.
[0072] The message configuration module configures the parameter information in the message processing flow. These parameters include: message type, message queue length, message priority, message flow control ratio, message backlog ratio, maximum message lifespan, and message consumption timeout.
[0073] The message monitoring module monitors the production and consumption rates of different message types, the resource usage of message consumers, and the response status after messages are consumed.
[0074] The message flow control module performs message flow control based on message monitoring, limiting the frequency of message reception and transmission.
[0075] Specifically, message flow control is implemented using a token bucket model:
[0076] Create two token buckets for each message type: a message sending token bucket and a message receiving token bucket, and preset the maximum capacity for each.
[0077] For message reception, when the percentage of a certain type of message queue used exceeds the message flow control ratio, the reception rate of this type of message is limited: tokens are added to the message reception token bucket at a fixed rate until the number of tokens in the message reception token bucket reaches the maximum capacity, and then the addition of tokens stops; messages are prioritized and it is determined whether there are still tokens for high-priority messages in the message reception token bucket. If so, the high-priority messages are transferred to the message queue; otherwise, the message sending request is rejected.
[0078] For message sending, when the message consumer resource utilization rate continues to increase, the message sending frequency is limited: tokens are added to the message sending token bucket at a fixed rate until the number of tokens in the message sending token bucket reaches the maximum capacity, and then the addition of tokens stops; messages are prioritized and it is determined whether there are still tokens for high-priority messages in the message sending token bucket. If so, the high-priority messages are sent to the message consumer; otherwise, they are not sent.
[0079] The message backlog processing module handles message backlog: it obtains the current message queue backlog status based on the message backlog ratio, and when the message queue is about to fill up, it continuously reduces the number of tokens generated per unit time for messages that are already in a backlog state; it performs a deduplication operation on unforwarded messages; it stores backlogged messages on disk, and clears the token count in the message receiving token bucket of backlogged messages, no longer receiving messages of this type.
[0080] The information interaction and execution process between the modules of the above-mentioned device are based on the same concept as the method embodiment of the present invention, and the specific details can be found in the description of the method embodiment of the present invention, and will not be repeated here.
[0081] Similarly, the advantages of the device of the present invention are:
[0082] Using the token bucket pattern to control the message receiving mechanism can stabilize the message receiving frequency and prevent system crashes caused by a sudden increase in message load. When the message consumer server is under excessive load, the token bucket pattern limits the number of messages forwarded to the message consumer, reducing the load on the consumer server and ensuring its normal operation.
[0083] It can obtain performance information of all message consumers in real time, making it easier for administrators to understand the message processing capabilities of message consumers;
[0084] For messages that are piling up, the message queue is switched to disk storage to reduce the pressure on the message middleware. After the message consumer repairs its consumption logic, the messages on disk are then switched back to the message queue to ensure that no messages are lost.
[0085] It should be noted that not all steps and modules in the above processes and device structures are mandatory; some steps or modules can be omitted as needed. The execution order of each step is not fixed and can be adjusted as required. The system structure described in the above embodiments can be a physical structure or a logical structure. That is, some modules may be implemented by the same physical entity, or some modules may be implemented by multiple physical entities, or they may be jointly implemented by certain components in multiple independent devices.
[0086] The above-described embodiments are merely preferred embodiments provided to fully illustrate the present invention, and the scope of protection of the present invention is not limited thereto. Equivalent substitutions or modifications made by those skilled in the art based on the present invention are all within the scope of protection of the present invention. The scope of protection of the present invention is defined by the claims.
Claims
1. A method for resolving message backlog, characterized by: include: Step 1: Configure the parameter information in the message processing flow. The parameters include: message type, message queue length, message priority, message flow control ratio, message backlog ratio, maximum message lifespan and message consumption timeout. Step 2: Monitor the production speed and consumption speed of different types of messages, the resource usage of message consumers, and the response status after messages are consumed; Step 3: Implement message flow control based on message monitoring data to limit the frequency of message reception and transmission; Specifically, message flow control is implemented using a token bucket model: Create two token buckets for each message type: a message sending token bucket and a message receiving token bucket, and preset the maximum capacity for each. For message reception, when the percentage of a certain type of message queue used exceeds the message flow control ratio, the reception rate of this type of message is limited: tokens are added to the message reception token bucket at a fixed rate until the number of tokens in the message reception token bucket reaches the maximum capacity, and then the addition of tokens stops; messages are prioritized and it is determined whether there are still tokens for high-priority messages in the message reception token bucket. If so, the high-priority messages are transferred to the message queue; otherwise, the message sending request is rejected. For message sending, when the message consumer resource utilization rate continues to increase, the message sending frequency is limited: tokens are added to the message sending token bucket at a fixed rate until the number of tokens in the message sending token bucket reaches the maximum capacity, and then the addition of tokens stops; messages are prioritized and it is determined whether there are still tokens for high-priority messages in the message sending token bucket. If so, the high-priority messages are sent to the message consumer; otherwise, they are not sent. Step 4: Handling Message Backlog: Refer to the message backlog ratio to obtain the current message queue backlog status. When the message queue is about to fill up, continuously reduce the number of tokens generated per unit time for message receiving token buckets that are already in a backlog state; perform deduplication operations on unforwarded messages; store backlogged messages on disk, and clear the token count in the message receiving token buckets of backlogged messages, no longer receiving messages of this type.
2. The method for resolving message backlog according to claim 1, characterized in that: In step 1, the message type is configured to distinguish between different types of messages; Configure message queue length to identify the maximum number of messages of a certain type that can be stored in the system; Configure message priority to control the order in which tokens are obtained from the token bucket during the message flow control phase; Configure message flow control ratio, which represents the percentage of the number of messages received in the message queue to the total number of queues when message reception flow control is applied; Configure message backlog ratio. Message backlog ratio refers to the percentage of the maximum number of messages stored in the message queue to the total number of messages in the message queue. When the total number of messages of a certain type exceeds the message backlog ratio, it indicates that the queue for this type of message is about to be filled. Configure the maximum message lifespan. The maximum message lifespan refers to the maximum time a message of a certain type can live in the message queue. Once the maximum message lifespan is exceeded, the message is considered outdated. Configure message consumption timeout, which indicates the maximum processing time for this type of message that the consumer is expected to set.
3. The method for resolving message backlog according to claim 1, characterized in that: Step 2 also periodically receives resource reporting requests from message consumers, records the consumer's CPU utilization and memory utilization, and, combined with the message consumer's past resource utilization data, infers whether the message consumer has the capacity to process messages that need to be consumed. At the same time, it receives normal consumption status submission requests from message consumers. Upon receiving a normal consumption status request from a message consumer, it cancels message flow control according to the message type for which the consumption status is requested, reads the data of this message type stored on disk, and fills the message into the message queue of this type to ensure that the message consumer processes unconsumed messages in a timely manner.
4. The method for resolving message backlog according to claim 1, characterized in that: In step 2, the consumer response time for each message is monitored in real time, and the response request is fed back to the message middleware. Messages that have not received a consumer response are polled, and the message consumption timeout time for this type of message is obtained according to the message type. If the difference between the current time and the time when message consumption begins exceeds the consumption timeout time, it indicates that the consumer cannot process the message, the connection with the message consumer will be disconnected, and message forwarding for this type of message will be stopped.
5. A method for resolving message backlog according to claim 1, characterized in that: Step 4 involves retrieving and deduplicating unforwarded messages, including: traversing all existing messages in the message queue, determining whether the message's timestamp is in the consumed message timestamp list, if so, indicating that the message has been consumed, and deleting the message from the message queue; simultaneously checking the message's existing time in the message queue, if the message's existing time exceeds the message's maximum lifespan, determining that the message is an expired message, and deleting the message from the message queue.
6. An apparatus for resolving message backlog, characterized in that: It includes a message configuration module, a message monitoring module, a message flow control module, and a message backlog processing module. The message configuration module configures the parameter information in the message processing flow. The parameters include: message type, message queue length, message priority, message flow control ratio, message backlog ratio, maximum message lifespan and message consumption timeout. The message monitoring module monitors the production speed and consumption speed of different types of messages, the resource usage of message consumers, and the response status after messages are consumed. The message flow control module performs message flow control based on message monitoring, limiting the frequency of message reception and transmission; Specifically, message flow control is implemented using a token bucket model: Create two token buckets for each message type: a message sending token bucket and a message receiving token bucket, and preset the maximum capacity for each. For message reception, when the percentage of a certain type of message queue used exceeds the message flow control ratio, the reception rate of this type of message is limited: tokens are added to the message reception token bucket at a fixed rate until the number of tokens in the message reception token bucket reaches the maximum capacity, and then the addition of tokens stops; messages are prioritized and it is determined whether there are still tokens for high-priority messages in the message reception token bucket. If so, the high-priority messages are transferred to the message queue; otherwise, the message sending request is rejected. For message sending, when the message consumer resource utilization rate continues to increase, the message sending frequency is limited: tokens are added to the message sending token bucket at a fixed rate until the number of tokens in the message sending token bucket reaches the maximum capacity, and then the addition of tokens stops; messages are prioritized and it is determined whether there are still tokens for high-priority messages in the message sending token bucket. If so, the high-priority messages are sent to the message consumer; otherwise, they are not sent. The message backlog processing module handles message backlog: it obtains the current message queue backlog status based on the message backlog ratio, and when the message queue is about to fill up, it continuously reduces the number of tokens generated per unit time for messages that are already in a backlog state; it performs a deduplication operation on unforwarded messages; it stores backlogged messages on disk, and clears the token count in the message receiving token bucket of backlogged messages, no longer receiving messages of this type.
7. The apparatus for resolving message backlog according to claim 6, characterized in that: The message configuration module configures message types to distinguish between different message types; Configure message queue length to identify the maximum number of messages of a certain type that can be stored in the system; Configure message priority to control the order in which tokens are obtained from the token bucket during the message flow control phase; Configure message flow control ratio, which represents the percentage of the number of messages received in the message queue to the total number of queues when message reception flow control is applied; Configure message backlog ratio. Message backlog ratio refers to the percentage of the maximum number of messages stored in the message queue to the total number of messages in the message queue. When the total number of messages of a certain type exceeds the message backlog ratio, it indicates that the queue for this type of message is about to be filled. Configure the maximum message lifespan. The maximum message lifespan refers to the maximum time a message of a certain type can live in the message queue. Once the maximum message lifespan is exceeded, the message is considered outdated. Configure message consumption timeout, which indicates the maximum processing time for this type of message that the consumer is expected to set.
8. The apparatus for resolving message backlog according to claim 6, characterized in that the message... The monitoring module also periodically receives resource reporting requests from message consumers, records the consumer's CPU and memory usage, and, combined with the message consumer's past resource usage data, infers whether the message consumer is capable of processing messages that need to be consumed. At the same time, it receives normal consumption status submission requests from message consumers. Upon receiving a normal consumption status request from a message consumer, it cancels message flow control according to the message type for which the consumption status is requested, reads the data of this message type stored on disk, and fills the message into the message queue of this type, ensuring that the message consumer processes unconsumed messages in a timely manner.
9. The apparatus for resolving message backlog according to claim 6, characterized in that: The message monitoring module monitors the consumer response time of each message in real time and feeds back the response request to the message middleware. It polls for messages that have not received a consumer response and obtains the message consumption timeout time for this type of message based on the message type. If the difference between the current time and the time when message consumption begins exceeds the consumption timeout time, it indicates that the consumer cannot process the message, and the connection with the message consumer will be disconnected, and message forwarding for this type of message will be stopped.
10. An apparatus for resolving message backlog according to claim 6, characterized in that the message... The backlog processing module performs a deduplication operation on unforwarded messages, including: traversing all existing messages in the message queue, determining whether the message's timestamp is in the consumed message timestamp list, if so, it means the message has been consumed, and deleting the message from the message queue; at the same time, it checks the message's existence time in the message queue, if the message's existence time exceeds the message's maximum lifespan, then it determines the message as an expired message and deletes it from the message queue.