Interface fusing method, interface fusing device and computer-readable storage medium
By leveraging AOP aspect technology and combining circuit breaking rules with a sliding time window, the high failure rate of interface calls in upstream business systems was solved, enabling intelligent circuit breaking of interfaces and reducing the failure rate of business processing.
Patent Information
- Application Number
- PCT/CN2024/142369
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-10-09
- Filing Date
- 2024-12-25
- Publication Date
- 2026-04-16
AI Technical Summary
In data interaction scenarios between upstream business systems and downstream or third-party business systems, existing technologies suffer from a high failure rate in interface calls, failing to effectively handle interface response anomalies that lead to a high failure rate in business processing.
By using the interface circuit breaking method, AOP aspect technology is used to set pre- and post-notifications before and after the interface call, obtain metadata and circuit breaking configuration parameters, determine the interface call conditions, count the number of calls and errors, and determine whether to execute circuit breaking processing according to the circuit breaking rules, including the combination of sliding time window and circuit breaking configuration parameters, to achieve circuit breaking processing of the target method.
This effectively reduced the failure rate of API calls, avoided frequent calls to APIs that failed to respond, and improved the success rate of business processing.
Smart Images

Figure CN2024142369_16042026_PF_FP_ABST
Abstract
Description
Interface fuse method, interface fuse device and computer-readable storage medium
[0001] Related applications
[0002] This application claims priority to Chinese patent application filed on October 9, 2024, application number 202411401204.6, entitled "Interface Fuse Method, Interface Fuse Device and Computer-Readable Storage Medium", the entire contents of which are incorporated herein by reference. Technical Field
[0003] This application relates to the field of computer technology, and in particular to interface fuse breaking methods, interface fuse breaking devices, and computer-readable storage media. Background Technology
[0004] In data interaction scenarios between upstream and downstream business systems, or between upstream and third-party business systems, the upstream business system often needs to call the business interfaces of the downstream or third-party business systems to complete business processing. However, when the downstream or third-party business interfaces experience response anomalies, such as missing required fields or insufficient balance, the upstream business system often lacks corresponding business logic for handling these failed calls. This leads to the upstream business system continuously calling the faulty interfaces, resulting in a high failure rate for its business processing.
[0005] Therefore, current related technologies still suffer from a high failure rate for API calls. Summary of the Invention
[0006] According to various embodiments of this application, an interface fuse breaking method, an interface fuse breaking device, and a computer-readable storage medium are provided.
[0007] Firstly, this embodiment provides an interface circuit breaker method, including:
[0008] Based on the target before-notification, the metadata and circuit breaker configuration parameters of the target method of the interface are obtained, and the circuit breaker configuration parameters and the current state of the circuit breaker are used to confirm whether the target method meets the calling conditions; if so, the target method is called; wherein, the target before-notification is the before-notification of the AOP aspect pre-configured for the target method.
[0009] Based on the target post-notification, it is determined whether the target method was successfully called; if so, the pre-configured circuit breaker rule is executed according to the meta-information of the target method; if the circuit breaker rule execution result is true, the number of calls and the number of call errors are counted; wherein, the target post-notification is a post-notification of the AOP aspect pre-configured for the target method.
[0010] If the target method call fails, the number of calls and the number of call errors are counted according to the circuit breaker configuration parameters;
[0011] Based on the number of calls and the number of call errors within the preset sliding time window, and in conjunction with the circuit breaker configuration parameters, it is determined whether to perform circuit breaker processing on the target method; if so, circuit breaker processing is performed on the target method.
[0012] In some embodiments, the determination of whether the target method meets the invocation conditions is based on the circuit breaker configuration parameters and the current state of the circuit breaker, including:
[0013] If the circuit breaker configuration parameters are not empty and the current state of the circuit breaker is closed, the target method is confirmed to meet the calling conditions.
[0014] In some embodiments, the determination of whether the target method meets the invocation conditions is based on the circuit breaker configuration parameters and the current state of the circuit breaker, including:
[0015] If the circuit breaker configuration parameter is not empty and the current state of the circuit breaker is open, determine whether the current timestamp is greater than or equal to the next retry timestamp; if so, set the current state of the circuit breaker to half open and confirm that the target method meets the calling conditions; wherein, the next retry timestamp is determined according to the circuit breaker duration specified by the circuit breaker configuration parameter and the timestamp corresponding to the last circuit breaker processing of the target method;
[0016] Otherwise, if the target method is found not to meet the calling conditions, the preset circuit breaker and degradation strategy is executed.
[0017] In some embodiments, the determination of whether the target method meets the invocation conditions is based on the circuit breaker configuration parameters and the current state of the circuit breaker, including:
[0018] If the circuit breaker configuration parameters are not empty and the current state of the circuit breaker is half open, it is confirmed that the target method does not meet the calling conditions, and the preset circuit breaker degradation strategy is executed.
[0019] In some embodiments, the method further includes:
[0020] If the circuit breaker configuration parameters are empty, confirm that the target method meets the calling conditions.
[0021] In some embodiments, when the target method call fails, the number of calls and the number of call errors are counted according to the circuit breaker configuration parameters, including:
[0022] When the target method call fails, obtain the call exception type that caused the target method call to fail;
[0023] Determine whether the call exception type is consistent with the preset exception type specified in the circuit breaker configuration parameters; if so, count the number of method calls and the number of method call errors within the current sliding time window.
[0024] In some embodiments, based on the number of calls and the number of call errors within a preset sliding time window, and in conjunction with the circuit breaker configuration parameters, it is determined whether to perform circuit breaker processing on the target method, including:
[0025] When the circuit breaker condition specified in the circuit breaker configuration parameters is the number of exceptions, the number of calls is greater than or equal to the minimum number of requests specified in the circuit breaker configuration parameters, and the number of call errors is greater than or equal to the number of times specified in the circuit breaker configuration parameters, it is confirmed that circuit breaker processing will be performed on the target method, the current state of the circuit breaker will be set to open, and the next retry timestamp will be set according to the specified circuit breaker duration.
[0026] When the circuit breaker determination condition is an abnormal ratio, the number of calls is greater than or equal to the minimum number of requests, and the call error ratio is greater than or equal to the ratio threshold specified by the circuit breaker configuration parameters, it is confirmed that the target method will be subjected to circuit breaker processing, the current state of the circuit breaker will be set to open, and the next retry timestamp will be set according to the circuit breaker duration; the call error ratio is the ratio of the number of call errors to the number of calls.
[0027] In some embodiments, the duration of the sliding time window is set according to the circuit breaker configuration parameters specifying the circuit breaker statistical duration; the sliding time window includes several sub-time window intervals.
[0028] Secondly, this embodiment provides an interface fuse-breaking device, including: an acquisition module, a judgment module, a counting module, and a fuse-breaking processing module; wherein:
[0029] The acquisition module is used to acquire the metadata and circuit breaker configuration parameters of the target method of the interface based on the target before-notification, and to confirm whether the target method meets the calling conditions according to the circuit breaker configuration parameters and the current state of the circuit breaker; if so, the target method is called; wherein, the target before-notification is the before-notification of the AOP aspect pre-configured for the target method.
[0030] The judgment module is used to determine whether the target method was successfully called based on the target post-notification; if so, it executes the pre-configured circuit breaker rule according to the meta-information of the target method; if the circuit breaker rule execution result is true, it counts the number of calls and the number of call errors; wherein, the target post-notification is a post-notification of the AOP aspect pre-configured for the target method.
[0031] The counting module is used to count the number of calls and the number of call errors according to the circuit breaker configuration parameters if the target method call fails.
[0032] The circuit breaker module is used to determine whether to perform circuit breaker processing on the target method based on the number of calls and the number of call errors within a preset sliding time window, combined with the circuit breaker configuration parameters; if so, the target method is subjected to circuit breaker processing.
[0033] Thirdly, this embodiment provides a storage medium storing a computer program that, when executed by a processor, implements the interface circuit breaking method described in the first aspect above.
[0034] Details of one or more embodiments of this application are set forth in the following drawings and description to make other features, objects and advantages of this application more readily apparent. Attached Figure Description
[0035] To more clearly illustrate the technical solutions in the embodiments of this application, 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 this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0036] Figure 1 is a hardware structure block diagram of the terminal of the interface circuit breaker method in this embodiment;
[0037] Figure 2 is a flowchart of the interface circuit breaker method in this embodiment;
[0038] Figure 3 is a flowchart of a method for configuring circuit breaker configuration parameters in some embodiments;
[0039] Figure 4 is a flowchart of an interface circuit breaker method in some embodiments;
[0040] Figure 5 is a structural block diagram of the interface fuse device in this embodiment. Detailed Implementation
[0041] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. 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.
[0042] Unless otherwise defined, the technical or scientific terms used in this application shall have the general meaning as understood by one of ordinary skill in the art to which this application pertains. Words such as “a,” “an,” “an,” “the,” “the,” and “these,” used in this application, do not indicate quantitative limitation and may be singular or plural. The terms “comprising,” “including,” “having,” and any variations thereof used in this application are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or device that comprises a series of steps or modules (units) is not limited to the listed steps or modules (units) but may include steps or modules (units) not listed, or may include other steps or modules (units) inherent to such processes, methods, products, or devices. The terms “connected,” “linked,” and “coupled,” used in this application, are not limited to physical or mechanical connections but may include electrical connections, whether direct or indirect. The term “multiple” used in this application refers to two or more. The "and / or" operator describes the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: A alone, A and B simultaneously, and B alone. Typically, the character " / " indicates that the objects before and after it are in an "or" relationship. The terms "first," "second," and "third," etc., used in this application are merely for distinguishing similar objects and do not represent a specific ordering of the objects.
[0043] The method embodiments provided in this example can be executed in a terminal, computer, or similar computing device. For example, when running on a terminal, Figure 1 is a hardware structure block diagram of the terminal for the interface circuit breaker method of this embodiment. As shown in Figure 1, the terminal may include one or more (only one is shown in Figure 1) processors 102 and a memory 104 for storing data, wherein the processor 102 may be, but is not limited to, a processing device such as a microprocessor (MCU) or a programmable logic device (FPGA). The terminal may also include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that the structure shown in Figure 1 is merely illustrative and does not limit the structure of the terminal. For example, the terminal may include more or fewer components than shown in Figure 1, or have a different configuration than that shown in Figure 1.
[0044] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the interface circuit breaker method in this embodiment. The processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, thereby implementing the aforementioned method. The memory 104 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0045] The transmission device 106 is used to receive or send data via a network. This network includes a wireless network provided by the terminal's communication provider. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 can be a Radio Frequency (RF) module used for wireless communication with the Internet.
[0046] This embodiment provides an interface circuit breaker method. Figure 2 is a flowchart of the interface circuit breaker method of this embodiment. As shown in Figure 2, the process includes the following steps:
[0047] Step S210: Based on the target before advice, obtain the metadata and circuit breaker configuration parameters of the target method of the interface, and confirm whether the target method meets the calling conditions according to the circuit breaker configuration parameters and the current state of the circuit breaker; if so, call the target method; wherein, the target before advice is the before advice of the AOP aspect pre-configured for the target method.
[0048] The target method is the method that requires circuit breaking functionality. This can be marked as a method requiring circuit breaking by adding a pre-defined annotation to the target method of the interface. Furthermore, before and after advice can be set for AOP aspects that have circuit breaking pre-added to the target method, providing entry points for subsequent circuit breaking rule judgments and the logic switch judgments of the circuit breaker used for circuit breaking. The aforementioned annotations are special markers applied to elements such as classes, methods, parameters, variables, constructors, and packages in computer programming languages. These markers can be read during compilation, loading, and runtime, and corresponding processing can be performed. Annotation information can be read at runtime or compile time through annotation processors or reflection mechanisms to perform specific processing. The aforementioned AOP aspect is a technique in Java aspect-oriented programming, which executes extended code before and after the execution of the target method, thereby improving code extensibility while reducing code coupling. The aforementioned circuit breaker is a state machine for the circuit breaking logic switch, including three modes: open, closed, and half-open.
[0049] Understandably, the aforementioned target pre-notification is the pre-processing logic of the AOP aspect pre-set for the target method. The target pre-notification will be triggered and executed before the target method is called. The target method's metadata may include the application's Internet Protocol address (IP), application name, class name, method name, input / output parameter names, and return value name of the system application executing the circuit breaker method. The aforementioned circuit breaker configuration parameters are pre-configured circuit breaker rules on the associated backend management system for the target method. These may include circuit breaker strategies, such as whether to determine circuit breaker based on the number of exceptions or the exception ratio, and may also include ratio thresholds, exception frequency thresholds, circuit breaker duration (in milliseconds), minimum request count, statistical duration (in milliseconds), circuit breaker rules (specifically, MVEL expressions), circuit breaker degradation strategies, specified exception class names, and the strategy for determining whether captured exceptions are included in the circuit breaker. Set the circuit breaker configuration parameters to the target method that needs to be circuit-breakered. For methods that have not been configured with circuit breakers, the corresponding circuit breaker configuration parameters are empty. The current state of the circuit breaker described above is one of three: open, partially open, or closed. MVEL expressions are a lightweight expression language used for reflection optimization and script execution. Based on Java syntax, MVEL expressions are suitable for scenarios requiring dynamic calculation and logical processing.
[0050] When the system application starts (e.g., for an upstream business system that needs to make API calls), the annotation scanner scans the metadata of all methods that require circuit breaking and are marked with preset annotations. It then sends the metadata of all annotated methods, along with the corresponding circuit breaking configuration parameters, to a data storage center (e.g., Nacos (Dynamic Naming and Configuration Service)) via a network request for storage. When the background management application starts, it reads the target methods of all APIs from the data storage center and displays the metadata and previously configured circuit breaking parameters in a visual format on the corresponding interface.
[0051] The aforementioned circuit breaker configuration parameters can be configured via the display interface. Specifically, the configuration entry point for each of these circuit breaker configuration parameters can be provided on the display interface associated with the background management application. Users can add or modify the values of the corresponding circuit breaker configuration parameters, which are then saved to the data storage center. After saving, the data storage center will send network requests to all application machines in the system, pushing the latest circuit breaker configuration parameters to the machine nodes of each application machine. After receiving the latest circuit breaker configuration parameters, the machine nodes will classify and organize the circuit breaker configuration parameters and metadata, and save them to the machine's memory for subsequent use in circuit breaker judgment during interface calls. Additionally, the counters corresponding to the number of calls and the number of call errors used for circuit breaker statistics can be initialized to 0.
[0052] Before the target method is invoked, the pre-processing logic of the AOP aspect will be executed based on the set target pre-instructions. In this pre-processing logic, the corresponding circuit breaker configuration parameters will be retrieved from the data storage center based on the target method's metadata. Then, the pre-processing logic will continue to confirm whether the target method meets the invocation conditions based on the circuit breaker configuration parameters and the current state of the circuit breaker. Once the invocation conditions are confirmed to be met, the specific logic for invoking the target method will be executed, that is, the processing logic within the target method will be executed.
[0053] The invocation condition is a preset setting used to determine whether the target method has already undergone a circuit breaker / downgrade strategy. Methods that have already undergone a circuit breaker / downgrade strategy will not meet the invocation condition; while methods that have not undergone a circuit breaker / downgrade strategy will meet the invocation condition.
[0054] Step S220: Based on the target post-advice, determine whether the target method was successfully called; if so, execute the pre-configured MVEL expression according to the target method's metadata; if the MVEL expression execution result is true, count the number of calls and the number of call errors; wherein, the target post-advice is the post-advice of the AOP aspect pre-configured for the target method.
[0055] After the target method is invoked, the AOP aspect's post-advice, or post-processing logic, is triggered. This post-processing logic checks whether the target method was successfully invoked, i.e., whether its execution was successful. It retrieves the circuit breaker configuration parameters based on the target method's metadata, and then determines whether to perform circuit breaker processing based on the invocation status. Specifically, if the target method is successfully invoked, the pre-configured circuit breaker rule is executed. This circuit breaker rule is an MVEL expression. Specifically, the target method's input and output parameters are substituted into the pre-configured MVEL expression, and the execution result of the MVEL expression determines again whether circuit breaker processing is necessary. The input and output parameters are the target method's input parameters and output information. Using the MVEL expression, a piece of Java-like code is executed according to the rules, which evaluates the target method's input parameter array (i.e., the array of input parameters) and output parameters. For example, if the MVEL expression is "param[0]==123456&&result=='Failed'", it means that if the first parameter of the input parameter group of the target method is equal to "123456" and the output parameter of the target method is the string "Failed", then the execution result of the MVEL expression is true. This indicates that the execution result of the target method meets the business scenario that requires circuit breaking, such as a field in the interface response containing the situation of insufficient funds. In this case, the number of calls and the number of call errors will be counted.
[0056] Additionally, if the MVEL expression evaluates to false, the current state of the circuit breaker is determined. If the current state is open, no action is taken; if the current state is partially open, the partially open state needs to be changed to closed; if the current state is closed, no action is taken.
[0057] Step S230: If the target method call fails, the number of calls and the number of call errors are counted according to the circuit breaker configuration parameters.
[0058] When the target method call fails, it is necessary to determine whether to count the error of this call based on the circuit breaker configuration parameters. For example, if the exception thrown by the failed target method call has the same class name as the exception specified in the circuit breaker configuration parameters, then the method call meets the exception conditions that require circuit breaking, and both the error count and the call count are counted, with the count incremented by 1.
[0059] Step S240: Based on the number of calls and the number of call errors within the preset sliding time window, and in conjunction with the circuit breaker configuration parameters, determine whether to perform circuit breaker processing on the target method; if so, perform circuit breaker processing on the target method.
[0060] Specifically, the total number of calls and the number of call errors within the sliding time window are counted to determine whether the target method needs circuit breaking. Once it is determined that the target method needs circuit breaking, a circuit breaking degradation strategy is executed, such as throwing a preset exception. Furthermore, the circuit breaker's current state is set to open, and the timest for the next circuit breaker recovery is set based on the current system timestamp and the circuit breaker duration, thereby controlling that the target method will not be called within the aforementioned circuit breaker duration.
[0061] Specifically, the aforementioned sliding time window can be a fixed time interval divided into smaller sub-intervals. Each time a count is performed, the window slides back N sub-intervals based on the current time, simultaneously accumulating the count values of all sub-intervals. Therefore, flexible and accurate statistical counting can be achieved as time changes.
[0062] Steps S210 to S240 above involve obtaining the metadata and circuit breaker configuration parameters of the target method of the interface based on the target before notification, and confirming whether the target method meets the calling conditions according to the circuit breaker configuration parameters and the current state of the circuit breaker; if so, the target method is called; wherein, the target before notification is the before notification of the AOP aspect pre-configured for the target method; based on the target after notification, determining whether the target method is successfully called; if so, executing the pre-configured circuit breaker rules according to the metadata of the target method; if the circuit breaker rule execution result is true, counting the number of calls and the number of call errors; wherein, the target after notification is the after notification of the AOP aspect pre-configured for the target method; if the target method call fails, counting the number of calls and the number of call errors according to the circuit breaker configuration parameters; based on the number of calls and the number of call errors within the preset sliding time window, combined with the circuit breaker configuration parameters, determining whether to perform circuit breaker processing on the target method; if so, circuit breaker processing is performed on the target method. It can use AOP aspects to determine the circuit breaker for target methods and promptly process the circuit breaker for target methods that meet the circuit breaker trigger conditions, thereby avoiding the high failure rate caused by frequent calls to business interfaces that fail to respond.
[0063] In one embodiment, based on step S210 above, determining whether the target method meets the invocation conditions according to the circuit breaker configuration parameters and the current state of the circuit breaker may specifically include:
[0064] If the circuit breaker configuration parameters are not empty and the circuit breaker is currently in the closed state, confirm that the target method meets the calling conditions.
[0065] In the pre-processing logic of the AOP aspect configured for the target method, it will determine whether the circuit breaker configuration parameter is empty. If it is not empty, it needs to obtain the current state of the circuit breaker corresponding to the target method. If the current state of the circuit breaker is closed, it means that the target method has not been subjected to circuit breaker processing beforehand, so the target method can be called directly.
[0066] In this embodiment, by combining the circuit breaker configuration parameters and the circuit breaker status, it is determined whether to call the target method. This avoids calling methods that fail to respond, thereby preventing a high failure rate in business execution caused by frequent calls to methods that fail to respond.
[0067] In another embodiment, based on the above step S210, determining whether the target method meets the invocation conditions according to the circuit breaker configuration parameters and the current state of the circuit breaker may specifically include:
[0068] If the circuit breaker configuration parameters are not empty and the circuit breaker is currently in the open state, determine whether the current timestamp is greater than or equal to the next retry timestamp. If so, set the current state of the circuit breaker to half-open and confirm that the target method meets the calling conditions. The next retry timestamp is determined based on the circuit breaker duration specified in the circuit breaker configuration parameters and the timestamp corresponding to the last circuit breaker processing of the target method. Otherwise, confirm that the target method does not meet the calling conditions and execute the preset circuit breaker degradation strategy.
[0069] If the circuit breaker is currently in the open state, it indicates that the target method has already undergone circuit breaker processing. Therefore, it is necessary to determine whether the circuit breaker processing set for the target method has exceeded the preset circuit breaker duration. If so, it is necessary to determine whether the restriction on this call to the target method can be lifted.
[0070] Specifically, it checks if the current timestamp is greater than or equal to the next retry timestamp. If so, it indicates that the circuit breaker processing for the target method has exceeded the circuit breaker duration, and the current call request to the target method can be allowed to complete the call. In other words, this call request can serve as a sniffing request for circuit breaker recovery, allowing the post-processing logic of the AOP aspect to determine whether the normal call to the target method can be resumed. Furthermore, the current state of the circuit breaker can be set to half-open. The aforementioned next retry timestamp can be determined by summing the timestamp corresponding to the most recent circuit breaker processing of the target method with the preset circuit breaker duration.
[0071] If the current timestamp is still less than the next retry timestamp, it indicates that the circuit breaker duration set for the target method has not yet exceeded the circuit breaker timeout. Therefore, the circuit breaker process needs to continue to prevent this call to the target method. A preset circuit breaker degradation strategy can be executed, such as throwing a specific exception.
[0072] In this embodiment, by determining whether to call the target method or continue to restrict calls based on timestamp information when the circuit breaker is open, accurate and flexible circuit breaking processing can be achieved, thereby avoiding excessive restrictions on calls to methods that can be called normally and erroneous calls to methods that cannot respond normally.
[0073] In another embodiment, based on step S210 above, confirming whether the target method meets the invocation conditions according to the circuit breaker configuration parameters and the current state of the circuit breaker may include:
[0074] If the circuit breaker configuration parameters are not empty and the circuit breaker is currently in a half-open state, the target method is confirmed not to meet the call conditions, and the preset circuit breaker degradation strategy is executed. That is, even if the circuit breaker is currently in a half-open state, circuit breaker degradation processing still needs to be performed to prevent the current call to the target method.
[0075] Additionally, the aforementioned interface circuit breaker method may also include: confirming that the target method meets the invocation conditions when the circuit breaker configuration parameters are empty. An empty circuit breaker configuration parameter indicates that the target method has not been configured for circuit breaker operation and can be invoked directly.
[0076] Furthermore, in one embodiment, when the target method call fails, counting the number of calls and the number of call errors according to the circuit breaker configuration parameters may include:
[0077] When the target method call fails, obtain the call exception type that caused the target method call to fail; determine whether the call exception type is consistent with the preset exception type specified in the circuit breaker configuration parameters; if so, count the number of method calls and the number of method call errors within the current sliding time window.
[0078] In other words, after the target method call is completed, the post-processing logic of the AOP aspect is entered. In this post-processing logic, the circuit breaker configuration parameters are obtained based on the target method's metadata. If the target method call fails, such as due to network timeout or system error, the corresponding interface will throw a business exception. After the AOP aspect catches this business exception, it first obtains the statistical counters under the current sliding time window based on the target method's metadata, including the total method call counter and the method call error counter. Based on the exception type configured in the backend, it determines whether the currently thrown business exception falls under the exception type specified in the circuit breaker configuration parameters (this type can be represented by a specific exception class name). If the thrown exception is the same as the specified exception type, then the target method meets the exception condition corresponding to the circuit breaker, and the total method call counter and the method call error counter are incremented by 1. For example, some exception classes in the Java language can be selected as the specified exception types for circuit breaker processing, or all exception classes in the Java language can be selected as the specified exception types for circuit breaker processing.
[0079] In this embodiment, determining whether to count the call errors of the target method based on the exception type enables accurate exception filtering.
[0080] Furthermore, in one embodiment, based on the above step S240, according to the number of calls and the number of call errors within a preset sliding time window, combined with the circuit breaker configuration parameters, it is determined whether to perform circuit breaker processing on the target method, which may specifically include:
[0081] When the circuit breaker condition specified in the circuit breaker configuration parameters is the number of exceptions, the number of calls is greater than or equal to the minimum number of requests specified in the circuit breaker configuration parameters, and the number of call errors is greater than or equal to the threshold number specified in the circuit breaker configuration parameters, circuit breaker processing is confirmed for the target method, the current state of the circuit breaker is set to open, and the next retry timestamp is set according to the specified circuit breaker duration. When the circuit breaker condition is the exception ratio, the number of calls is greater than or equal to the minimum number of requests, and the call error ratio is greater than or equal to the ratio threshold specified in the circuit breaker configuration parameters, circuit breaker processing is confirmed for the target method, the current state of the circuit breaker is set to open, and the next retry timestamp is set according to the circuit breaker duration. The call error ratio is the ratio of the number of call errors to the number of calls.
[0082] The process begins by determining the current state of the circuit breaker. If it's open, no action is taken; if it's partially open, it needs to be changed to open; if it's closed, the circuit breaker's trigger condition needs to be set. Specifically, if the circuit breaker trigger condition is an exception count, it indicates that the number of failed calls will be used as the basis for triggering the circuit breaker. Therefore, it's necessary to determine whether the total number of requests to the target method within the current sliding time window (i.e., the number of calls) is greater than or equal to the pre-configured minimum number of requests. If it's less, the call to the target method is allowed. Otherwise, it's determined whether the number of call errors is greater than or equal to the pre-configured threshold. If it's less, the call to the target method is allowed; if it is greater, the circuit breaker's current state is set to open, and the next retry timestamp is set based on the sum of the current timestamp and the circuit breaker duration to indicate the circuit breaker recovery time, forming a logical loop with the call condition determination in the pre-processing logic.
[0083] Additionally, if the circuit breaker condition is an abnormal ratio, it checks whether the total number of requests (number of calls) within the current sliding time window is greater than or equal to the configured minimum number of requests. If it is less than the minimum number of requests, the call to the target method is allowed. If it is greater than or equal to the minimum number of requests, the error ratio is calculated, which is the ratio of the number of call errors to the number of calls. If the error ratio is greater than or equal to the configured ratio threshold, the circuit breaker is set to open, and the next circuit breaker recovery timestamp (next retry timestamp) is set according to the current timestamp and the circuit breaker duration. If the error ratio is less than the ratio threshold, the request is allowed.
[0084] In this embodiment, the circuit breaker is applied to the frequency of call errors obtained from statistics based on either the number of anomalies or the proportion of anomalies, thereby achieving accurate and timely circuit breaker processing for abnormal call interfaces.
[0085] Specifically, in one embodiment, the duration of the sliding time window is set according to the circuit breaker statistics duration specified in the circuit breaker configuration parameters; the sliding time window includes several sub-time window intervals. In this embodiment, the length of the sliding time window is set according to the circuit breaker statistics duration specified in the circuit breaker configuration parameters. Each time circuit breaker statistics are performed, the current sliding time window is determined based on the current time and the circuit breaker statistics duration. Therefore, the time window in this embodiment is a flexible and dynamically changing window. Furthermore, dividing the sliding time window into multiple smaller sub-time window intervals allows for the separate statistics of the corresponding call count and call error count for each sub-time window interval.
[0086] Therefore, compared to the problem of inaccurate exception counting and inability to accurately perform circuit breaking when dealing with traffic surges during the transition between two windows using a fixed time window, this embodiment can flexibly and accurately perform circuit breaking for call exceptions generated at different times, thereby further improving the timeliness and accuracy of interface circuit breaking processing.
[0087] Figure 3 is a flowchart of a method for configuring circuit breaker configuration parameters according to some embodiments. This configuration method is executed after the system application starts. As shown in Figure 3, the method for configuring circuit breaker configuration parameters includes the following steps:
[0088] Step S301: After the system application starts, it scans the target methods with added annotations and registers the corresponding metadata to the data storage center.
[0089] Step S302: Start the background management application. The background management application reads the method metadata registered on the data storage center and adds the circuit breaker configuration parameters of the metadata to the data storage center.
[0090] In step S303, the data storage center sends the circuit breaker configuration parameters to each front-end application node; wherein, the front-end application node is the aforementioned machine node.
[0091] Step S304: The front-end application node sets the circuit breaker configuration parameters according to the metadata of multiple target methods.
[0092] In step S305, the front-end application node initializes the current state of the circuit breaker to closed, initializes the total call counter to 0, and initializes the call error counter to 0.
[0093] Figure 4 is a flowchart of one embodiment of the interface circuit breaker method. As shown in Figure 4, the interface circuit breaker method includes the following steps:
[0094] Step S401: Execute the pre-processing logic of the target method to determine whether the circuit breaker is closed; if yes, execute step S405; otherwise, execute step S402; wherein, before the target method is called, the pre-processing logic of the configured AOP aspect determines whether the current state of the circuit breaker is closed.
[0095] Step S402: Determine whether the circuit breaker is open; if yes, proceed to step S403; otherwise, proceed to step S413.
[0096] Step S403: Determine whether the retry time has been reached; if yes, proceed to step S404; otherwise, proceed to step S413; wherein, the determination of whether the retry time has been reached is based on the relationship between the current timestamp and the next retry timestamp.
[0097] Step S404: Determine whether the circuit breaker was successfully switched from open to half open; if so, proceed to step S405; otherwise, proceed to step S413.
[0098] Step S405: Call the target method.
[0099] Step S406: Determine if the target method call is abnormal; if yes, proceed to step S407; otherwise, proceed to step S414.
[0100] Step S407: Increment the total call counter and the call error counter under the current sliding time window by 1.
[0101] Step S408: Determine whether the circuit breaker is open; if yes, end the process; otherwise, proceed to step S409.
[0102] Step S409: Determine if the circuit breaker is partially open; if yes, proceed to step S415; otherwise, proceed to step S410.
[0103] Step S410: Determine whether the total number of requests under the current sliding time window is greater than or equal to the minimum number of requests; if yes, proceed to step S411; otherwise, end the process.
[0104] Step S411: Determine whether the current anomaly ratio is greater than or equal to a preset ratio threshold, or whether the current number of anomalies is greater than or equal to a preset number of calls threshold; if yes, proceed to step S412; otherwise, end the process. Here, the current anomaly ratio is the ratio between the number of call errors and the total number of calls. The number of anomalies is the number of call errors.
[0105] Step S412: Set the circuit breaker to open; end the process.
[0106] Step S413: Execute the circuit breaker degradation strategy; end the process. The circuit breaker degradation strategy can throw a preset exception.
[0107] Step S414: Determine whether the input and output parameters of the target method satisfy the MVEL expression; if yes, proceed to step S407; otherwise, end the process.
[0108] Step S415: Determine whether the exception type of the called exception meets the specified exception type, or whether the input and output parameters meet the MVEL expression; if yes, proceed to step S418; otherwise, proceed to step S416.
[0109] Step S416: Set the circuit breaker to closed.
[0110] Step S417: Reset all counters within the current sliding time window. Specifically, reset the total call counter and the call error counter. End the process.
[0111] Step S418: Set the circuit breaker to open.
[0112] Step S419: Update the next retry timestamp. End the process.
[0113] Steps S401 to S419 above involve intercepting and capturing the input and output parameters of the target method through AOP aspects, and executing MVEL expressions on the input and output parameters using dynamically configured MVEL expressions. If the execution result of the MVEL expression is true, the call is recorded as an abnormal call. Subsequently, by controlling the opening and closing of the circuit breaker within a sliding window based on the configured circuit breaker trigger condition, the interface call will be circuit-broken on the next call, and a degradation strategy will be executed to protect the business interface call from a high failure rate.
[0114] The following example illustrates the interface circuit breaker method described in the above embodiment. First, the system application name A, interface class name B, and interface class target method name C can be set. Then, based on the application name, interface class name, and interface class target method name, the full path unique identifier of the target method is determined as "A#B#C". The circuit breaker condition for the target method is configured as the number of exceptions, that is, whether to perform circuit breaker processing is determined based on whether the number of exceptions exceeds the threshold. The statistical threshold is set to 1, and the minimum number of requests is set to 1. The circuit breaker duration is set to 10000 milliseconds, and the circuit breaker statistics duration is set to 180000 milliseconds. The content of the MVEL expression is set to "param[0]==123456&&result=='Insufficient balance'", that is, when the input parameter of the target method is "123456", and the execution result of the target method is the string "Insufficient balance", the execution result of the MVEL expression is true. The flag for including exceptions in the circuit breaker statistics can be enabled; the specified exception class name can be set to all Java class names. Configure the circuit breaker degradation strategy to only throw a preset exception.
[0115] In other words, the above circuit breaker configuration is as follows: within a statistical duration of 180,000 milliseconds, if the number of calls to the target method meets the minimum request count requirement of 1, and if the number of call errors is 1, or if the MVEL expression is true 1 time, then a circuit breaker exception will be thrown within a 10,000 millisecond circuit breaker duration, continuously suspending calls to the target method.
[0116] The `@Fusing` annotation can be used to mark target methods that require circuit breaking. For example, you can set the `@Fusing` annotation on the target method "test" to mark it as requiring circuit breaking functionality. The content of the target method can be as follows:
[0117] When the target method is called, it will first output the input parameter "reqId". Then, it will specify that reqId equals the string "123" to simulate an exception during the target method call. In this case, an exception of type "BizException" will be thrown directly. If reqId is specified as the string "1234", it simulates the case where the target method returns data normally after the call, which does not satisfy the MVEL expression constructed above. If reqId is specified as the string "123456", it simulates the case where the target method returns data normally. Since the method return value is fixed as "insufficient balance", the MVEL expression constructed above is satisfied. It is understood that the execution logic of the target method and the specific content of the MVEL expression described above are merely examples and do not constitute a limitation on the target method or the MVEL expression.
[0118] After the application starts, it will obtain the background configuration log, obtain the unique identifier of the full path, the circuit breaker configuration parameters, and the metadata of the target method. When calling the target method, if the input parameter "reqId" is "1234", the target method will respond normally and output the message "insufficient balance". At this time, the target method is successfully called, and the MVEL expression will be executed to capture the input and output parameters. At this time, the input parameter group param[0] is "1234", which does not meet the condition of "param[0]==123456" in MVEL. Therefore, the execution result of the MVEL expression is false, and the target method can be called normally.
[0119] When calling the target method, if the input parameter "reqId" is "123", the target method will throw an exception with the message "123 is an invalid number, an exception has been thrown". Subsequently, when the same input parameter (i.e., "reqId" is "123") is used to call the target method a second time, the circuit breaker will trigger circuit breaking for that target method because the exception count threshold specified in the circuit breaker configuration parameters is one. At this time, the user will be notified that the service has been circuit broken. The circuit breaker's state will change from closed to open. On the third call to the target method, if the input parameter is changed to "1234" (i.e., simulating a normal request), the call will retry after 10,000 milliseconds of the circuit breaker's duration. The circuit breaker's state will then change from half-open to open, and the target method will resume normal operation.
[0120] Additionally, if the input parameter is changed to "123456" when the target method is called (simulating satisfying the MVEL expression condition), since the target method returns "insufficient balance", the MVEL expression "param[0]==123456&&result=='insufficient balance'" is true for the method's input and output parameters. At this time, the circuit breaker is changed from closed to open. In the second call, the input parameter is still "123456". Since the circuit breaker is already open, the circuit breaker is triggered, and an exception is thrown. In the third call, the input parameter is changed to "1234" (simulating a normal request). After the circuit breaker duration of 10000 milliseconds has expired, it is retried. At this time, the circuit breaker changes from half open to closed. The target method will resume normal call.
[0121] This embodiment also provides an interface fuse device for implementing the above embodiments and optional implementations; details already described will not be repeated. The terms "module," "unit," "subunit," etc., used below refer to combinations of software and / or hardware that implement a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0122] Figure 5 is a structural block diagram of the interface fuse device 50 of this embodiment. As shown in Figure 5, the interface fuse device 50 includes: an acquisition module 52, a judgment module 54, a counting module 56, and a fuse-breaking processing module 58; wherein:
[0123] The acquisition module 52 is used to acquire the metadata and circuit breaker configuration parameters of the target method of the interface based on the target before notification, and to confirm whether the target method meets the calling conditions according to the circuit breaker configuration parameters and the current state of the circuit breaker; if so, the target method is called; wherein, the target before notification is the before notification of the AOP aspect pre-configured for the target method. The judgment module 54 is used to determine whether the target method is successfully called based on the target after notification; if so, the pre-configured circuit breaker rules are executed according to the metadata of the target method; if the execution result of the circuit breaker rules is true, the number of calls and the number of call errors are counted; wherein, the target after notification is the after notification of the AOP aspect pre-configured for the target method. The counting module 56 is used to count the number of calls and the number of call errors according to the circuit breaker configuration parameters if the target method call fails. The circuit breaker processing module 58 is used to determine whether to perform circuit breaker processing on the target method according to the number of calls and the number of call errors within a preset sliding time window, combined with the circuit breaker configuration parameters; if so, the circuit breaker processing is performed on the target method.
[0124] It should be noted that the above modules can be functional modules or program modules, and can be implemented through software or hardware. For modules implemented through hardware, the above modules can reside in the same processor; or the above modules can be located in different processors in any combination.
[0125] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementations, and will not be repeated in this embodiment.
[0126] Furthermore, in conjunction with the interface circuit breaker method provided in the above embodiments, this embodiment can also provide a storage medium for implementation. The storage medium stores a computer program; when executed by a processor, the computer program implements any of the interface circuit breaker methods in the above embodiments.
[0127] It should be understood that the specific embodiments described herein are merely illustrative of the application and not intended to limit it. All other embodiments derived by those skilled in the art based on the embodiments provided in this application without inventive effort are within the scope of protection of this application.
[0128] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0129] Obviously, the accompanying drawings are merely some examples or embodiments of this application. Those skilled in the art can apply this application to other similar situations based on these drawings without any creative effort. Furthermore, it is understood that although the work done in this development process may be complex and lengthy, for those skilled in the art, certain design, manufacturing, or production modifications made based on the technical content disclosed in this application are merely conventional technical means and should not be considered as insufficient disclosure of this application.
[0130] The term "embodiment" in this application refers to a specific feature, structure, or characteristic described in connection with an embodiment that may be included in at least one embodiment of this application. The appearance of this phrase in various places in the specification does not necessarily imply the same embodiment, nor does it imply that it is mutually exclusive with or independent of other embodiments. It will be clearly or implicitly understood by those skilled in the art that the embodiments described in this application may be combined with other embodiments without conflict.
[0131] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of patent protection. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the appended claims.
Claims
1. A method for interface fuse breaking, characterized in that, include: Based on the target pre-notification, the meta-information and circuit breaker configuration parameters of the target method of the interface are obtained, and the circuit breaker configuration parameters and the current state of the circuit breaker are used to confirm whether the target method meets the calling conditions. If so, the target method is invoked; wherein the target before advice is a before advice of an AOP aspect pre-configured for the target method; Based on the target post-notification, it is determined whether the target method was successfully called; if so, the pre-configured circuit breaker rule is executed according to the meta-information of the target method; if the circuit breaker rule execution result is true, the number of calls and the number of call errors are counted; wherein, the target post-notification is a post-notification of the AOP aspect pre-configured for the target method. If the target method call fails, the number of calls and the number of call errors are counted according to the circuit breaker configuration parameters; Based on the number of calls and the number of call errors within the preset sliding time window, and in conjunction with the circuit breaker configuration parameters, it is determined whether to perform circuit breaker processing on the target method; if so, circuit breaker processing is performed on the target method.
2. The interface fuse-breaking method according to claim 1, wherein, Based on the circuit breaker configuration parameters and the current state of the circuit breaker, confirm whether the target method meets the invocation conditions, including: If the circuit breaker configuration parameters are not empty and the current state of the circuit breaker is closed, the target method is confirmed to meet the calling conditions.
3. The interface fuse breaking method according to claim 1, wherein, Based on the circuit breaker configuration parameters and the current state of the circuit breaker, confirm whether the target method meets the invocation conditions, including: If the circuit breaker configuration parameter is not empty and the current state of the circuit breaker is open, determine whether the current timestamp is greater than or equal to the next retry timestamp; if so, set the current state of the circuit breaker to half open and confirm that the target method meets the calling conditions; wherein, the next retry timestamp is determined according to the circuit breaker duration specified by the circuit breaker configuration parameter and the timestamp corresponding to the last circuit breaker processing of the target method; Otherwise, if the target method is found not to meet the calling conditions, the preset circuit breaker and degradation strategy is executed.
4. The interface fuse-breaking method according to claim 1, wherein, Based on the circuit breaker configuration parameters and the current state of the circuit breaker, confirm whether the target method meets the invocation conditions, including: If the circuit breaker configuration parameters are not empty and the current state of the circuit breaker is half open, it is confirmed that the target method does not meet the calling conditions, and the preset circuit breaker degradation strategy is executed.
5. The interface fuse breaking method according to claim 1, wherein, The method further includes: If the circuit breaker configuration parameters are empty, confirm that the target method meets the calling conditions.
6. The interface fusing method of claim 1, wherein, When the target method call fails, the number of calls and the number of call errors are counted according to the circuit breaker configuration parameters, including: When the target method call fails, obtain the call exception type that caused the target method call to fail; Determine whether the call exception type is consistent with the preset exception type specified in the circuit breaker configuration parameters; if so, count the number of method calls and the number of method call errors within the current sliding time window.
7. The interface fuse breaking method according to claim 1, wherein, Based on the number of calls and the number of call errors within a preset sliding time window, and in conjunction with the circuit breaker configuration parameters, determine whether to perform circuit breaker processing on the target method, including: When the circuit breaker condition specified in the circuit breaker configuration parameters is the number of exceptions, the number of calls is greater than or equal to the minimum number of requests specified in the circuit breaker configuration parameters, and the number of call errors is greater than or equal to the number of times specified in the circuit breaker configuration parameters, it is confirmed that circuit breaker processing will be performed on the target method, the current state of the circuit breaker will be set to open, and the next retry timestamp will be set according to the specified circuit breaker duration. When the circuit breaker determination condition is an abnormal ratio, the number of calls is greater than or equal to the minimum number of requests, and the call error ratio is greater than or equal to the ratio threshold specified by the circuit breaker configuration parameters, it is confirmed that the target method will be subjected to circuit breaker processing, the current state of the circuit breaker will be set to open, and the next retry timestamp will be set according to the circuit breaker duration; the call error ratio is the ratio of the number of call errors to the number of calls.
8. The interfusion method according to any one of claims 1 to 7, wherein, The duration of the sliding time window is set according to the circuit breaker configuration parameters specifying the circuit breaker statistical duration; the sliding time window includes several sub-time window intervals.
9. An interface fuse device, characterized by, include: The module includes an acquisition module, a judgment module, a counting module, and a circuit breaker handling module; among which: The acquisition module is used to acquire the metadata and circuit breaker configuration parameters of the target method of the interface based on the target before-notification, and to confirm whether the target method meets the calling conditions according to the circuit breaker configuration parameters and the current state of the circuit breaker; if so, the target method is called; wherein, the target before-notification is the before-notification of the AOP aspect pre-configured for the target method. The judgment module is used to determine whether the target method was successfully called based on the target post-notification; if so, it executes the pre-configured circuit breaker rule according to the meta-information of the target method; if the circuit breaker rule execution result is true, it counts the number of calls and the number of call errors; wherein, the target post-notification is a post-notification of the AOP aspect pre-configured for the target method. The counting module is used to count the number of calls and the number of call errors according to the circuit breaker configuration parameters if the target method call fails. The circuit breaker module is used to determine whether to perform circuit breaker processing on the target method based on the number of calls and the number of call errors within a preset sliding time window, combined with the circuit breaker configuration parameters; if so, the target method is subjected to circuit breaker processing.
10. A computer-readable storage medium having stored thereon a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the interface circuit breaking method according to any one of claims 1 to 8.
Citation Information
Patent Citations
API fusing degradation implementation method and system based on back-end error code
CN115065588A
Interface fusing method and device, server and computer readable storage medium
CN115686912A
Fusing processing method, device and equipment based on Golang language, medium and product
CN116126556A
Fusing information processing method and electronic equipment
CN118445097A
Interface fusing method, interface fusing device and computer readable storage medium
CN118916074A