API gateway data synchronization method, device and storage medium based on strategy mode and task chain
Through the method based on policy patterns and task chains, dynamically matches the type and version number of the gateway, the flexibility of data synchronization of API gateways is achieved, and the problem of inflexible synchronization methods in the existing technology is solved, ensuring the stability and consistency of data synchronization.
Patent Information
- Application Number
- CN202510459055.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-14
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2045-04-14
AI Technical Summary
The existing API gateway data synchronization technology adopts hard-coded methods, which is difficult to adapt to the diversified needs of different gateways, resulting in poor synchronization flexibility.
Using a method based on policy patterns and task chains, we can obtain the gateway type, version number and port address, dynamically match the pull synchronization policy class, and call the synchronization interface to pull data from the gateway to realize data synchronization tasks.
Improves the flexibility of gateway data synchronization, can adapt to gateway type or version changes, and ensures the stability and consistency of data synchronization.
Smart Images

Figure CN120017662B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to an API gateway data synchronization method, device, and storage medium based on a policy pattern and a task chain. Background Art
[0002] In a microservices architecture, the API (Application Programming Interface) gateway serves as a unified request entry point, handling various non-business-related logic such as routing, load balancing, protocol conversion, and security protection. Each microservice, however, focuses on implementing its own business logic. To ensure stable operation and data consistency across the entire microservices architecture, data synchronization across multiple API gateways is required to centrally manage and update information such as service lists, API lists, and related policies.
[0003] At present, API gateway data synchronization technology usually adopts a hard-coded method. For example, if a multi-gateway platform manages multiple API gateways, when the multi-gateway platform needs to synchronize the data of the API gateways it manages, it will pre-write the code in the data synchronization module and define the relevant data processing logic. When the multi-gateway platform needs to synchronize gateway data, it will first receive the data, and then perform data synchronization processing according to the pre-defined data processing logic. However, the above hard-coded synchronization method is difficult to adapt to the diverse needs of different gateway data, because different types of gateways may have different data formats and synchronization interfaces. The data processing logic defined in advance in the data synchronization module cannot meet the diverse needs of different gateways, and the flexibility of gateway data synchronization is poor.
[0004] The above content is only used to assist in understanding the technical solution of this application and does not constitute an admission that the above content is prior art. Summary of the Invention
[0005] The main purpose of this application is to provide an API gateway data synchronization method, device and storage medium based on policy mode and task chain, aiming to solve the technical problem of poor flexibility of gateway data synchronization.
[0006] To achieve the above objectives, this application proposes an API gateway data synchronization method based on a strategy pattern and a task chain, the method comprising:
[0007] When the scheduled synchronization task chain of the gateway triggers the data pull synchronization task, the type, version number and port address of the gateway are obtained;
[0008] Based on the type and version number of the gateway, matching the configuration parameters in the data synchronization policy class, determining the pull synchronization policy class corresponding to the gateway;
[0009] Based on the pull synchronization policy class and the type, version number and port address of the gateway, a synchronization interface is called to pull data from the gateway to execute the data pull synchronization task.
[0010] In one embodiment, when the scheduled synchronization task chain of the gateway regularly triggers the data pull synchronization task, before the step of obtaining the type, version number and port address of the gateway, the method further includes:
[0011] In response to a new gateway instruction input by a user, obtaining the type, version number, and port address of the new gateway input by the user;
[0012] Based on the type, version number and port address of the newly added gateway input by the user, a scheduled synchronization task chain of the newly added gateway is created according to preset rules, and the scheduled synchronization task chain of the newly added gateway is controlled to trigger the data pull synchronization task.
[0013] In one embodiment, the step of calling a synchronization interface to pull data from the gateway based on the pull synchronization policy class and the type, version number, and port address of the gateway includes:
[0014] Read the pull implementation class list in the gateway adapter SDK through the pull synchronization strategy class;
[0015] The pull synchronization strategy class is matched with the pull implementation class list based on the type and version number of the gateway to determine the target pull implementation class;
[0016] Based on the target pull implementation class and the port address of the gateway, a synchronous interface is called to pull data from the gateway.
[0017] In one embodiment, when the scheduled synchronization task chain of the gateway regularly triggers the data pull synchronization task, before the step of obtaining the type, version number and port address of the gateway, the method further includes:
[0018] Define a service provider interface, which includes a data pull interface and a data push interface. The data pull interface is used to declare the synchronous data pull method that different gateway service providers need to implement, and the data push interface is used to declare the synchronous data push method that different gateway service providers need to implement.
[0019] The gateway adapter SDK sent by the receiving gateway service provider based on the service provider interface includes an implementation class, wherein the implementation class includes a pull implementation class and a push implementation class. The pull implementation class is used to implement the synchronous data pulling method, and the push implementation class is used to implement the synchronous data pushing method.
[0020] In one embodiment, the step of calling a synchronous interface to pull data from the gateway based on the target pull implementation class and the port address of the gateway includes:
[0021] Determining a synchronization interface corresponding to the gateway based on the port address of the gateway;
[0022] Based on the synchronous data pulling method corresponding to the target pull implementation class, data is pulled from the gateway through the synchronous interface.
[0023] In one embodiment, the method further comprises:
[0024] Receive new configuration data of the gateway input by the user and generate a real-time push synchronization task;
[0025] Based on the type and version number of the gateway, the configuration parameters in the data synchronization policy class are matched to determine the push synchronization policy class corresponding to the real-time push synchronization task;
[0026] Read the push implementation class list in the gateway adapter SDK through the push synchronization strategy class;
[0027] The push synchronization strategy class is matched with the push implementation class list based on the type and version number of the gateway to determine the target push implementation class;
[0028] Based on the synchronous data push method corresponding to the target push implementation class, the synchronization interface is called to push the newly added configuration data to the gateway to execute the real-time push synchronization task.
[0029] In one embodiment, the scheduled synchronization task chain includes at least one data pull synchronization task, and the scheduled synchronization task chain is stored in a task engine. The method further includes:
[0030] Receive a control signal from a task engine console, where the control signal is used to trigger the execution of any one or more target data pull synchronization tasks in the scheduled synchronization task chain of the gateway;
[0031] Based on the control signal, the timing synchronization task chain of the control gateway is controlled to trigger the target data pulling synchronization task.
[0032] In one embodiment, after the step of controlling the scheduled synchronization task chain of the gateway to trigger the target data pulling synchronization task based on the control signal, the method further includes:
[0033] After the target data pull synchronization task is completed, a downstream data pull synchronization task is executed, where the downstream data pull synchronization task is located after the target data pull synchronization task.
[0034] In addition, to achieve the above-mentioned purpose, the present application also proposes an API gateway data synchronization device based on policy patterns and task chains, the device comprising: a memory, a processor, and a computer program stored on the memory and executable on the processor, the computer program being configured to implement the steps of the API gateway data synchronization method based on policy patterns and task chains as described above.
[0035] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by the processor, the steps of the API gateway data synchronization method based on the policy pattern and task chain as described above are implemented.
[0036] The present application provides an API gateway data synchronization method based on a policy pattern and a task chain. When the scheduled synchronization task chain of the gateway triggers a data pull synchronization task, the type, version number and port address of the gateway are obtained. Based on the type and version number of the gateway, the configuration parameters in the data synchronization policy class are matched to determine the pull synchronization policy class corresponding to the gateway. Then, based on the pull synchronization policy class and the type, version number and port address of the gateway, the synchronization interface is called to pull data from the gateway to execute the data pull synchronization task. When the multi-gateway platform needs to execute data pull synchronization, the above method can dynamically match the pull synchronization policy class in the data synchronization policy class according to the type and version number of the gateway. When the gateway type or version in the multi-gateway platform changes, the multi-gateway platform can select different pull synchronization policy classes to adapt to the changes in the gateway, thereby improving the flexibility of gateway data synchronization. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0038] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0039] Figure 1 This is a flowchart of the first embodiment of the API gateway data synchronization method based on the strategy mode and task chain of this application;
[0040] Figure 2 This is a flowchart of the second embodiment of the API gateway data synchronization method based on the strategy mode and task chain of this application;
[0041] Figure 3 This is a flowchart of the third embodiment of the API gateway data synchronization method based on the strategy mode and task chain of this application;
[0042] Figure 4 This is a flowchart of the fourth embodiment of the API gateway data synchronization method based on the strategy mode and task chain of this application;
[0043] Figure 5 This is a flowchart of the fifth embodiment of the API gateway data synchronization method based on the strategy mode and task chain of this application;
[0044] Figure 6 This is a flowchart of a method for synchronizing data via an API gateway based on a policy pattern and a task chain according to an embodiment of the present application;
[0045] Figure 7 This is a schematic diagram of the device structure of the hardware operating environment involved in the API gateway data synchronization method based on the policy mode and task chain in the embodiment of the present application.
[0046] The purpose, features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0047] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not intended to limit the present application.
[0048] In order to better understand the technical solution of this application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0049] In a microservices architecture, the API gateway serves as a unified request entry point, handling various business-independent logic such as routing, load balancing, protocol conversion, and security protection. Each microservice, however, focuses on implementing its own business logic. To ensure stable operation and data consistency across the entire microservices architecture, data synchronization across multiple API gateways is required to uniformly manage and update information such as service lists, API lists, and related policies.
[0050] At present, API gateway data synchronization technology usually adopts a hard-coded method. For example, if a multi-gateway platform manages multiple API gateways, when the multi-gateway platform needs to synchronize the data of the API gateways it manages, it will pre-write the code in the data synchronization module and define the relevant data processing logic. When the multi-gateway platform needs to synchronize gateway data, it will first receive the data, and then perform data synchronization processing according to the pre-defined data processing logic. However, the above hard-coded synchronization method is difficult to adapt to the diverse needs of different gateway data, because different types of gateways may have different data formats and synchronization interfaces. The data processing logic defined in advance in the data synchronization module cannot meet the diverse needs of different gateways, and the flexibility of gateway data synchronization is poor.
[0051] In view of the above problems, the present application proposes an API gateway data synchronization method based on a policy pattern and a task chain. When the scheduled synchronization task chain of the gateway triggers the data pull synchronization task, the type, version number and port address of the gateway are obtained. Based on the type and version number of the gateway, the configuration parameters in the data synchronization policy class are matched to determine the pull synchronization policy class corresponding to the gateway. Then, based on the pull synchronization policy class and the type, version number and port address of the gateway, the synchronization interface is called to pull data from the gateway to execute the data pull synchronization task. When the multi-gateway platform needs to execute data pull synchronization, the above method can dynamically match the pull synchronization policy class in the data synchronization policy class according to the type and version number of the gateway. When the gateway type or version within the multi-gateway platform changes, the multi-gateway platform can select different pull synchronization policy classes to adapt to the changes in the gateway, thereby improving the flexibility of gateway data synchronization.
[0052] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program execution functions, or an electronic device capable of implementing the above functions. The following uses the multi-gateway platform as an example to illustrate this embodiment and the following embodiments.
[0053] Based on this, the first embodiment proposed in this application provides an API gateway data synchronization method based on strategy mode and task chain, referring to Figure 1 In this embodiment, the API gateway data synchronization method based on the policy pattern and task chain includes steps S10 to S30:
[0054] Step S10: When the scheduled synchronization task chain of the gateway triggers the data pull synchronization task, the type, version number and port address of the gateway are obtained.
[0055] It should be noted that the multi-gateway platform can manage and synchronize data from multiple API gateways of different manufacturers and versions. As a key component in the system architecture, the API gateway acts as an intermediary between the client and the back-end service, responsible for processing and routing client requests, and provides a series of functions to ensure that the client can call the back-end service safely and reliably. The multi-gateway platform is a tool for unified management and configuration of these gateways. When the multi-gateway platform adds a new managed gateway, the multi-gateway platform can automatically synchronize the configuration data of the newly added gateway. A scheduled synchronization task chain refers to an ordered collection of data pull synchronization tasks, which defines the pull synchronization tasks for different types of data in the gateway. The scheduled synchronization task chain automatically triggers data pull synchronization tasks according to preset time intervals or specific time points.
[0056] Each gateway managed in the multi-gateway platform corresponds to a scheduled synchronization task chain. When the scheduled synchronization task chain of any gateway triggers a data pull synchronization task, the multi-gateway platform will first obtain the type, version number and port address of the gateway. Among them, the type of gateway is a classification identifier of the gateway, which is divided according to the core technical architecture, deployment method, supported functional features, and compatible protocol standards adopted by the gateway. For example, the gateway based on the high-performance open source reverse proxy server NGINX, the "Apache APISIX" gateway developed based on the high-performance open source server Apache, and the "Spring Cloud Gateway" gateway designed for microservice architecture. The version number is an identifier for different versions of the same type of gateway, which is used to distinguish the status and differences of the gateway in terms of functions, performance, security, etc. at different time points, such as 1.20.0, 1.22.1, etc. of the "Apache APISIX" gateway.
[0057] Step S20 : Based on the type and version number of the gateway, the configuration parameters in the data synchronization policy class are matched to determine the pull synchronization policy class corresponding to the gateway.
[0058] The data synchronization policy class is a tool class in the multi-gateway platform that is used to load the implementation method corresponding to the data synchronization task when implementing the data synchronization task, such as the ServiceLoader class in JAVA, where the ServiceLoader class belongs to the Java service provider mechanism, which allows applications to dynamically discover and load service implementations. In this embodiment, the data synchronization policy class can select a suitable implementation method to perform data pull synchronization tasks based on the type and version number of the gateway. There are multiple data synchronization policy classes stored in the multi-gateway platform, and these data synchronization policy classes correspond one-to-one to gateways of different types and version numbers. The multi-gateway platform matches the configuration parameters of the data synchronization policy class based on the type and version number of the gateway to determine the pull synchronization policy class corresponding to the gateway.
[0059] Step S30: Based on the pull synchronization policy class and the type, version number and port address of the gateway, call the synchronization interface to pull data from the gateway to execute the data pull synchronization task.
[0060] Optionally, step S30 includes steps S31 to S33:
[0061] Step S31: read the pull implementation class list in the gateway adapter SDK through the pull synchronization strategy class.
[0062] It should be noted that the gateway adapter SDK (Software Development Kit) is designed by different gateway service providers to enable data interaction between the gateways they provide and multiple gateway platforms.
[0063] Optionally, the multi-gateway platform includes a preset first gateway adapter SDK and a second gateway adapter SDK written by the gateway service provider through the SPI (Service Provider Interface) protocol.
[0064] Specifically, the Multi-Gateway Platform includes a built-in set of standard first-tier gateway adapter SDKs. These are pre-designed and implemented for common gateway types and versions, allowing for direct use without the need for additional development. The Multi-Gateway Platform also provides the SPI protocol, allowing third-party gateway service providers to write their own gateway adapter SDKs for integration with the Multi-Gateway Platform. The SPI defines a set of interfaces or abstract classes for implementing specific services, allowing multiple different implementation classes to provide the same functionality.
[0065] For example, an SPI named "A.AbcDef" is defined in the multi-gateway platform. "A.AbcDef" defines the functions that the gateway service provider needs to implement, such as data pull synchronization. Then the gateway service provider can develop a gateway adapter SDK according to the SPI protocol, and write two pull implementation classes "A.AbcDeflmpl1" and "A.AbcDeflmpl2" in the gateway adapter SDK. These two pull implementation classes define two different data pull synchronization methods, which are used to implement data pull synchronization tasks for gateways of different types and versions. After the gateway service provider registers the gateway adapter SDK with the multi-gateway platform, all the pull implementation classes in the gateway adapter SDK will be included in the configuration file of the multi-gateway platform, namely the above-mentioned "A.AbcDeflmpl1" and "A.AbcDeflmpl2". The multi-gateway platform can read all pull implementation classes, that is, the pull implementation class list, from the configuration file through the pull synchronization policy class.
[0066] Step S32: The pull synchronization strategy class is matched with the pull implementation class list based on the type and version number of the gateway to determine the target pull implementation class.
[0067] It's important to note that different gateway types or versions may have different data formats, encryption methods, or communication protocols. Therefore, different gateway service providers may define different data communication methods based on gateway type and version. The implementation class list includes all pull implementation classes in the gateway adapter SDK, each corresponding to a specific gateway type and version. The pull synchronization strategy class, based on the gateway type and version, searches through all pull implementation classes in the gateway adapter SDK to find the one that matches the gateway currently triggering the data pull synchronization task.
[0068] Step S33: Based on the target pull implementation class and the port address of the gateway, call the synchronization interface to pull data from the gateway.
[0069] The port address of the gateway specifies which network port of the gateway the multi-gateway platform should obtain synchronization data from. During the data synchronization process, the multi-gateway platform uses this port address to call the synchronization interface to establish a connection with the gateway. The target pull implementation class contains all the logic required for synchronizing data, including how to build requests, how to handle responses, and how to parse returned data. The synchronization interface builds requests through the algorithm defined in the target pull implementation class and pulls data from the gateway through the gateway's port address. After receiving the request, the gateway will process it according to the content of the request and return the corresponding data. The synchronization interface of the multi-gateway platform will receive the returned data and use the parsing logic defined in the target pull implementation class to parse the data. The parsed data is stored in the specified location of the multi-gateway platform to complete the data synchronization task.
[0070] In this embodiment, the target pull implementation class can separate the implementation of the algorithm from the code that uses the algorithm. The specific implementation code of the algorithm is encapsulated in the target pull implementation class, and the data synchronization module in the multi-gateway platform only needs to write the code that uses the target pull implementation class. In this way, when the type and version of the gateway managed in the multi-platform changes, or the synchronization data type changes, it is only necessary to add a new data synchronization policy class to the configuration file of the multi-gateway platform, or change and replace the target pull implementation class, without changing the code of the data synchronization module inside the multi-gateway platform, thereby improving the flexibility of gateway data synchronization.
[0071] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above embodiment 1 can be referred to the above introduction and will not be described in detail later. Figure 2 Before step S10, the API gateway data synchronization method based on the strategy pattern and task chain further includes steps S40 to S50:
[0072] Step S40 , in response to the new gateway instruction input by the user, obtaining the type, version number and port address of the new gateway input by the user.
[0073] Step S50: Based on the type, version number and port address of the newly added gateway input by the user, a scheduled synchronization task chain of the newly added gateway is created according to preset rules, and the scheduled synchronization task chain of the newly added gateway is controlled to trigger a data pull synchronization task.
[0074] The Multi-Gateway Platform provides a user interface. When a user wishes to add a managed gateway to the platform, they can enter a new gateway command and enter the new gateway's Internet Protocol address, type, version number, port address, and communication protocol attributes. If the Multi-Gateway Platform detects the user-entered new gateway command through a pre-set detection mechanism, it will generate a corresponding scheduled synchronization task chain based on the type, version number, and port address of the new gateway entered by the user.
[0075] Optionally, you can pre-set the data pull synchronization task types and order for a scheduled synchronization task chain. For example, you can pre-set four data pull synchronization tasks and execute them in the pre-set order: "System data pull synchronization task -> Application data pull synchronization task -> API and policy data pull synchronization task -> Service and policy data pull synchronization task." When a scheduled synchronization task chain triggers a data pull synchronization task, data pull is executed sequentially in this pre-set order.
[0076] It should be noted that the trigger frequency of the scheduled synchronization task chain can be set according to actual business needs, for example, triggering a data pull synchronization task once a day or once a week. When a new gateway is added to the Multi-Gateway Platform and a corresponding scheduled synchronization task chain is created for the new gateway, a data pull synchronization task will be triggered immediately to pull data from the new gateway and synchronize it to the Multi-Gateway Platform.
[0077] Optionally, when a user edits the attribute parameters of a managed gateway, such as the port address, through the user interface of the multi-gateway platform, the current scheduled synchronization task chain of the gateway is deleted, a new scheduled synchronization task chain is recreated based on the edited gateway attribute parameters, and a data pull synchronization task is immediately triggered.
[0078] If a user deletes a managed gateway through the user interface of the Multi-Gateway Platform, the scheduled synchronization task chain of the gateway will be deleted, but the synchronized data in the Multi-Gateway Platform will be retained.
[0079] Based on the above embodiments of the present application, in the third embodiment of the present application, the same or similar contents as those in the above embodiments can be referred to the above introduction and will not be described in detail later. Figure 3 Before step S10, the API gateway data synchronization method based on the strategy pattern and task chain further includes steps S60 to S70:
[0080] Step S60, define the service provider interface, which includes a data pull interface and a data push interface, wherein the data pull interface is used to declare the synchronous data pull method that different gateway service providers need to implement, and the data push interface is used to declare the synchronous data push method that different gateway service providers need to implement.
[0081] The SPI provides a standardized access point for different gateway providers, ensuring they can interact with diverse gateway platforms in a unified manner. The data pull interface declares a series of synchronous data pull methods. These methods can be implemented by each gateway provider based on their own gateway characteristics. They define the specific logic for pulling data from the gateway, including constructing requests, sending requests, processing responses, and parsing data. The data push interface, on the other hand, declares synchronous data push methods.
[0082] Step S70, receiving the gateway adapter SDK sent by the gateway service provider based on the service provider interface, the gateway adapter SDK includes an implementation class, wherein the implementation class includes a pull implementation class and a push implementation class, the pull implementation class is used to implement the synchronous data pulling method, and the push implementation class is used to implement the synchronous data pushing method.
[0083] Through the SPI, the Multi-Gateway Platform receives gateway adapter SDKs from various gateway service providers. These SDKs contain implementation classes written by the service providers for different gateway types and versions, namely pull implementation classes and push implementation classes. These implementation classes encapsulate the code for pushing and pulling data. By loading and using these SDKs, the Multi-Gateway Platform can flexibly support multiple gateway types without hard-coding specific data synchronization logic for each gateway.
[0084] Optionally, in step S33, when the multi-gateway platform calls the synchronization interface to pull data from the gateway based on the target pull implementation class and the port address of the gateway, it first determines the synchronization interface corresponding to the gateway based on the port address of the gateway, and then pulls data from the gateway through the synchronization interface based on the synchronization data pulling method corresponding to the target pull implementation class.
[0085] When a gateway has more than one port address available for implementing data pull synchronization tasks, the gateway service provider can define the port address corresponding to the implementation class in the data pull implementation class. When the multi-gateway platform obtains the target pull implementation class, it calls the synchronization interface to connect to the port address specified in the target pull implementation class and execute the data pull synchronization task.
[0086] In this embodiment, by defining a standardized SPI, gateway service providers can implement data pull and push methods according to their own gateway characteristics, so that the multi-gateway platform can dynamically support data synchronization tasks of different gateways by loading SDK, thereby improving the flexibility of gateway data synchronization.
[0087] Based on the above embodiments of the present application, in the fourth embodiment of the present application, the same or similar contents as those in the above embodiments can be referred to the above introduction and will not be described in detail later. Figure 4 The API gateway data synchronization method based on the strategy pattern and task chain further includes steps S80 to S120:
[0088] Step S80: receiving the newly added configuration data of the gateway input by the user, and generating a real-time push synchronization task.
[0089] Users can enter new configuration data for a gateway through the Multi-Gateway Platform's user interface to update the configuration data for all managed gateways. Based on the new configuration data entered by the user, the Multi-Gateway Platform generates a real-time push task to push the new configuration data to all existing managed gateways.
[0090] Step S90 : Based on the type and version number of the gateway, the configuration parameters in the data synchronization policy class are matched to determine the push synchronization policy class corresponding to the real-time push synchronization task.
[0091] In this embodiment, the data synchronization policy class can select an appropriate implementation method to perform real-time push synchronization tasks based on the gateway type and version number. The multi-gateway platform stores multiple data synchronization policy classes, each corresponding to a gateway of different types and versions. The multi-gateway platform matches the gateway type and version number within the data synchronization policy class configuration parameters to determine the push synchronization policy class that corresponds to that gateway.
[0092] Step S100: Read the push implementation class list in the gateway adapter SDK through the push synchronization strategy class.
[0093] Step S110 : The push synchronization policy class is matched with the push implementation class list based on the type and version number of the gateway to determine a target push implementation class.
[0094] The multi-gateway platform can retrieve all push implementation classes (i.e., the push implementation class list) from the configuration file by pulling the synchronization strategy class. This list includes push implementation classes from all gateway adapter SDKs, each corresponding to a specific gateway type and version. Based on the gateway type and version number, the push synchronization strategy class searches through all push implementation classes in the gateway adapter SDKs to find the one that matches the gateway for the current real-time push synchronization task.
[0095] Step S120: Based on the synchronization data push method corresponding to the target push implementation class, the synchronization interface is called to push the newly added configuration data to the gateway to execute the real-time push synchronization task.
[0096] The multi-faceted gateway platform uses the synchronized data push method defined in the target push implementation class. This method contains all the logic required to push the newly added configuration data to the gateway, including constructing the request, setting authentication information, and sending the data. The multi-faceted gateway platform calls the synchronized data push method defined in the push implementation class, obtains the gateway's port address, connects to the port address through the synchronization interface, and pushes the newly added configuration data to the gateway. This process completes the real-time push synchronization task, ensuring that the gateway receives the latest configuration data and can update accordingly.
[0097] Based on the above embodiments of the present application, in the fifth embodiment of the present application, the same or similar contents as those in the above embodiments can be referred to the above introduction and will not be described in detail later. Figure 5 The scheduled synchronization task chain includes at least one data pull synchronization task, and the scheduled synchronization task chain is stored in the task engine. The API gateway data synchronization method based on the strategy pattern and task chain also includes steps S130 to S140:
[0098] Step S130: receiving a control signal from a task engine console, wherein the control signal is used to trigger the execution of any one or more target data pulling synchronization tasks in the scheduled synchronization task chain of the gateway.
[0099] Step S140: Based on the control signal, the scheduled synchronization task chain of the control gateway is controlled to trigger the target data pulling synchronization task.
[0100] It should be noted that the Task Engine Console is a user interface or management tool that allows users to monitor, manage, and trigger data pull synchronization tasks in a scheduled synchronization task chain. The Task Engine Console provides an intuitive interface for user interaction with the Task Engine. Control signals are signals entered by users through the Task Engine Console to indicate which data pull synchronization task should be executed. These signals include specific information about the target data pull synchronization task, such as a task identifier or other unique identifier.
[0101] Optionally, the scheduled synchronization task chain is saved in the xxl-job task engine, where xxl-job is a distributed task scheduling framework that provides powerful distributed task scheduling capabilities, can realize the distribution and execution of tasks in the cluster, and provides visual management, monitoring and task execution logs.
[0102] Optionally, after the target data pull synchronization task is completed, the downstream data pull synchronization task is executed, and the downstream data pull synchronization task is located after the target data pull synchronization task.
[0103] The data pull synchronization tasks in the scheduled synchronization task chain are arranged in a specific order. After the target data pull synchronization task is completed, if there are downstream data pull synchronization tasks after the scheduled synchronization task chain, these downstream data pull synchronization tasks will be automatically executed in the order defined in the scheduled synchronization task chain.
[0104] Optionally, when an exception occurs during the execution of a data pull synchronization task in the scheduled synchronization task chain, the user can manually trigger the restart of one or more data pull synchronization tasks in the scheduled synchronization task chain in the task engine console to ensure the continuity and stability of data synchronization.
[0105] In this embodiment, through the task engine console, users can intuitively monitor and manage each task in the scheduled synchronization task chain and manually trigger the execution of any target data pull synchronization task as needed. This manual triggering mechanism allows the multi-faceted gateway platform to quickly respond to abnormal situations or the need to prioritize specific tasks during the data synchronization process, promptly starting or restarting related tasks to ensure the continuity and stability of data synchronization.
[0106] For example, in order to help understand the implementation process of the API gateway data synchronization method based on the strategy pattern and task chain obtained by combining this embodiment with the above embodiments, please refer to Figure 6 , Figure 6 This article provides a brief flowchart of the API gateway data synchronization method based on the strategy pattern and task chain. Specifically:
[0107] Multiple gateways are managed in the multi-gateway platform, including the gateway type, gateway version, communication protocol, domain name address and authentication parameters of each gateway. When the multi-gateway platform adds a new gateway or edits an existing managed gateway, it can generate a scheduled synchronization task chain. The scheduled synchronization task chain includes system data pull synchronization tasks, application data pull synchronization tasks, application programming interface and policy data pull synchronization tasks, and service and policy data pull synchronization tasks. These pull synchronization tasks are managed by the task engine. The task engine supports scheduled calls to the scheduled synchronization task chain to execute data pull synchronization tasks, and also supports manual selection of target data pull synchronization tasks for execution. At the same time, when the service management module and the application programming interface management module modify and edit the service policy configuration data and the application programming interface policy configuration data, they can generate real-time push synchronization tasks to execute the push and distribution of the gateway's services and related policy update configuration data. For example, if Figure 6 As shown, the multi-gateway platform is configured with two data synchronization policy classes: "Gateway A V1.3.2 Data Synchronization Policy Class" and "Gateway B V1.2.2 Data Synchronization Policy Class." It also includes three gateway adapter SDKs: "Software Development Kit 1," "Software Development Kit 2," and "Software Development Kit 3." The data synchronization policy class retrieves the corresponding target data synchronization policy class based on the gateway type and version number. The target data synchronization policy class then searches for the corresponding implementation class in the gateway adapter based on the gateway type and version number, executing synchronization tasks according to the data synchronization methods defined in the implementation class. The service provider interface includes a data pull interface and a data push interface. Gateway service providers can integrate their own gateway adapter SDKs with the multi-gateway platform using the SPI protocol to implement gateway management.
[0108] It should be noted that the above examples are only used to understand this application and do not constitute a limitation on the API gateway data synchronization method based on strategy mode and task chain of this application. More forms of simple transformations based on this technical concept are all within the scope of protection of this application.
[0109] The present application provides an API gateway data synchronization device based on a policy pattern and a task chain. The API gateway data synchronization device based on a policy pattern and a task chain includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the API gateway data synchronization method based on the policy pattern and the task chain in the above-mentioned embodiment one.
[0110] Reference below Figure 7, which shows a schematic diagram of the structure of an API gateway data synchronization device based on a policy pattern and task chain suitable for implementing an embodiment of the present application. The API gateway data synchronization device based on a policy pattern and task chain in the embodiment of the present application can include, but is not limited to, mobile terminals such as laptop computers (PADs) and fixed terminals such as desktop computers. Figure 7 The API gateway data synchronization device based on the policy pattern and task chain shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0111] like Figure 7 As shown, the API gateway data synchronization device based on the policy pattern and task chain may include a processing device 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes based on programs stored in a read-only memory (ROM) 1002 or programs loaded from a storage device 1003 into a random access memory (RAM) 1004. The random access memory 1004 also stores various programs and data required for the operation of the API gateway data synchronization device based on the policy pattern and task chain. The processing device 1001, the read-only memory 1002, and the random access memory 1004 are connected to each other via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, a touch screen, touchpad, keyboard, mouse, image sensor, microphone, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 1003 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 1009. The communication device 1009 can allow the API gateway data synchronization device based on the policy pattern and task chain to communicate wirelessly or wired with other devices to exchange data. Although the figure shows an API gateway data synchronization device based on the policy pattern and task chain with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have instead.
[0112] In particular, according to the embodiments disclosed in the present application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in the present application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program comprising program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via a communication device, or installed from a storage device 1003, or installed from a read-only memory 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are performed.
[0113] The API gateway data synchronization device based on policy pattern and task chain provided by this application adopts the API gateway data synchronization method based on policy pattern and task chain in the above embodiment, which can solve the technical problem of poor flexibility of gateway data synchronization. Compared with the prior art, the beneficial effects of the API gateway data synchronization device based on policy pattern and task chain provided by this application are the same as the beneficial effects of the API gateway data synchronization method based on policy pattern and task chain provided by the above embodiment, and the other technical features of the API gateway data synchronization device based on policy pattern and task chain are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0114] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0115] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.
[0116] The present application provides a computer-readable storage medium having computer-readable program instructions (i.e., computer programs) stored thereon, and the computer-readable program instructions are used to execute the API gateway data synchronization method based on the policy pattern and task chain in the above-mentioned embodiment.
[0117] The computer-readable storage medium provided herein may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems, or devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory, read-only memory, erasable programmable read-only memory (EPROM or flash memory), optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including, but not limited to, wires, optical cables, radio frequency (RF), etc., or any suitable combination thereof.
[0118] The above-mentioned computer-readable storage medium can be included in the API gateway data synchronization device based on the policy mode and task chain; or it can exist independently without being assembled into the API gateway data synchronization device based on the policy mode and task chain.
[0119] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by the API gateway data synchronization device based on the policy pattern and task chain, the API gateway data synchronization device based on the policy pattern and task chain can be written in one or more programming languages or a combination thereof to write computer program codes for performing the operations of the present application. The above-mentioned programming languages include object-oriented programming languages such as Java, Smalltalk, C++, and also conventional procedural programming languages such as "C" language or similar programming languages. The program code can be executed entirely on the user computer, partially on the user computer, or as an independent software package, partially on the user computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer can be connected to the user computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, using an Internet service provider to connect through the Internet).
[0120] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, program segment or part of code, and the module, program segment or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, as well as the combination of boxes in the block diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or can be implemented using a combination of dedicated hardware and computer instructions.
[0121] The modules described in the embodiments of the present application may be implemented in software or hardware, wherein the name of a module does not necessarily limit the unit itself.
[0122] The computer-readable storage medium provided in this application stores computer-readable program instructions (i.e., a computer program) for executing the aforementioned API gateway data synchronization method based on a policy pattern and task chaining. This computer-readable storage medium can address the technical issue of insufficient flexibility in gateway data synchronization. Compared to the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the API gateway data synchronization method based on a policy pattern and task chaining provided in the aforementioned embodiments, and are not further elaborated here.
[0123] The above description is only part of the embodiments of the present application and does not limit the patent scope of the present application. All equivalent structural transformations made by using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect application in other related technical fields are included in the patent protection scope of the present application.
Claims
1. An API gateway data synchronization method based on strategy mode and task chain, characterized in that: The method comprises: When the scheduled synchronization task chain of the gateway triggers the data pull synchronization task, the type, version number and port address of the gateway are obtained; Based on the type and version number of the gateway, the configuration parameters in the data synchronization strategy class are matched to determine the pull synchronization strategy class corresponding to the gateway. The data synchronization strategy class is a tool class used to load the implementation method corresponding to the data synchronization task, and corresponds one-to-one with gateways of different types and versions. The gateway type is a classification identifier of the gateway, which is divided according to the core technology architecture, deployment method, supported functional features and compatible protocol standards adopted by the gateway; The pull implementation class list in the gateway adapter SDK is read through the pull synchronization strategy class. Different data pull synchronization methods are defined in the pull implementation class to implement data pull synchronization tasks for gateways of different types and versions; The pull synchronization strategy class matches the pull implementation class list based on the type and version number of the gateway to determine the target pull implementation class. The target pull implementation class contains all the logic required for synchronizing data, including how to construct requests, how to process responses, and how to parse returned data. Based on the target pull implementation class and the port address of the gateway, the synchronization interface is called to pull data from the gateway, including: the synchronization interface constructs a request through the algorithm defined in the target pull implementation class; after the gateway receives the request, it processes it according to the content of the request and returns the corresponding data; the synchronization interface of the multi-gateway platform receives the returned data and uses the parsing logic defined in the target pull implementation class to parse the data; the parsed data is stored in the specified location of the multi-gateway platform to complete the data synchronization task.
2. The API gateway data synchronization method based on strategy pattern and task chain according to claim 1, characterized in that: When the scheduled synchronization task chain of the gateway triggers the data pulling synchronization task on a regular basis, before the step of obtaining the type, version number and port address of the gateway, the method further includes: In response to a new gateway instruction input by a user, obtaining the type, version number, and port address of the new gateway input by the user; Based on the type, version number and port address of the newly added gateway input by the user, a scheduled synchronization task chain of the newly added gateway is created according to preset rules, and the scheduled synchronization task chain of the newly added gateway is controlled to trigger the data pull synchronization task.
3. The API gateway data synchronization method based on strategy pattern and task chain according to claim 1, characterized in that: When the scheduled synchronization task chain of the gateway triggers the data pulling synchronization task on a regular basis, before the step of obtaining the type, version number and port address of the gateway, the method further includes: Define a service provider interface, which includes a data pull interface and a data push interface. The data pull interface is used to declare the synchronous data pull method that different gateway service providers need to implement, and the data push interface is used to declare the synchronous data push method that different gateway service providers need to implement. The gateway adapter SDK sent by the receiving gateway service provider based on the service provider interface includes an implementation class, wherein the implementation class includes a pull implementation class and a push implementation class. The pull implementation class is used to implement the synchronous data pulling method, and the push implementation class is used to implement the synchronous data pushing method.
4. The API gateway data synchronization method based on strategy pattern and task chain according to claim 3 is characterized in that: The step of calling a synchronous interface to pull data from the gateway based on the target pull implementation class and the port address of the gateway includes: Determining a synchronization interface corresponding to the gateway based on the port address of the gateway; Based on the synchronous data pulling method corresponding to the target pull implementation class, data is pulled from the gateway through the synchronous interface.
5. The API gateway data synchronization method based on strategy pattern and task chain according to claim 3 is characterized in that: The method further comprises: Receive new configuration data of the gateway input by the user and generate a real-time push synchronization task; Based on the type and version number of the gateway, the configuration parameters in the data synchronization policy class are matched to determine the push synchronization policy class corresponding to the real-time push synchronization task; Read the push implementation class list in the gateway adapter SDK through the push synchronization strategy class; The push synchronization strategy class is matched with the push implementation class list based on the type and version number of the gateway to determine the target push implementation class; Based on the synchronous data push method corresponding to the target push implementation class, the synchronization interface is called to push the newly added configuration data to the gateway to execute the real-time push synchronization task.
6. The API gateway data synchronization method based on strategy pattern and task chain according to claim 1, characterized in that: The scheduled synchronization task chain includes at least one data pull synchronization task, and the scheduled synchronization task chain is stored in a task engine. The method further includes: Receive a control signal from a task engine console, where the control signal is used to trigger the execution of any one or more target data pull synchronization tasks in the scheduled synchronization task chain of the gateway; Based on the control signal, the timing synchronization task chain of the control gateway is controlled to trigger the target data pulling synchronization task.
7. The API gateway data synchronization method based on strategy pattern and task chain according to claim 6, characterized in that: After the step of controlling the gateway's scheduled synchronization task chain to trigger the target data pulling synchronization task based on the control signal, the method further includes: After the target data pull synchronization task is completed, a downstream data pull synchronization task is executed, where the downstream data pull synchronization task is located after the target data pull synchronization task.
8. An API gateway data synchronization device based on strategy mode and task chain, characterized in that: The device comprises: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the API gateway data synchronization method based on a policy pattern and a task chain as described in any one of claims 1 to 7.
9. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by the processor, the steps of the API gateway data synchronization method based on the policy pattern and task chain as described in any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Data transmission method and device, electronic equipment and storage medium
CN116095077A