Method for managing API (Application Program Interface) address

By combining the configuration center and the API gateway, the API interface address can be dynamically managed and updated, solving the problems of increased maintenance workload and long fault recovery time caused by interface address changes in the existing technology, and achieving high availability and rapid response of the system.

CN120743801APending Publication Date: 2025-10-03HENAN XUNLIN TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202510858584.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-25
Publication Date
2025-10-03

AI Technical Summary

Technical Problem

In existing technologies, changes in the binding relationship of API interface addresses require re-evaluation and updating, resulting in increased maintenance workload. Strong coupling relationships lead to project changes and risk transfer, especially in the event of a failure, which results in a long recovery time.

Method used

The API interface address is stored and dynamically updated through the configuration center, supporting multi-version management, using the API gateway for routing, and combined with the fault tolerance mechanism to automatically retry, downgrade and switch to the backup interface address, realizing real-time query and automatic update of the interface address.

Benefits of technology

It improves the system's fault tolerance, reduces coupling between services, improves the system's maintainability and response speed, reduces the impact of failures, reduces the need for manual intervention, and improves fault recovery speed and efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120743801A_ABST
    Figure CN120743801A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of computers, in particular to a method for managing an API (Application Program Interface) address, which comprises the following steps of: S1, storing the API address and dynamically updating the API address through a configuration center, and supporting multi-version management; when the system is used, the optimal version is dynamically selected and the availability of the interface is evaluated, so that the system can be conveniently and automatically switched to a more stable version, the fault-tolerant capability of the system is improved, the API gateway is used as a unified entrance, management and routing of API requests are simplified, coupling between services is reduced, the maintainability of the system is improved, and the system reliability is improved. Through real-time query and automatic updating of the interface address, tedious operation of manual intervention is avoided, the response speed and the stability of the system are improved, the influence caused by faults is reduced, fault processing is carried out automatically according to the preset strategy, the requirement for manual intervention is reduced, and the fault recovery speed and efficiency are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method for managing API interface addresses. Background Art

[0002] An API (Application Programming Interface) is a specification for communication between computer systems. An API address is the network address of a specific service, used to instruct computers on how to access a service or resource. An API address typically contains a protocol, domain name, port number, path, and possible query parameters. Computers use this information to identify the target service and initiate requests.

[0003] The patent application number is CN201811613199.X, and its description states that "the present invention relates to a method and system for managing API interface addresses, the method comprising: obtaining a target project and related projects, establishing a binding relationship between the target project and the related projects, adding an API interface address based on the binding relationship, and calling the API interface address of the related project for use. The management system comprises an acquisition module, a relationship binding module, an address binding module, and a calling module, which solves the problem of requiring multiple R&D personnel to cooperate with testers to conduct project testing, can uniformly manage the API interface addresses of different projects, can flexibly call the API interface addresses, and avoid confusion in API interface addresses caused by project version releases." Although the above technology can simplify the interface calling process through two-way binding, the binding relationship changes, and the related interface addresses need to be re-evaluated and updated, resulting in increased maintenance workload. The strong coupling relationship of the two-way binding causes changes in project a, and other related projects b, c, and d will also be affected, resulting in risk transfer. In particular, when a failure occurs, a longer recovery time is required.

[0004] In summary, developing a method for managing API interface addresses is still a key issue that needs to be urgently addressed in the field of computer technology. Summary of the Invention

[0005] The purpose of the present invention is to solve the problem in the prior art that although the above-mentioned technology can simplify the interface calling process through two-way binding, the binding relationship changes, and the relevant interface addresses need to be re-evaluated and updated, resulting in increased maintenance workload. The strong coupling relationship of two-way binding causes changes in project a, and other related projects b, c and d will also be affected, resulting in risk transfer, especially when a failure occurs, requiring a long recovery time.

[0006] To achieve the above object, the present invention provides the following technical solutions:

[0007] The present invention provides a method for managing API interface addresses, comprising the following steps: S1, storing API interface addresses and dynamically updating API interface addresses through a configuration center, and supporting multi-version management;

[0008] S2. Query the interface address through the configuration center, and use the API interface address of application A to call the API interface address of application B;

[0009] S3. Deploy the API gateway and perform API gateway routing based on the API interface address provided by the configuration center;

[0010] S4. When the API interface address changes, the new API interface address is pushed to the API gateway through the configuration center;

[0011] S5. When an API interface call fails, the fault-tolerant mechanism automatically retries, downgrades, and switches to a backup API interface address.

[0012] Furthermore, in step S1, the method for storing the API interface address and dynamically updating the API interface address through the configuration center and supporting multi-version management is:

[0013] Select Nacos Configuration Center to integrate with the application architecture, and use the configuration center as a centralized configuration management service. Use a structured approach to manage and dynamically update the API interface addresses stored in the configuration center. The storage method is in the form of key-value pairs, JSON, and YAML formats. The configuration center supports version selection management, and switches versions through the version number of the configuration file. The availability of each version of the API interface address is evaluated through the availability calculation formula, and the API interface address is updated through the push mechanism of the configuration center. In addition, the configuration center checks every 5 minutes for updates to the API interface address and provides the latest API interface address configuration to the application. The version selection formula is: Used to select the optimal API version based on version weight and availability, where V r is the optimal version selected, w represents an API version, Q(w) is the weight of the version, E(w) is the availability of the version, arg max represents the value that maximizes the expression, and the availability calculation formula is: Where E(w) is the availability of the API version, is the adjustment factor for availability, and ErrorRate(w) is the error rate of the API version.

[0014] Furthermore, in step S2, the interface address is queried through the configuration center, and the method for the API interface address of application A to call the API interface address of application B is:

[0015] Nacos automatically obtains the interface address configuration stored in the configuration center. Application A selects the API interface address of the corresponding version of Application B based on the requested API version number. The configuration center supports dynamic updates. Application A receives notifications of configuration changes in real time through the push mechanism. When the API interface address of Application B changes, the configuration center pushes updates to Application A.

[0016] Furthermore, in step S2, the interface address is queried through the configuration center, and the method for the API interface address of application A to call the API interface address of application B is:

[0017] During the query process, application A caches the API interface address and sets a cache expiration time. After obtaining the API interface address of application B, application A makes subsequent API calls through the API interface address. API calls are made using HTTP and HTTPS network protocols. The cache expiration and query formulas are as follows: where y(t) represents the current validity of the cached data, u0 represents the current time point, u1 represents the storage time of the cached data, I represents the maximum survival time of the cached data, and exp(·) is an exponential function.

[0018] Furthermore, in step S3, by deploying the API gateway, the method for performing API gateway routing according to the API interface address provided by the configuration center is:

[0019] Deploy Nginx API gateway. The API gateway serves as a unified entry point and is responsible for receiving and forwarding all API requests. Then, the API gateway is integrated with the configuration center to query the stored API interface address in real time. The API gateway dynamically generates routing configuration based on the interface address, routing rules, and load balancing obtained from the configuration center. The load balancing formula is: Among them a represents the load distribution ratio of the i-th service node, p i represents the processing capacity of the i-th service node, represents the total processing capacity of all i service nodes, and N represents the total number of nodes in the service cluster.

[0020] Furthermore, in step S3, by deploying the API gateway, the method for performing API gateway routing according to the API interface address provided by the configuration center is:

[0021] When an API involves multiple versions, the API gateway routes based on the version number in the API request and the API interface address of the corresponding version in the configuration center. When the API interface address in the configuration center changes, the API gateway can obtain the new interface address configuration in real time, and then use the push mechanism of the configuration center to automatically update the routing configuration of the API interface address.

[0022] Furthermore, in step S4, when the API interface address changes, the method of pushing the new API interface address to the API gateway through the configuration center is:

[0023] The configuration center provides a change monitoring and push mechanism. When the API interface address changes, the configuration center can identify and trigger a change event, and use the push mechanism to push the changed API interface address to the API gateway. During the push process, the configuration center will send the updated interface address, version number, and related configurations to the API gateway.

[0024] Furthermore, in step S4, when the API interface address changes, the method of pushing the new API interface address to the API gateway through the configuration center is:

[0025] After receiving the push notification, the API gateway updates the routing rules according to the new configuration, reloads the configuration, replaces the old API interface address, and processes subsequent API requests according to the new configuration. After the new API interface address takes effect, the API gateway automatically uses the new routing rules, and the old API interface address will be eliminated under the guidance of the configuration center. The push update and routing rule update formula is: Among them S d represents the success probability of the configuration update, D represents the probability that the API gateway successfully receives the configuration update request, and F represents the delay time of the configuration update.

[0026] Furthermore, in step S5, when a fault occurs in an API interface call, the method for automatically retrying, downgrading, and switching to a backup API interface address is as follows:

[0027] The monitoring system monitors the health of the API interface in real time, detects whether the interface call is successful, and determines whether a failure occurs by recording the response status code and timeout. When the interface returns an error or timeout, the problem is identified, triggering the fault tolerance mechanism, and automatically retrying according to the preset retry strategy. The retry strategy includes a maximum of 3 retries, each with an interval of 1 second. If the retry is successful, the process ends and the result is returned to the caller. If the retry fails after the maximum number of times, the process enters the degradation processing stage. The degradation processing includes returning default data, using a simplified version of the API function, and switching to low-priority or low-risk services. The formula for the probability of retry failure is: Among them G h (α,β) represents the probability of failure after α attempts, β is the average number of failures per unit time, α represents the number of failed attempts, ε is the base of the natural logarithm, and α! represents the factorial. The retry success rate formula is: G k (χ)=1-G h (α,β), where G k (χ) represents the probability of successful operation, G h (α, β) represents the probability of operation failure, and the degradation strategy formula is: Among them G L is the degree of degradation, Z max is the maximum allowed degradation threshold, Z cur is the current level of degradation.

[0028] Furthermore, in step S5, when a fault occurs in an API interface call, the method for automatically retrying, downgrading, and switching to a backup API interface address is as follows:

[0029] If the API interface address is still unavailable after the downgrade process, it will be switched according to the pre-configured backup API interface address. The backup interface address includes other service nodes with the same function, API interfaces of different versions, and completely independent backup service systems. After the switch, the API request will continue to be executed. When the original API interface address is restored, it will automatically switch back to the primary API interface address. During the recovery process, the availability of the restored API interface address will be verified by the reliability formula. After the recovery switch is completed, the backup API interface address and the downgrade process will be stopped. During the fault-tolerant process, relevant logs and error information will be recorded, and an alarm will be issued through the monitoring system. The switching formula is: G X =C(V b )·M(V b ), where G X is the success probability of recovery switching, C(V b ) is the success rate of the recovery verification operation, M(V b ) is the delay in the recovery process, and the reliability formula is: where q t′ (i′) is the overall reliability of restoring the API interface address at time i′, q H (i′) represents the reliability of the Hth sub-recovery API interface address at time i′, n represents the total number, For all q between H = 1 and n H (i′).

[0030] Beneficial effects

[0031] Compared with the known public technology, the technical solution provided by the present invention has the following advantages:

[0032] Beneficial effects:

[0033] When in use, the present invention facilitates automatic switching to a more stable version by dynamically selecting the optimal version and evaluating the availability of the interface, which is beneficial to improving the fault tolerance of the present application. The API gateway serves as a unified entrance, simplifies the management and routing of API requests, reduces the coupling between services, and improves the maintainability of the system. By querying and automatically updating the interface address in real time, it is beneficial to avoid the tedious operation of manual intervention, improves the response speed and system stability, and helps to reduce the impact of failures. The present application automatically handles faults according to preset strategies, which is beneficial to reducing the need for manual intervention and improving the speed and efficiency of fault recovery. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] Figure 1 This is a flow chart of a method for managing API interface addresses of the present invention. DETAILED DESCRIPTION

[0035] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.

[0036] It should be noted that the terms "first," "second," and the like in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or precedence. It should be understood that the numbers used in this manner are interchangeable where appropriate so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus comprising a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units that are not explicitly listed or that are inherent to these processes, methods, products, or apparatuses.

[0037] The present invention is described in further detail below with reference to the accompanying drawings:

[0038] Example:

[0039] like Figure 1As shown, the present invention provides a method for managing API interface addresses, comprising the following steps: S1, storing API interface addresses and dynamically updating API interface addresses through a configuration center, and supporting multi-version management;

[0040] Furthermore, in step S1, the method for storing the API interface address and dynamically updating the API interface address through the configuration center and supporting multi-version management is:

[0041] Select Nacos Configuration Center to integrate with the application architecture, and use the configuration center as a centralized configuration management service. Use a structured approach to manage and dynamically update the API interface addresses stored in the configuration center. The storage method is in the form of key-value pairs, JSON, and YAML formats. The configuration center supports version selection management, and switches versions through the version number of the configuration file. The availability of each version of the API interface address is evaluated through the availability calculation formula, and the API interface address is updated through the push mechanism of the configuration center. In addition, the configuration center checks every 5 minutes for updates to the API interface address and provides the latest API interface address configuration to the application. The version selection formula is: Used to select the optimal API version based on version weight and availability, where V r is the optimal version selected, w represents an API version, Q(w) is the weight of the version, E(w) is the availability of the version, arg max represents the value that maximizes the expression, and the availability calculation formula is: Where E(w) is the availability of the API version, is the availability adjustment factor, ErrorRate(w) is the error rate of the API version;

[0042] In this embodiment, by evaluating availability and dynamically selecting the optimal API version, it is convenient to use the interface with the highest availability, reducing the impact of interface failures on the business. By utilizing settings that support API multi-version management, the interface version can be flexibly switched according to actual needs, reducing compatibility issues caused by version changes. The configuration center automatically pushes API interface address updates and conducts regular checks to facilitate the use of the latest API interface and reduce manual intervention. By dynamically selecting the optimal version and evaluating the availability of the interface, it is convenient to automatically switch to a more stable version, which is beneficial to improving the fault tolerance of this application. The automated configuration management and update mechanism reduces the workload of operation and maintenance personnel and improves the maintenance efficiency of the system.

[0043] S2. Query the interface address through the configuration center, and use the API interface address of application A to call the API interface address of application B;

[0044] Furthermore, in step S2, the interface address is queried through the configuration center, and the method for the API interface address of application A to call the API interface address of application B is:

[0045] Nacos automatically obtains the interface address configuration stored in the configuration center. Application A selects the API interface address of the corresponding version of Application B based on the requested API version number. The configuration center supports dynamic updates. Application A receives notifications of configuration changes in real time through the push mechanism. When the API interface address of Application B changes, the configuration center pushes updates to Application A.

[0046] Furthermore, in step S2, the interface address is queried through the configuration center, and the method for the API interface address of application A to call the API interface address of application B is:

[0047] During the query process, application A caches the API interface address and sets a cache expiration time. After obtaining the API interface address of application B, application A makes subsequent API calls through the API interface address. API calls are made using HTTP and HTTPS network protocols. The cache expiration and query formulas are as follows: Where y(t) represents the current validity of the cached data, u0 represents the current time point, u1 represents the storage time of the cached data, I represents the maximum survival time of the cached data, and exp(·) is an exponential function;

[0048] In this embodiment, through the push mechanism of the configuration center, application A can obtain notifications of changes to the interface address in real time, ensuring that the latest API interface address is always used, reducing errors caused by expired API interface addresses, and by caching the API interface address, reducing the overhead of frequent queries to the configuration center, which is beneficial to improving the performance of application A. The flexibility of cache management is improved by setting the cache validity period and formula calculation, while avoiding repeated queries to the configuration center. Through the caching and dynamic query mechanism, the response speed during the API call process is optimized, and the interface address is dynamically selected according to the API version number. Application A can flexibly switch to different versions of the API to meet different needs.

[0049] S3. Deploy the API gateway and perform API gateway routing based on the API interface address provided by the configuration center;

[0050] Furthermore, in step S3, by deploying the API gateway, the method for performing API gateway routing according to the API interface address provided by the configuration center is:

[0051] Deploy Nginx API gateway. The API gateway serves as a unified entry point and is responsible for receiving and forwarding all API requests. Then, the API gateway is integrated with the configuration center to query the stored API interface address in real time. The API gateway dynamically generates routing configuration based on the interface address, routing rules, and load balancing obtained from the configuration center. The load balancing formula is: Among them a represents the load distribution ratio of the i-th service node, p i represents the processing capacity of the i-th service node, represents the total processing capacity of all i service nodes, and N represents the total number of nodes in the service cluster.

[0052] Furthermore, in step S3, by deploying the API gateway, the method for performing API gateway routing according to the API interface address provided by the configuration center is:

[0053] When an API involves multiple versions, the API gateway routes based on the version number in the API request and the API interface address of the corresponding version in the configuration center. When the API interface address in the configuration center changes, the API gateway can obtain the new interface address configuration in real time, and then use the push mechanism of the configuration center to automatically update the routing configuration of the API interface address.

[0054] In this embodiment, the API gateway serves as a unified entry point, which simplifies the management and routing of API requests, reduces the coupling between services, and improves the maintainability of the system. Through integration with the configuration center, the API gateway can obtain real-time updates of the interface address, automatically adjust the routing configuration, and ensure that the request is correctly routed to the target service. The load balancing strategy facilitates the distribution of API requests, improves the performance and availability of this application, and uses the API gateway to select different versions of API interface addresses based on the API version number, supports version switching, and enables this application to still run stably in the case of multiple versions of API. Through load balancing and automatic routing updates, it is easy to maintain high availability in the face of service node failures or interface changes. Through real-time query and automatic update of interface addresses, it is helpful to avoid the tedious operation of manual intervention, improve the response speed and stability of the system, and as this application expands, the API gateway and configuration center dynamically adjust the service nodes and routing strategies according to demand to support the horizontal expansion of this application.

[0055] S4. When the API interface address changes, the new API interface address is pushed to the API gateway through the configuration center;

[0056] Furthermore, in step S4, when the API interface address changes, the method of pushing the new API interface address to the API gateway through the configuration center is:

[0057] The configuration center provides a change monitoring and push mechanism. When the API interface address changes, the configuration center can identify and trigger a change event, and use the push mechanism to push the changed API interface address to the API gateway. During the push process, the configuration center will send the updated interface address, version number, and related configurations to the API gateway.

[0058] Furthermore, in step S4, when the API interface address changes, the method of pushing the new API interface address to the API gateway through the configuration center is:

[0059] After receiving the push notification, the API gateway updates the routing rules according to the new configuration, reloads the configuration, replaces the old API interface address, and processes subsequent API requests according to the new configuration. After the new API interface address takes effect, the API gateway automatically uses the new routing rules, and the old API interface address will be eliminated under the guidance of the configuration center. The push update and routing rule update formula is: Among them S d represents the success probability of the configuration update, D represents the probability that the API gateway successfully receives the configuration update request, and F represents the delay time of the configuration update;

[0060] In this embodiment, by configuring the success probability of the update and the probability of the API gateway receiving the configuration update, the interface address update is completed in a short time through the push mechanism, which is conducive to reducing the risk of update failure and ensuring the availability of this application. By calculating the configuration update delay time, it is convenient to monitor the update process in real time, timely discover and solve potential performance bottlenecks, and make the API interface update process proceed smoothly. Due to the automation of the push mechanism and the rapid update of routing rules, it is conducive to reducing service interruptions caused by changes in the API interface address and improving the stability of the system.

[0061] S5. When an API call fails, the fault-tolerance mechanism automatically retries, downgrades, and switches to an alternate API interface address.

[0062] Furthermore, in step S5, when a fault occurs in an API interface call, the method for automatically retrying, downgrading, and switching to a backup API interface address is as follows:

[0063] The monitoring system monitors the health of the API interface in real time, detects whether the interface call is successful, and determines whether a failure occurs by recording the response status code and timeout. When the interface returns an error or timeout, the problem is identified, triggering the fault tolerance mechanism, and automatically retrying according to the preset retry strategy. The retry strategy includes a maximum of 3 retries, each with an interval of 1 second. If the retry is successful, the process ends and the result is returned to the caller. If the retry fails after the maximum number of times, the process enters the degradation processing stage. The degradation processing includes returning default data, using a simplified version of the API function, and switching to low-priority or low-risk services. The formula for the probability of retry failure is: Among them G h (α,β) represents the probability of failure after α attempts, β is the average number of failures per unit time, α represents the number of failed attempts, ε is the base of the natural logarithm, and α! represents the factorial. The retry success rate formula is: G k (χ)=1-G h (α,β), where G k (χ) represents the probability of successful operation, G h (α, β) represents the probability of operation failure, and the degradation strategy formula is: Among them G L is the degree of degradation, Z max is the maximum allowed degradation threshold, Z cur is the current level of degradation.

[0064] Furthermore, in step S5, when a fault occurs in an API interface call, the method for automatically retrying, downgrading, and switching to a backup API interface address is as follows:

[0065] If the API interface address is still unavailable after the downgrade process, it will be switched according to the pre-configured backup API interface address. The backup interface address includes other service nodes with the same function, API interfaces of different versions, and completely independent backup service systems. After the switch, the API request will continue to be executed. When the original API interface address is restored, it will automatically switch back to the primary API interface address. During the recovery process, the availability of the restored API interface address will be verified by the reliability formula. After the recovery switch is completed, the backup API interface address and the downgrade process will be stopped. During the fault-tolerant process, relevant logs and error information will be recorded, and an alarm will be issued through the monitoring system. The switching formula is: G X =C(V b )·M(V b ), where G X is the success probability of recovery switching, C(V b ) is the success rate of the recovery verification operation, M(V b ) is the delay in the recovery process, and the reliability formula is: where qt′ (i′) is the overall reliability of restoring the API interface address at time i′, q H (i′) represents the reliability of the Hth sub-recovery API interface address at time i′, n represents the total number, For all q between H = 1 and n H The product of (i′);

[0066] In this embodiment, through automatic retry, downgrade and backup interface switching, the present application continues to be available when the API interface fails, thereby reducing service interruptions caused by failures. Through downgrade processing and backup interface addresses, users will not be immediately affected when encountering API call failures, which is conducive to protecting the continuity and responsiveness of the service and improving the user experience. Through the fault-tolerant mechanism and the switching of the backup interface, it is convenient to switch to the backup interface when the main interface cannot provide service, so that the business is not interrupted, which is conducive to reducing the impact of the failure. The present application automatically handles faults according to preset strategies, which is conducive to reducing the need for manual intervention and improving the speed and efficiency of fault recovery. Recovery switching is performed according to the reliability of the interface, which is convenient for reliable restoration of services after the interface is restored, improving the overall availability and flexibility of the present application. The logging and monitoring system alarm functions integrated in the fault-tolerant mechanism track the cause of the fault and handle the fault in real time, and prevent the recurrence of the fault, so that the present application can operate stably for a long time.

[0067] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements will not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the various embodiments of the present invention.

Claims

1. A method for managing API interface addresses, characterized in that: The following steps are involved: S1. Store API interface addresses and dynamically update API interface addresses through the configuration center, and support multi-version management; S2. Query the interface address through the configuration center, and use the API interface address of application A to call the API interface address of application B; S3. Deploy the API gateway and perform API gateway routing based on the API interface address provided by the configuration center; S4. When the API interface address changes, the new API interface address is pushed to the API gateway through the configuration center; S5. When an API interface call fails, the fault-tolerant mechanism automatically retries, downgrades, and switches to a backup API interface address.

2. A method for managing API interface addresses according to claim 1, characterized in that: In step S1, the method for storing the API interface address and dynamically updating the API interface address through the configuration center and supporting multi-version management is: Select Nacos Configuration Center to integrate with the application architecture, and use the configuration center as a centralized configuration management service. Use a structured approach to manage and dynamically update the API interface addresses stored in the configuration center. The storage method is in the form of key-value pairs, JSON, and YAML formats. The configuration center supports version selection management, and switches versions through the version number of the configuration file. The availability of each version of the API interface address is evaluated through the availability calculation formula, and the API interface address is updated through the push mechanism of the configuration center. In addition, the configuration center checks every 5 minutes for updates to the API interface address and provides the latest API interface address configuration to the application. The version selection formula is: Used to select the optimal API version based on version weight and availability, where V r is the optimal version selected, w represents an API version, Q(w) is the weight of the version, E(w) is the availability of the version, arg max represents the value that maximizes the expression, and the availability calculation formula is: Where E(w) is the availability of the API version, is the adjustment factor for availability, and ErrorRate(w) is the error rate of the API version.

3. A method for managing API interface addresses according to claim 2, characterized in that: In step S2, the configuration center queries the interface address. The method for the API interface address of application A to call the API interface address of application B is: Nacos automatically obtains the interface address configuration stored in the configuration center. Application A selects the API interface address of the corresponding version of Application B based on the requested API version number. The configuration center supports dynamic updates. Application A receives notifications of configuration changes in real time through the push mechanism. When the API interface address of Application B changes, the configuration center pushes updates to Application A.

4. A method for managing API interface addresses according to claim 3, characterized in that: In step S2, the configuration center queries the interface address. The method for using the API interface address of application A to call the API interface address of application B is: During the query process, application A caches the API interface address and sets a cache expiration time. After obtaining the API interface address of application B, application A makes subsequent API calls through the API interface address. API calls are made using HTTP and HTTPS network protocols. The cache expiration and query formulas are as follows: where y(t) represents the current validity of the cached data, u0 represents the current time point, u1 represents the storage time of the cached data, I represents the maximum survival time of the cached data, and exp(·) is an exponential function.

5. A method for managing API interface addresses according to claim 4, characterized in that: In step S3, by deploying the API gateway, the method for routing the API gateway according to the API interface address provided by the configuration center is as follows: Deploy Nginx API gateway. The API gateway serves as a unified entry point and is responsible for receiving and forwarding all API requests. Then, the API gateway is integrated with the configuration center to query the stored API interface address in real time. The API gateway dynamically generates routing configuration based on the interface address, routing rules, and load balancing obtained from the configuration center. The load balancing formula is: Among them a represents the load distribution ratio of the i-th service node, p i represents the processing capacity of the i-th service node, represents the total processing capacity of all i service nodes, and N represents the total number of nodes in the service cluster.

6. A method for managing API interface addresses according to claim 5, characterized in that: In step S3, by deploying the API gateway, the method for routing the API gateway according to the API interface address provided by the configuration center is as follows: When an API involves multiple versions, the API gateway routes based on the version number in the API request and the API interface address of the corresponding version in the configuration center. When the API interface address in the configuration center changes, the API gateway can obtain the new interface address configuration in real time, and then use the push mechanism of the configuration center to automatically update the routing configuration of the API interface address.

7. A method for managing API interface addresses according to claim 6, characterized in that: In step S4, when the API interface address changes, the method of pushing the new API interface address to the API gateway through the configuration center is: The configuration center provides a change monitoring and push mechanism. When the API interface address changes, the configuration center can identify and trigger a change event, and use the push mechanism to push the changed API interface address to the API gateway. During the push process, the configuration center will send the updated interface address, version number, and related configurations to the API gateway.

8. A method for managing API interface addresses according to claim 7, characterized in that: In step S4, when the API interface address changes, the method of pushing the new API interface address to the API gateway through the configuration center is: After receiving the push notification, the API gateway updates the routing rules according to the new configuration, reloads the configuration, replaces the old API interface address, and processes subsequent API requests according to the new configuration. After the new API interface address takes effect, the API gateway automatically uses the new routing rules, and the old API interface address will be eliminated under the guidance of the configuration center. The push update and routing rule update formula is: Among them S d represents the success probability of the configuration update, D represents the probability that the API gateway successfully receives the configuration update request, and F represents the delay time of the configuration update.

9. A method for managing API interface addresses according to claim 8, characterized in that: In step S5, the method of automatically retrying, downgrading, and switching to a backup API interface address when a failure occurs in the API interface call through the fault tolerance mechanism is as follows: The monitoring system monitors the health of the API interface in real time, detects whether the interface call is successful, and determines whether a failure occurs by recording the response status code and timeout. When the interface returns an error or timeout, the problem is identified, triggering the fault tolerance mechanism, and automatically retrying according to the preset retry strategy. The retry strategy includes a maximum of 3 retries, each with an interval of 1 second. If the retry is successful, the process ends and the result is returned to the caller. If the retry fails after the maximum number of times, the process enters the degradation processing stage. The degradation processing includes returning default data, using a simplified version of the API function, and switching to low-priority or low-risk services. The formula for the probability of retry failure is: Among them G h (α,β) represents the probability of failure after α attempts, β is the average number of failures per unit time, α represents the number of failed attempts, ε is the base of the natural logarithm, and α! represents the factorial. The formula for the retry success rate is: G k (χ)=1-G h (α,β), where G k (χ) represents the probability of successful operation, G h (α, β) represents the probability of operation failure, and the degradation strategy formula is: Among them G L is the degree of degradation, Z max is the maximum allowed degradation threshold, Z cur is the current level of degradation.

10. The method for managing API interface addresses according to claim 8, characterized in that: In step S5, the method of automatically retrying, downgrading, and switching to a backup API interface address when a failure occurs in the API interface call through the fault tolerance mechanism is as follows: If the API interface address is still unavailable after the downgrade process, it will be switched according to the pre-configured backup API interface address. The backup interface address includes other service nodes with the same function, API interfaces of different versions, and completely independent backup service systems. After the switch, the API request will continue to be executed. When the original API interface address is restored, it will automatically switch back to the primary API interface address. During the recovery process, the availability of the restored API interface address will be verified by the reliability formula. After the recovery switch is completed, the backup API interface address and the downgrade process will be stopped. During the fault-tolerant process, relevant logs and error information will be recorded, and an alarm will be issued through the monitoring system. The switching formula is: G X =C(V b )·M(V b ), where G X is the success probability of recovery switching, C(V b ) is the success rate of the recovery verification operation, M(V b ) is the delay in the recovery process, and the reliability formula is: where q t′ (i′) is the overall reliability of restoring the API interface address at time i′, q H (i′) represents the reliability of the Hth sub-recovery API interface address at time i′, n represents the total number, For all q between H = 1 and n H (i′).

Citation Information

Patent Citations

  • Method and system for managing API address

    CN109857480A