Message routing control method and device and electronic equipment
By establishing an event-driven dynamic service routing table in a distributed cluster, and combining downstream service status and message attributes, adaptive message routing control is achieved, solving the problems of message backlog and system failure in existing technologies, and improving system availability and resource utilization efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-29
- Publication Date
- 2026-03-27
AI Technical Summary
In a distributed cluster environment, when downstream service components suspend services, upstream service components continue to send messages, leading to message backlog, processing timeouts, and cascading system failures. Existing message queue systems lack business awareness and cannot make adaptive routing decisions, resulting in slow response and low resource utilization efficiency.
By establishing an event-driven dynamic service routing table, integrating downstream service status and message business attributes, and generating routing decision factors, adaptive and differentiated control of message paths is achieved. Immediate and delayed sending strategies are adopted to ensure the accuracy of message distribution and the efficiency of system response.
It improves the overall availability and service quality of distributed systems, avoids message backlog and system failures, and enhances resource utilization efficiency and business processing reliability.
Smart Images

Figure CN121750558A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of message transmission technology, and in particular to a message routing control method, apparatus and electronic device. Background Technology
[0002] Currently, in distributed cluster environments composed of multiple heterogeneous subsystems, application components within these subsystems frequently engage in cross-system communication. However, downstream service components often need to temporarily suspend services due to system upgrades, routine maintenance, fault recovery, or resource scheduling. If upstream service components continue to send messages during this time, the corresponding upstream service components will become stuck due to synchronous call blocking, leading to a large backlog of messages, processing timeouts, or even cascading system failures. This directly impacts the data consistency, service reliability, and overall availability of the distributed cluster.
[0003] In existing technologies, message queues are typically added between subsystems as buffers, often using message queue systems such as RabbitMQ and Kafka. These systems achieve communication and data exchange between application components through asynchronous message transmission mechanisms. In actual operation, these traditional message queue systems rely primarily on pre-configured static rules within the message queues to asynchronously forward messages from upstream service components. However, such systems lack the ability to perceive message business types and cannot make adaptive routing decisions, resulting in sluggish overall response, low resource utilization efficiency, and difficulty in guaranteeing the quality of service for pending messages. Summary of the Invention
[0004] This application provides a message routing control method, apparatus, device, and storage medium. By establishing an event-driven dynamic service routing table and integrating downstream service status and message business attributes for intelligent decision-making, it achieves adaptive and differentiated precise control of message paths, thereby improving system availability and service quality. It effectively solves the routing rigidity problem caused by the reliance on static rules and lack of business awareness in traditional message queue systems.
[0005] In a first aspect, embodiments of this application propose a message routing control method, applied to an upstream service component in a distributed system, comprising: In response to a processing instruction for a business event, a message to be sent corresponding to the business event is generated, the message to be sent carrying the identifiers of one or more downstream service components for processing the business event; The identifiers of each downstream service component are matched with the dynamic service routing table. The dynamic service routing table is dynamically generated based on the event type corresponding to the processable business event of the upstream service component and the running status of each downstream service component. It includes the identifier of at least one target downstream service component, and the event type is used to determine the target downstream service component associated with the event type. If the dynamic service routing table includes the identifier of the destination downstream service component, then obtain the running status indicators of each access endpoint in the destination downstream service component; Based on the running status indicators of each access endpoint and the attribute information of the service events corresponding to the messages to be sent, a routing decision factor is generated. The routing decision factor is matched with at least one decision rule, and the target message sending strategy is determined from the predefined message sending strategies corresponding to the decision rule based on the matching result. Based on the target message sending strategy, the message to be sent is sent to the corresponding downstream service component.
[0006] The above message routing control method dynamically generates routing tables based on event types and running status, generates routing decision factors by combining message attributes, and determines sending strategies based on rule matching. This achieves real-time, adaptive, and business-aware routing decisions, thereby effectively improving the accuracy of message distribution and the overall system response efficiency.
[0007] In some possible embodiments, the dynamic service routing table is generated in the following manner: During the initialization of each upstream service component, based on the list of downstream service components associated with the target event type corresponding to each upstream service component, the target downstream service component corresponding to each upstream service component is determined from the preset downstream service components, wherein the target event type corresponding to the upstream service component is the event type corresponding to the processable business event of the upstream service component; The dynamic service routing table is generated based on the identifier of the target downstream service component corresponding to each upstream service component.
[0008] In some possible embodiments, the operational status indicators include health parameters and current load rate. The generation of routing decision factors based on the operational status indicators of each access endpoint and the attribute information of the service events corresponding to the messages to be sent includes: By parsing the message header fields and metadata tags of the message to be sent, the attribute information of the business event corresponding to the message to be sent is extracted. The attribute information includes at least message priority and business urgency. For any access endpoint of the downstream service component of the destination, the message priority, the business urgency, the health parameters corresponding to the access endpoint and the current load rate are normalized respectively, and the normalized numerical features are weighted and fused with preset weight coefficients to generate the sub-routing decision factor corresponding to the access endpoint. The target sub-route decision factor with the highest value is selected from all sub-route decision factors and used as the route decision factor.
[0009] In some possible embodiments, the step of matching the routing decision factor with at least one decision rule and determining the target message sending strategy from predefined message sending strategies corresponding to the decision rule based on the matching result includes: The routing decision factor is input into the rule engine, which includes a plurality of preset decision rules, wherein the decision rules include a mapping relationship between at least one numerical range of the routing decision factor and the message sending strategy. The rule engine is executed to output the target message sending strategy corresponding to the routing decision factor.
[0010] In some possible embodiments, the target message sending strategy is an instant sending strategy, and the step of sending the message to be sent to the corresponding destination downstream service component based on the message sending strategy includes: For any access endpoint in the downstream service component of the destination, the endpoint performance parameters corresponding to the access endpoint are determined based on the health parameters and current load rate in the running status indicators of the access endpoint and the business urgency of the business event corresponding to the message to be sent. Based on the endpoint performance parameters, a target access endpoint is selected from the access endpoints of the downstream service component. Based on the communication link corresponding to the target access endpoint, the message to be sent is sent to the target access endpoint.
[0011] In some possible embodiments, the target message sending strategy is a delayed sending strategy, and the step of sending the message to be sent to the corresponding destination downstream service component based on the message sending strategy includes: The message to be sent, the identifier of the downstream service component carried in the message to be sent, and the number of scans are recorded as a delayed task in the delayed sending record table, wherein the number of scans represents the number of times the delayed task is scanned; Start an asynchronous timed task to scan each delayed task in the delayed sending record table according to the preset time for the first scan of delayed tasks; For each delayed task, during the scanning process, based on the destination downstream service component identifier carried in the message to be sent in the delayed task, the running status indicators of each access endpoint of the destination downstream service component are obtained. Based on the operating status indicators of each access endpoint, determine whether the preset sending conditions are met; If the sending conditions are met, the message to be sent in the delayed task is sent to the destination downstream service component carried by the message to be sent. If the sending conditions are not met, the number of scans in the delayed task is increased by a step value, and a preset backoff algorithm is used to determine the time when the delayed task will be scanned next based on the number of scans.
[0012] In some possible embodiments, the method further includes the following steps: If a successful processing confirmation for the target message to be sent is received from a downstream service component within a preset time, the delayed task including the target message to be sent is deleted. If no successful processing confirmation or processing failure confirmation is received from the downstream service component within the preset time, the number of scans in the delayed task is increased by a step value, and a preset backoff algorithm is used to determine the time when the delayed task will be scanned next based on the number of scans.
[0013] In some possible embodiments, the operational status indicators include health parameters and current load rate, and the method further includes: If the dynamic service routing table includes the identifier of the destination downstream service component, and there is no available access endpoint in the destination downstream service component, then the identifier of the destination downstream service component is deleted from the dynamic service routing table. If the dynamic service routing table does not include the identifier of the destination downstream service component, and there is an available access endpoint in the destination downstream service component, then the identifier of the destination downstream service component is added to the dynamic service routing table. Wherein, the health parameter corresponding to the available access endpoint is greater than a first preset threshold, and the current load rate is less than a second preset threshold.
[0014] Secondly, embodiments of this application propose a message routing control device, comprising: The message generation module is used to respond to the processing instructions for the business event and generate a message to be sent corresponding to the business event. The message to be sent carries the identifiers of one or more downstream service components for processing the business event. The matching module is used to match the identifiers of each downstream service component with the dynamic service routing table. The dynamic service routing table is dynamically generated based on the event type corresponding to the processable business event of the upstream service component and the running status of each downstream service component. It includes the identifier of at least one target downstream service component, and the event type is used to index the downstream service component associated with the event type. The detection module is used to obtain the running status indicators of each access endpoint in the downstream service component if the dynamic service routing table includes the identifier of the downstream service component. The decision factor generation module is used to generate routing decision factors based on the running status indicators of each access endpoint and the attribute information of the service event corresponding to the message to be sent. The strategy determination module is used to match the routing decision factor with at least one decision rule, and determine the target message sending strategy from the predefined message sending strategies corresponding to the decision rule based on the matching result; The message sending module is used to send the message to be sent to the corresponding downstream service component based on the target message sending strategy.
[0015] The aforementioned message routing control device dynamically generates a routing table based on event type and running status, generates routing decision factors by combining message attributes, and determines the sending strategy based on rule matching. This achieves real-time, adaptive, and business-aware routing decisions, thereby effectively improving the accuracy of message distribution and the overall system response efficiency.
[0016] Thirdly, embodiments of this application provide an electronic device, including: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform steps in a message routing control method as described in any of the first aspects of the above embodiments.
[0017] Fourthly, embodiments of this application provide a computer-readable storage medium storing computer-executable instructions for performing steps in a message routing control method as described in any of the first aspects of the above embodiments.
[0018] Fifthly, embodiments of this application provide a computer program product comprising: computer program code, which, when executed on a computer, causes the computer to perform steps in a message routing control method as described in any of the first aspects of the above embodiments.
[0019] This application proposes a message routing control method, apparatus, electronic device, computer-readable storage medium, and computer program product. By establishing an event type-driven dynamic service routing table and integrating the running status indicators of each access endpoint in downstream service components with the attribute information of the business events corresponding to the messages to be sent in real time for intelligent decision-making, it achieves accurate, adaptive, and differentiated routing control of message distribution paths, thereby improving the overall availability of the system and the quality of business services.
[0020] Other features and advantages of this application will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the application. The objectives and other advantages of this application may be realized and obtained by means of the structures particularly pointed out in the written description, claims, and drawings. Attached Figure Description
[0021] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1 This is a flowchart of a message routing control method according to an embodiment of this application; Figure 2 This is a flowchart illustrating a message sending strategy using an instant sending approach in an embodiment of this application. Figure 3 This is a flowchart illustrating a message sending process using a delayed sending strategy in an embodiment of this application. Figure 4 This is a schematic diagram of the structure of a message routing control device according to an embodiment of this application; Figure 5 This is a schematic diagram of the structure of an electronic device according to an embodiment of this application. Detailed Implementation
[0023] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application. Unless otherwise specified, the embodiments and features in the embodiments of this application can be arbitrarily combined with each other. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than that shown here.
[0024] The terms "first" and "second" in the specification, claims, and accompanying drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the term "comprising" and any variations thereof are intended to cover non-exclusive protection. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or devices. The term "multiple" in this application can mean at least two, for example, two, three, or more, and the embodiments of this application do not impose limitations.
[0025] The following explanations of some terms used in the embodiments of the present invention are provided to facilitate understanding by those skilled in the art.
[0026] (1) Business events refer to discrete facts or state changes with clear business meanings generated by user operations, internal system state changes or external triggers in a distributed system, such as "user payment successful", "order status update" or "inventory deduction request". (2) Upstream service components refer to the service modules that initiate or generate messages to be sent in the message passing chain. They are usually the starting point or intermediate processing node of the business process, responsible for constructing messages according to business logic and sending them to other service components responsible for the next stage of processing. (3) Downstream service components refer to service modules that receive and process messages sent by upstream service components in the message passing chain, and undertake specific business logic execution responsibilities, such as data persistence, calculation and analysis or notification push. One of the messages of an upstream service component may correspond to one or more downstream service components, forming a one-to-many fan-out relationship to achieve business decoupling and parallel processing. (4) Health parameters refer to technical indicators used to quantitatively evaluate the current operating status of each access endpoint in the downstream service components. They are usually obtained through active detection or passive monitoring and are used to comprehensively judge the service reachability and core function availability of the access endpoint. (5) Sub-routing decision factor refers to a quantitative decision reference value (or a set of values) generated by a predefined algorithm or model based on the real-time collected operating status indicators of each access endpoint during the message routing control process. It comprehensively reflects the expected efficiency, success probability and business suitability of sending the current message to be sent through the access endpoint at a specific time.
[0027] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of this application, including various details to aid understanding. These embodiments should be considered merely exemplary. Therefore, those skilled in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope of this application. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description. It should be noted that in the embodiments of this application, certain existing industry solutions such as software, components, and models may be mentioned. These should be considered exemplary, intended only to illustrate the feasibility of implementing the technical solutions of this application, and do not imply that the applicant has already used or necessarily used such solutions.
[0028] The acquisition, transmission, storage, and use of data in this application all comply with the requirements of relevant national laws and regulations.
[0029] Before introducing the message routing control method, apparatus, electronic device, computer-readable storage medium, and computer program product provided in the embodiments of this application, the technical background of the embodiments of this application will be described in detail below for ease of understanding.
[0030] Currently, in distributed cluster environments composed of multiple heterogeneous subsystems, application components within these subsystems often communicate and exchange data across systems via message passing. However, downstream service components frequently need to temporarily suspend services for various reasons (such as system upgrades, routine maintenance, fault recovery, and resource scheduling). If upstream service components continue to send messages during this time, the corresponding upstream service components will become stuck due to synchronous call blocking, leading to a large backlog of messages, processing timeouts, or even cascading system failures. This directly impacts the data consistency, service reliability, and overall availability of the distributed cluster.
[0031] In existing technologies, message queues are typically added between subsystems as buffers. Message queue systems such as RabbitMQ and Kafka are commonly used to achieve communication and data exchange between application components through asynchronous message transmission mechanisms.
[0032] In actual operation, the aforementioned traditional message queue system mainly relies on pre-configured static rules in the message queue to asynchronously forward messages received from upstream service components to the corresponding downstream service components, but it still has the following main drawbacks: The aforementioned message queue system lacks the ability to perceive message service types, cannot make adaptive routing decisions, and often adopts a simple first-in-first-out strategy in message processing, lacking the ability to differentiate and process different types of messages, resulting in sluggish overall response, low resource utilization efficiency, and difficulty in guaranteeing the service quality of messages to be sent. The aforementioned message queue system also lacks the ability to dynamically adjust message sending strategies based on the status of downstream service components. When downstream service components need to be shut down for maintenance or experience failures, upstream service components will continue to send messages, causing messages to accumulate when downstream components are unavailable, which may lead to system crashes or data loss.
[0033] In view of the technical problem that traditional message queue systems lack the ability to perceive message service types and cannot make adaptive routing decisions, this application proposes a message routing control method. By establishing an event-driven dynamic service routing table and integrating downstream service status and message service attributes for intelligent decision-making, the method achieves adaptive and differentiated precise control of message paths, thereby improving system availability and service quality.
[0034] One message routing control method in this application embodiment is applied to an upstream service component in a distributed system, such as... Figure 1 As shown, it includes: Step S101: In response to the processing instruction for the business event, generate a message to be sent corresponding to the business event. The message to be sent carries the identifiers of one or more downstream service components used to process the business event. Step S102: Match the identifiers of each downstream service component with the dynamic service routing table. Step S103: If the dynamic service routing table includes the identifier of the destination downstream service component, then obtain the running status indicators of each access endpoint in the destination downstream service component. Step S104: Generate routing decision factors based on the running status indicators of each access endpoint and the attribute information of the business events corresponding to the messages to be sent; Step S105: Match the routing decision factor with at least one decision rule, and determine the target message sending strategy from the predefined message sending strategies corresponding to the decision rules based on the matching results; Step S106: Based on the target message sending strategy, send the message to be sent to the corresponding downstream service component.
[0035] In this embodiment, the dynamic service routing table is dynamically generated based on the event type corresponding to the processable business events of the upstream service component and the running status of each downstream service component. It includes the identifier of at least one target downstream service component, and the event type is used to determine the target downstream service component associated with the event type.
[0036] Specifically, the dynamic service routing table is used to represent a list of identifiers of downstream service components that are allowed to receive messages from the upstream service component, and is generated in the following manner: During the initialization of each upstream service component, based on the list of downstream service components associated with the target event type corresponding to each upstream service component, the target downstream service component corresponding to each upstream service component is determined from the preset downstream service components, wherein the target event type corresponding to the upstream service component is the event type corresponding to the processable business event of the upstream service component; A dynamic service routing table is generated based on the identifiers of the target downstream service components corresponding to each upstream service component.
[0037] The target event type refers to the event type that can handle business events pre-configured for each upstream service component. For example, for a certain upstream service component A, business events 1-3 of event type a and business events 4-5 of event type b are pre-configured. When upstream service component A is initialized, based on the target event types a and b corresponding to upstream service component A, the target downstream service component B corresponding to target event type a and the target downstream service components C and D corresponding to target event type b are determined respectively. Based on the identifiers of B, C, and D determined as target downstream service components, a dynamic service routing table is generated.
[0038] The following table 1 shows one possible form of a dynamic service routing table: Table 1
[0039] By setting up the dynamic service routing table in the above manner, it is possible to control whether upstream service components can route messages to corresponding downstream service components, thereby achieving proactive, precise, and adaptive governance of message flow in distributed systems.
[0040] In the above steps, if the dynamic service routing table does not include the identifier of the destination downstream service component, the message to be sent is actively discarded and a corresponding security audit log is generated.
[0041] In this embodiment, based on the real-time status of the dynamic service routing table, precise control is proactively implemented for messages to be sent to unauthorized or abnormal downstream components, and security audit logs are generated. This effectively prevents invalid message delivery to unauthorized or abnormal downstream components, thereby eliminating the consumption of system resources by invalid traffic at the source.
[0042] In step S103 above, if the dynamic service routing table includes the identifier of the destination downstream service component, the running status indicators of each access endpoint in the destination downstream service component are obtained. Optionally, in a distributed system including the above-mentioned upstream service component and downstream service component, a registration center is also included to detect the running status of each service component according to a preset time period. The operational status metrics include health parameters and current load rate. Upstream service components obtain the operational status metrics of each access endpoint in the downstream service components through this registry center, using the following methods: Send a request message to the registry center to request the running status indicators of each access endpoint in the destination downstream service component; Receive the response message from the registry center in response to the request message, which carries the running status indicators of each access endpoint in the downstream service component.
[0043] In this application embodiment, only one possible implementation method for obtaining the running status indicators of each access endpoint in the downstream service component is given. Other existing detection methods can also be used to obtain the running status indicators according to actual needs, and no specific limitation is made here.
[0044] In some possible embodiments, in step S104 above, the routing decision factor characterizes the expected efficiency, success probability, and service suitability of sending the currently pending message through the access endpoint at a specific time. Specifically, generating the routing decision factor based on the operating status indicators of each access endpoint and the attribute information of the service event corresponding to the pending message includes the following steps: By parsing the message header fields and metadata tags of the message to be sent, the attribute information of the business event corresponding to the message to be sent can be extracted. The attribute information includes at least message priority (including low, medium and high levels) and business urgency (including low, medium and high levels). For any access endpoint of the downstream service component, the message priority, business urgency, health parameters corresponding to any access endpoint, and current load rate are normalized respectively. The normalized numerical features are then weighted and fused with preset weight coefficients to generate the sub-route decision factor corresponding to any access endpoint. The various sub-routing decision factors are weighted and merged to generate a single routing decision factor.
[0045] For business events involving asset transfers, it is typically necessary to set higher message priorities and business urgency. Taking a payment success event as an example, the payment message generated in response to the instruction processing this event carries a destination downstream service component, which includes two access endpoints. A specific process for generating routing decision factors is given below, including: The message will be parsed and its priority and business urgency will be set to "high". The health parameters for the first access endpoint are 0.95 and the current load rate is 0.65. The health parameters for the second access endpoint are 0.85 and the current load rate is 0.7. For the first access endpoint, after normalizing the message priority, service urgency, health parameters and current load rate, the corresponding sub-route decision factor is calculated to be 0.825 according to the preset weight coefficients (message priority weight 0.3, service urgency weight 0.4, health parameter weight 0.2, current load rate 0.1). For the second access endpoint, the same processing method is performed, and the corresponding sub-route decision factor is calculated to be 0.8; The target sub-routing decision factor with the highest value, 0.825, is selected as the routing decision factor.
[0046] In this embodiment, message priority and business urgency are determined by the upstream service component based on business events when generating messages to be sent. Existing methods for determining message priority and business urgency can be used, and will not be elaborated here.
[0047] After generating the routing decision factor corresponding to the message to be sent, the upstream service component matches the routing decision factor with at least one decision rule. Based on the matching result, it determines the target message sending strategy from the predefined message sending strategies corresponding to the decision rules, thereby transforming the multidimensional real-time status and business attributes into specific, executable routing control instructions.
[0048] In some possible embodiments, the message sending strategy includes an immediate sending strategy and a delayed sending strategy, with the corresponding decision rules set as follows: when the routing decision factor is greater than a first preset value (e.g., 0.8), the immediate sending strategy is adopted; when the routing decision factor is less than the first preset value, the delayed sending strategy is adopted.
[0049] Optionally, determining the target message sending strategy from predefined message sending strategies corresponding to the decision rules based on the matching results includes: The routing decision factors are input into the rule engine, which includes multiple preset decision rules. Each decision rule includes a mapping relationship between at least one numerical range of the routing decision factors and the message sending strategy. The execution rule engine outputs the target message sending strategy corresponding to the routing decision factor.
[0050] Taking the above business event as a payment success event, and calculating the routing decision factor of the corresponding message to be sent as 0.825 as an example, the routing decision factor of 0.825 is input into the rule engine and executed. The rule engine outputs the target message sending strategy corresponding to the routing decision factor. When the routing decision factor of 0.825 is greater than the first preset value of 0.8, the target message sending strategy is determined to be an instant sending strategy.
[0051] By matching preset rules to determine the target message sending strategy, a seamless transition from state awareness to strategy execution is achieved. This not only ensures the timeliness of core business processing, but also enhances the reliability and controllability of distributed system services through deterministic execution of the strategy.
[0052] In this embodiment of the application, if the target message sending strategy is an immediate sending strategy, the message to be sent is sent to the corresponding destination downstream service component based on the message sending strategy, including: For any access endpoint in the downstream service component, determine the endpoint performance parameters corresponding to any access endpoint based on the health parameters and current load rate in the running status indicators of any access endpoint, as well as the business urgency of the business event corresponding to the message to be sent. Based on endpoint performance parameters, select the target access endpoint from the access endpoints of the downstream service components. Based on the communication link corresponding to the target access endpoint, the message to be sent is sent to the target access endpoint.
[0053] The endpoint performance parameters are calculated using the following formula 1: (Formula 1) The above-mentioned selection of the target access endpoint from the access endpoints of the downstream service component can also be achieved without using the aforementioned endpoint performance parameter comparison method, instead employing a preset load balancing algorithm, such as round-robin, weighted least connections, or consistent hashing. In this embodiment, only one possible implementation is given, and no specific limitation is made.
[0054] The following describes the complete sending process for a message to be sent, where the target message sending strategy is instantaneous. Figure 2 As shown, it includes: Step S201: Based on the matching results, determine the target message sending strategy as an instant sending strategy; Step S202: For any access endpoint in the downstream service component, determine the endpoint performance parameters corresponding to any access endpoint based on the health parameters and current load rate in the running status indicators of any access endpoint, and the business urgency of the business event corresponding to the message to be sent. Step S203: Select the access endpoint with the highest endpoint performance parameters as the target access endpoint; Step S204: Based on the communication link corresponding to the target access endpoint, send the message to be sent to the target access endpoint.
[0055] In this embodiment of the application, the above-mentioned immediate sending strategy and delayed sending strategy together constitute an adaptive message sending strategy. When it is determined that it is not appropriate to send immediately, the delayed sending strategy will be automatically activated. Through time scheduling and state waiting mechanism, the message will be reliably delivered in the end while avoiding the current risk.
[0056] Specifically, if the target message sending strategy is a delayed sending strategy, the above-mentioned sending of the message to be sent to the corresponding downstream service component based on the message sending strategy includes the following steps: S1 records the message to be sent, the identifier of the downstream service component to be sent, and the number of scans as a delayed task in the delayed sending record table.
[0057] The scan count represents the number of times the delayed task is scanned. The default value of this count is 0, and it is accumulated according to the scan frequency in subsequent processing.
[0058] S2, start the asynchronous timed task, and scan each delayed task in the delayed sending record table according to the preset time of the first scan of the delayed task.
[0059] For each delayed task, when it is recorded in the delayed sending record table, the corresponding asynchronous timed task is started synchronously to perform a timed scan of the delay according to the default scan time for the first delayed task.
[0060] S3, for each delayed task, during the scanning process, obtains the running status indicators of each access endpoint of the target downstream service component based on the identifier of the target downstream service component carried in the message to be sent in the delayed task.
[0061] S4, based on the running status indicators of each access endpoint, determine whether the preset sending conditions are met; S5a, if the sending conditions are met, the message to be sent in the delayed task is sent to the downstream service component of the destination carried in the message to be sent; S5b: If the sending conditions are not met, the number of scans in the delayed task is increased by the step size value, and the time for the next scan of the delayed task is determined by a preset backoff algorithm based on the number of scans.
[0062] In step S3 above, the running status indicators of each access endpoint of the downstream service component are obtained by sending a request message to the registration center as described above, which will not be repeated here.
[0063] In this embodiment of the application, the operating status indicators include health parameters and current load rate. In step S4 above, based on the operating status indicators of each access endpoint, it is determined whether the preset sending conditions are met, including: Based on the operational status indicators of each access endpoint, if it is determined that there is an available access endpoint in the downstream service component of the destination, the preset sending conditions are met. Based on the operational status indicators of each access endpoint, if it is determined that there is no available access endpoint in the downstream service component of the destination, it is determined that the preset sending conditions are not met. Among them, the health parameters corresponding to the above-mentioned available access endpoints are greater than the first preset threshold, and the current load rate is less than the second preset threshold.
[0064] Based on the above method, when the preset sending conditions are met, the message to be sent in the delayed task is sent to the downstream service component of the destination carried by the message to the determined available access endpoint and the communication link corresponding to the available access endpoint.
[0065] In some possible embodiments, if multiple available access endpoints are determined, the endpoint performance parameter comparison method described above or a preset load balancing algorithm is used to select from the multiple available access endpoints to determine the target available access endpoint. Based on the communication link corresponding to the target available access endpoint, the message to be sent in the delayed task is sent to the destination downstream service component carried by the message to be sent. This will not be elaborated further here.
[0066] Once the sending conditions are met and the message to be sent in the delayed task is sent to the downstream service component carried by the message, the lifecycle of the delayed task does not end immediately, but enters a critical confirmation and closed-loop management phase.
[0067] Specifically, by monitoring the processing confirmations returned by downstream service components, the delayed tasks are accurately assessed for status and subsequent handling. The method also includes: If a successful processing confirmation for the target message to be sent is received from the downstream service component within a preset time, the delayed task including the target message to be sent is deleted. If no confirmation of successful processing of the target message to be sent is received from the downstream service component within the preset time, or if a confirmation of processing failure is received, the number of scans in the delayed task will be increased by a step value, and the time for the delayed task to be scanned next will be determined based on the number of scans using a preset backoff algorithm.
[0068] In this embodiment of the application, the backoff algorithm performed when no successful processing confirmation for the target message to be sent is received from the downstream service component within the preset time or when a processing failure confirmation is received is the same as the calculation process when the sending conditions are not met, and will not be repeated here.
[0069] Through the aforementioned closed-loop management phase, the problem of inconsistency between the message sending status of the upstream service component and the message processing status of the downstream service component caused by network partitioning, timeouts, or transient failures of downstream service components in distributed systems is fundamentally solved, thereby ensuring the eventual consistency of message processing status among service components across subsystems.
[0070] In step S5b above, if the sending conditions are not met, the number of scans in the delayed task is increased by a step value, and a preset backoff algorithm is used to determine the time when the delayed task will be scanned next based on the number of scans.
[0071] Optionally, this step size is 1, and the corresponding backoff algorithm is used to calculate the delay of the next scan, as expressed by the following formula 2: (Formula 2) The basic interval can be determined according to actual needs, the backoff coefficient can be adjusted according to different business events or different downstream service components, and the attenuation factor is usually set to 1.
[0072] Using the backoff algorithm described above, a shorter scan delay can be calculated in the early stages of delayed task recording (when the number of scans is small), in order to quickly detect and recover the task. As the duration of the task increases, the calculated scan delay also increases, which can significantly reduce the overhead of ineffective components.
[0073] In some possible embodiments, a maximum number of scans can also be set. If it is determined that the number of scans exceeds the maximum number of scans, the corresponding delayed task is marked as failed and an alarm is triggered, so that maintenance personnel can intervene even if the delayed task is sent indefinitely, thus avoiding the black box state of delayed tasks being sent indefinitely.
[0074] The following describes the complete sending process for a message to be sent, where the target message sending strategy is a delayed sending strategy. Figure 3 As shown, it includes: Step S301: Based on the matching results, determine the target message sending strategy as a delayed sending strategy; Step S302: Record the message to be sent, the identifier of the downstream service component to be sent, and the number of scans as a delayed task in the delayed sending record table; Step S303: Start the asynchronous timed task and scan the delayed task according to the preset time of the first scan delayed task; Step S304: Based on the destination downstream service component identifier carried in the message to be sent in the delayed task, obtain the running status indicators of each access endpoint of the destination downstream service component. Step S305: Based on the running status indicators of each access endpoint, determine that there is an available access endpoint in the downstream service component of the destination, determine that the preset sending conditions are met, and send the message to be sent in the delayed task to the downstream service component of the destination carried in the message to be sent. Step S306: If a successful processing confirmation for the target message to be sent is received from the downstream service component within a preset time, the delayed task including the target message to be sent is deleted.
[0075] In some possible embodiments, in order to achieve high efficiency and accuracy in routing decisions and to ensure strong consistency between routing information and the actual state of downstream service components, the aforementioned dynamic service routing table will also continuously execute the logic of deleting and adding identifiers of target downstream service components according to a preset update cycle or triggered by changes in the running state of downstream service components, so as to dynamically maintain its content.
[0076] Optionally, the above methods also include: If the dynamic service routing table includes the identifier of the destination downstream service component, and there is no available access endpoint in the destination downstream service component, then the identifier of the destination downstream service component is deleted from the dynamic service routing table. If the dynamic service routing table does not include the identifier of the destination downstream service component, and there is an available access endpoint in the destination downstream service component, then the identifier of the destination downstream service component is added to the dynamic service routing table.
[0077] In this embodiment, when there is no available access endpoint in the downstream service component, it is determined that the component has lost its service capability at the current moment, and the component is actively isolated (its identifier is deleted from the dynamic service routing table). This avoids the upstream service component continuously sending messages to be sent to a downstream service component that is unavailable as a whole, which would lead to problems such as request timeout, upstream thread blocking and resource waste.
[0078] In some possible embodiments, the dynamic service routing table can also be updated according to the actual situation, specifically by reconfiguring the processable events of the upstream service components, including deleting target processable events and adding target processable events.
[0079] After an upstream service component determines that its processable events have been reconfigured, it re-determines the current target downstream service component based on the event type of the reconfigured processable events. When it detects that the target downstream service component in the dynamic service routing table no longer belongs to the current target downstream service component, it deletes the corresponding identifier from the dynamic service routing table.
[0080] Correspondingly, when a target downstream service component not currently in the dynamic service routing table is detected, and it is determined that there is an available access endpoint, the corresponding identifier is added to the dynamic service routing table. This includes two scenarios: Scenario 1: For a target downstream service component that has been deleted, if it is determined that there is an available access endpoint, it is determined that the service capability has been restored, and the corresponding identifier is added to the dynamic service routing table so that it can be re-managed. Scenario 2: After an upstream service component determines that its processable events have been reconfigured, it re-determines the current target downstream service component based on the event type of the reconfigured processable events. When it is detected that a target downstream service component does not exist in the dynamic service routing table, and it is determined that there is an available access endpoint, its identifier can also be added to the aforementioned dynamic service routing table.
[0081] In some possible embodiments, the aforementioned dynamic service routing table and delayed transmission record table are both stored in high-performance distributed caches such as Redis, which facilitates configuration and state sharing across multiple upstream service component instances, as well as fast read and write access to data.
[0082] By externalizing the core routing state and task state to a shared cache, the problem of state inconsistency in the traditional single-machine memory storage mode is effectively solved. It supports seamless horizontal scaling of upstream service components and ensures the continuity of routing decisions and the persistence of delayed tasks in single-point failure or rolling restart scenarios, thereby greatly enhancing the overall reliability, scalability and operation and maintenance convenience of the distributed message routing system.
[0083] To ensure that core business processes are not interrupted in the event of extreme downstream failures or system overload, and to maximize the eventual reachability of business data, in some possible embodiments, the message sending strategy may also include a degraded sending strategy. The corresponding decision rule may also include: when the routing decision factor is lower than a second preset value (e.g., 0.6), a degraded sending strategy is adopted.
[0084] The degradation sending strategy includes routing the message to be sent to a preset degradation processing component, or persisting it to a bypass storage system for asynchronous compensation processing.
[0085] Optionally, the degradation processing component is a simplified, resource-isolated, and highly available service component used to receive and process core business data for degradation messages, such as a lightweight log service that only records key business identifiers and statuses, or a reliable message queue used to ensure eventual consistency.
[0086] By employing the aforementioned downgraded transmission strategy, the most critical business data was preserved in extreme scenarios, providing a reliable basis for subsequent asynchronous compensation and system recovery. This approach minimized and made the impact on business operations as well as maintained the overall availability of the system.
[0087] This application proposes a message routing control method. By establishing an event type-driven dynamic service routing table and integrating the running status indicators of each access endpoint in the downstream service components with the attribute information of the business events corresponding to the messages to be sent in real time, the method makes intelligent decisions to achieve accurate, adaptive, and differentiated routing control of message distribution paths, thereby improving the overall availability of the system and the quality of business services.
[0088] Based on the same inventive concept, embodiments of this application propose a message routing control device, such as... Figure 4 As shown, it includes: The message generation module 401 is used to respond to the processing instructions for the business event and generate a message to be sent corresponding to the business event. The message to be sent carries the identifiers of one or more downstream service components for processing the business event. The matching module 402 is used to match the identifiers of each downstream service component with the dynamic service routing table. The dynamic service routing table is dynamically generated based on the event type corresponding to the processable business events of the upstream service component and the running status of each downstream service component. It includes the identifier of at least one target downstream service component, and the event type is used to index the downstream service component associated with the event type. The detection module 403 is used to obtain the running status indicators of each access endpoint in the destination downstream service component if the dynamic service routing table includes the identifier of the destination downstream service component. The decision factor generation module 404 is used to generate routing decision factors based on the running status indicators of each access endpoint and the attribute information of the business events corresponding to the messages to be sent. The strategy determination module 405 is used to match the routing decision factor with at least one decision rule, and determine the target message sending strategy from the predefined message sending strategies corresponding to the decision rules based on the matching results; The message sending module 406 is used to send the message to be sent to the corresponding downstream service component based on the target message sending strategy.
[0089] The aforementioned message routing control device dynamically generates a routing table based on event type and running status, generates routing decision factors by combining message attributes, and determines the sending strategy based on rule matching. This achieves real-time, adaptive, and business-aware routing decisions, thereby effectively improving the accuracy of message distribution and the overall system response efficiency.
[0090] Based on the same inventive concept, embodiments of this application propose an electronic device, including at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform a message routing control method as described in any of the first aspects of the above embodiments.
[0091] The following reference Figure 5 This application describes an electronic device 500 according to one embodiment of the present application. Figure 5 The device 500 shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0092] like Figure 5 As shown, an electronic device 500 is presented in the form of a general-purpose electronic device. The components of an electronic device 500 may include, but are not limited to: at least one processor 501, at least one memory 502, and a bus 503 connecting different system components (including memory 502 and processor 501).
[0093] Bus 503 represents one or more of several bus structures, including a memory bus or memory controller, peripheral bus, processor, or local bus using any of the various bus structures.
[0094] The memory 502 may include a readable medium in the form of volatile memory, such as random access memory (RAM) 5021 and / or cache memory 5022, and may further include read-only memory (ROM) 5023.
[0095] The memory 502 may also include a program / utility 5025 having a set (at least one) of program modules 5024, including but not limited to: an operating system, one or more application programs, other program modules, and program data, each or some combination of these examples may include an implementation of a network environment.
[0096] An electronic device 500 can also communicate with one or more external devices 504 (e.g., keyboard, pointing device, etc.), one or more devices that enable a user to interact with a transaction pre-screening device 500, and / or any device that enables the electronic device 500 to communicate with one or more other electronic devices (e.g., router, modem, etc.). This communication can be performed via an input / output (I / O) interface 505. Furthermore, an electronic device 500 can also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) via a network adapter 506. As shown, the network adapter 506 communicates with other modules used in the electronic device 500 via a bus 503. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with the electronic device 500, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0097] Based on the same inventive concept, embodiments of this application provide a computer-readable storage medium storing a computer program. The computer program includes program instructions, which, when executed by a computer, cause the computer to perform any of the message routing control methods discussed above. Since the principle by which the above-described computer-readable storage medium solves the problem is similar to the access control method for a voucher cabinet, the implementation of the above-described computer-readable storage medium can be found in the implementation of the method; repeated details will not be elaborated further.
[0098] Based on the same inventive concept, this application also provides a computer program product, which includes computer program code. When the computer program code is run on a computer, it causes the computer to execute any of the message routing control methods discussed above. Since the principle by which the above-described computer program product solves the problem is similar to that of the message routing control method, the implementation of the above-described computer program product can be referred to the implementation of the method, and repeated details will not be described again.
[0099] The message routing control method, apparatus, electronic device, computer-readable storage medium, and computer program product in this application embodiment establish an event-driven dynamic service routing table and make intelligent decisions by integrating downstream service status and message business attributes. This achieves adaptive and differentiated precise control of message paths, thereby improving system availability and service quality. It effectively solves the routing rigidity problem caused by the reliance on static rules and lack of business awareness in traditional message queue systems.
[0100] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0101] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0102] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0103] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0104] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.
Claims
1. A message routing control method, characterized in that, Upstream service components used in distributed systems include: In response to a processing instruction for a business event, a message to be sent corresponding to the business event is generated, the message to be sent carrying the identifiers of one or more downstream service components for processing the business event; The identifiers of each downstream service component are matched with the dynamic service routing table. The dynamic service routing table is dynamically generated based on the event type corresponding to the processable business event of the upstream service component and the running status of each downstream service component. It includes the identifier of at least one target downstream service component, and the event type is used to determine the target downstream service component associated with the event type. If the dynamic service routing table includes the identifier of the destination downstream service component, then obtain the running status indicators of each access endpoint in the destination downstream service component; Based on the running status indicators of each access endpoint and the attribute information of the service events corresponding to the messages to be sent, a routing decision factor is generated. The routing decision factor is matched with at least one decision rule, and the target message sending strategy is determined from the predefined message sending strategies corresponding to the decision rule based on the matching result. Based on the target message sending strategy, the message to be sent is sent to the corresponding downstream service component.
2. The method according to claim 1, characterized in that, The dynamic service routing table is generated in the following manner: During the initialization of each upstream service component, based on the list of downstream service components associated with the target event type corresponding to each upstream service component, the target downstream service component corresponding to each upstream service component is determined from the preset downstream service components, wherein the target event type corresponding to the upstream service component is the event type corresponding to the processable business event of the upstream service component; The dynamic service routing table is generated based on the identifier of the target downstream service component corresponding to each upstream service component.
3. The method according to claim 1, characterized in that, The operational status indicators include health parameters and current load rate. The generation of routing decision factors based on the operational status indicators of each access endpoint and the attribute information of the service events corresponding to the messages to be sent includes: By parsing the message header fields and metadata tags of the message to be sent, the attribute information of the business event corresponding to the message to be sent is extracted. The attribute information includes at least message priority and business urgency. For any access endpoint of the downstream service component of the destination, the message priority, the business urgency, the health parameters corresponding to the access endpoint and the current load rate are normalized respectively, and the normalized numerical features are weighted and fused with preset weight coefficients to generate the sub-routing decision factor corresponding to the access endpoint. The target sub-route decision factor with the highest value is selected from all sub-route decision factors and used as the route decision factor.
4. The method according to claim 1, characterized in that, The step of matching the routing decision factor with at least one decision rule, and determining the target message sending strategy from predefined message sending strategies corresponding to the decision rule based on the matching result, includes: The routing decision factor is input into the rule engine, which includes a plurality of preset decision rules, wherein the decision rules include a mapping relationship between at least one numerical range of the routing decision factor and the message sending strategy. The rule engine is executed to output the target message sending strategy corresponding to the routing decision factor.
5. The method according to claim 1, characterized in that, The target message sending strategy is an instant sending strategy. The step of sending the message to be sent to the corresponding downstream service component based on the message sending strategy includes: For any access endpoint in the downstream service component of the destination, the endpoint performance parameters corresponding to the access endpoint are determined based on the health parameters and current load rate in the running status indicators of the access endpoint and the business urgency of the business event corresponding to the message to be sent. Based on the endpoint performance parameters, a target access endpoint is selected from the access endpoints of the downstream service component. Based on the communication link corresponding to the target access endpoint, the message to be sent is sent to the target access endpoint.
6. The method according to claim 1, characterized in that, The target message sending strategy is a delayed sending strategy. The step of sending the message to be sent to the corresponding downstream service component based on the message sending strategy includes: The message to be sent, the identifier of the downstream service component carried in the message to be sent, and the number of scans are recorded as a delayed task in the delayed sending record table, wherein the number of scans represents the number of times the delayed task is scanned; Start an asynchronous timed task to scan each delayed task in the delayed sending record table according to the preset time for the first scan of delayed tasks; For each delayed task, during the scanning process, based on the destination downstream service component identifier carried in the message to be sent in the delayed task, the running status indicators of each access endpoint of the destination downstream service component are obtained. Based on the operating status indicators of each access endpoint, determine whether the preset sending conditions are met; If the sending conditions are met, the message to be sent in the delayed task is sent to the destination downstream service component carried by the message to be sent. If the sending conditions are not met, the number of scans in the delayed task is increased by a step value, and a preset backoff algorithm is used to determine the time when the delayed task will be scanned next based on the number of scans.
7. The method according to claim 6, characterized in that, The method further includes the following steps: If a successful processing confirmation for the target message to be sent is received from a downstream service component within a preset time, the delayed task including the target message to be sent is deleted. If no successful processing confirmation or processing failure confirmation is received from the downstream service component within the preset time, the number of scans in the delayed task is increased by a step value, and a preset backoff algorithm is used to determine the time when the delayed task will be scanned next based on the number of scans.
8. The method according to claim 6, characterized in that, The operational status indicators include health parameters and current load rate, and the method further includes: If the dynamic service routing table includes the identifier of the destination downstream service component, and there is no available access endpoint in the destination downstream service component, then the identifier of the destination downstream service component is deleted from the dynamic service routing table. If the dynamic service routing table does not include the identifier of the destination downstream service component, and there is an available access endpoint in the destination downstream service component, then the identifier of the destination downstream service component is added to the dynamic service routing table. Wherein, the health parameter corresponding to the available access endpoint is greater than a first preset threshold, and the current load rate is less than a second preset threshold.
9. A message routing control device, characterized in that, include: The message generation module is used to respond to the processing instructions for the business event and generate a message to be sent corresponding to the business event. The message to be sent carries the identifiers of one or more downstream service components for processing the business event. The matching module is used to match the identifiers of each downstream service component with the dynamic service routing table. The dynamic service routing table is dynamically generated based on the event type corresponding to the processable business event of the upstream service component and the running status of each downstream service component. It includes the identifier of at least one target downstream service component, and the event type is used to index the downstream service component associated with the event type. The detection module is used to obtain the running status indicators of each access endpoint in the downstream service component if the dynamic service routing table includes the identifier of the downstream service component. The decision factor generation module is used to generate routing decision factors based on the running status indicators of each access endpoint and the attribute information of the service event corresponding to the message to be sent. The strategy determination module is used to match the routing decision factor with at least one decision rule, and determine the target message sending strategy from the predefined message sending strategies corresponding to the decision rule based on the matching result; The message sending module is used to send the message to be sent to the corresponding downstream service component based on the target message sending strategy.
10. An electronic device, characterized in that, include: At least one processor; And a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the steps in a message processing method to be sent as described in any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions for performing steps in a message routing control method as described in any one of claims 1 to 8.
12. A computer program product, characterized in that, The computer program product includes: computer program code, which, when run on a computer, causes the computer to perform the steps in a message routing control method as described in any one of claims 1 to 8.