Gateway configuration method, device and system
The gateway configuration system addresses reliability issues by loading configuration data from a center, using local files and event bus monitoring, ensuring real-time updates and maintainability, even in middleware failures.
Patent Information
- Application Number
- CN202311069889.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-23
- Publication Date
- 2024-12-13
- Estimated Expiration
- 2043-08-23
AI Technical Summary
Existing gateway configuration systems rely on monitoring middleware like nacos or zookeeper for dynamic updates, leading to poor reliability when these middleware fail.
A gateway configuration method and system that loads configuration data from a configuration center, constructs objects based on this data, and updates the cache, with fallbacks and retries to ensure reliability, including local configuration files and event bus monitoring for dynamic updates.
Improves reliability by allowing real-time configuration data updates without relying on monitoring middleware, ensuring gateway functionality even in middleware failures, and enhancing maintainability and scalability.
Smart Images

Figure CN117041044B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of network technology, and in particular to a gateway configuration method, device and system. Background Art
[0002] As a channel for operators, digital content providers and network equipment manufacturers to provide network services, the gateway can provide multiple network applications and services such as bandwidth data, voice, video, network security, energy management, and health monitoring.
[0003] In traditional technology, the configuration data of the gateway is stored in the database, and the dynamic update of the database depends on the monitoring mechanism of middleware such as nacos or zookeeper. When adding a corresponding table in the database to store configuration data, the corresponding record is published to the configuration center of nacos or zookeeper node through the database update operation, and the gateway engine monitors nacos or zookeeper to realize the dynamic update of configuration data.
[0004] However, in the above method, if the monitoring middleware fails, the configuration data cannot be dynamically updated, and the reliability is poor. Summary of the invention
[0005] Based on this, it is necessary to provide a gateway configuration method, device and system that can improve reliability in response to the above technical problems.
[0006] In a first aspect, the present application provides a gateway configuration method, which is applied to a gateway engine, and the method includes:
[0007] Loading first configuration data by calling an interface of a first configuration center, wherein the first configuration center represents a configuration center matching a first configuration mode, and the first configuration mode represents a configuration mode used by the gateway engine;
[0008] In the case where the first configuration data is successfully loaded, constructing a first configuration object based on the first configuration data, and placing the first configuration object into a cache management queue for processing;
[0009] In the process of processing the cache management queue, when the first configuration object is obtained from the cache management queue, the first configuration data is updated to the cache of the gateway to configure the gateway.
[0010] In a possible implementation, the method further includes:
[0011] Determine if a local configuration file exists;
[0012] If the local configuration file exists, load the second configuration data from the local configuration file;
[0013] When the second configuration data is successfully loaded, a second configuration object is constructed based on the second configuration data, and the second configuration object is put into the cache management queue for processing.
[0014] In a possible implementation, the loading of the first configuration data by calling an interface of the first configuration center includes:
[0015] In the case where the local configuration file does not exist, loading the first configuration data by calling an interface of the first configuration center;
[0016] or,
[0017] In the case that the local configuration file exists but the second configuration data is not loaded successfully, the first configuration data is loaded by calling an interface of the first configuration center.
[0018] In a possible implementation, the method further includes:
[0019] In the case where the first configuration data is not loaded successfully, a first failure event is constructed based on the first configuration data, and the first failure event is added to a delay queue for processing.
[0020] In a possible implementation, the method further includes:
[0021] When the time length of the first failure event entering the delay queue is greater than a first threshold, obtaining the first failure event from the delay queue;
[0022] When the number of retries of the first failure event is less than a second threshold, reloading the first configuration data from the first configuration center according to the configuration class of the first failure event, where the configuration class is used to indicate a type of a configuration model adopted by the first configuration data;
[0023] If the reloading is successful, constructing the first configuration object based on the first configuration data, and putting the first configuration object into the cache management queue for processing;
[0024] If the reloading fails, the number of retries of the first failure event is increased by one and the event is added to the delay queue for processing.
[0025] In a possible implementation, placing the first configuration object into a cache management queue for processing includes:
[0026] Determine whether there is a third configuration object in the cache management queue, the third configuration object is used to represent a configuration object with the same configuration center and configuration class as those corresponding to the first configuration object, the configuration class is used to indicate a type of a configuration model, and the configuration model is used to indicate a storage format of configuration data;
[0027] If the third configuration object exists and the version number of the first configuration object is greater than the version number of the third configuration object, putting the first configuration object into the cache queue for processing;
[0028] or,
[0029] If the third configuration object does not exist, the first configuration object is placed in the cache queue for processing.
[0030] In a possible implementation, the method further includes:
[0031] If the first configuration data is not successfully updated to the cache and the number of retries of the first configuration object is less than a third threshold, the number of retries of the first configuration object is increased by one and the first configuration object is put back into the cache management queue for processing.
[0032] In a possible implementation, the method further includes:
[0033] Initialize the first configuration center, and add a configuration change listener to each configuration class of the first configuration center, where the configuration class is used to indicate a type of a configuration model, and the configuration model is used to indicate a storage format of configuration data;
[0034] Subscribe to the event bus;
[0035] When a fourth configuration object is received from the event bus, the fourth configuration object is placed in the cache management queue for processing, the fourth configuration object is published to the event bus by the configuration change listener, and the fourth configuration object is generated based on the updated configuration data in the first configuration center.
[0036] In a second aspect, the present application also provides a gateway configuration device. The device is applied to a gateway engine. The device includes:
[0037] A loading module, configured to load first configuration data by calling an interface of a first configuration center, wherein the first configuration center represents a configuration center matching a first configuration mode, and the first configuration mode represents a configuration mode used by the gateway engine;
[0038] A construction module, configured to construct a first configuration object based on the first configuration data when the first configuration data is successfully loaded, and put the first configuration object into a cache management queue for processing;
[0039] An updating module is used to update the first configuration data into the cache of the gateway when the first configuration object is obtained from the cache management queue during processing of the cache management queue, so as to configure the gateway.
[0040] In a possible implementation manner, the device further includes:
[0041] A determination module, used to determine whether a local configuration file exists;
[0042] The loading module is also used to load the second configuration data from the local configuration file when the local configuration file exists; when the second configuration data is successfully loaded, construct a second configuration object based on the second configuration data, and put the second configuration object into the cache management queue for processing.
[0043] In a possible implementation, the loading module is further used for:
[0044] In the case where the local configuration file does not exist, loading the first configuration data by calling an interface of the first configuration center;
[0045] or,
[0046] In the case that the local configuration file exists but the second configuration data is not loaded successfully, the first configuration data is loaded by calling an interface of the first configuration center.
[0047] In a possible implementation, the building block is further used to:
[0048] In the case where the first configuration data is not loaded successfully, a first failure event is constructed based on the first configuration data, and the first failure event is added to a delay queue for processing.
[0049] In a possible implementation, the device further includes: an acquisition module and a first adding module;
[0050] The acquisition module is configured to acquire the first failure event from the delay queue when the time length of the first failure event entering the delay queue is greater than a first threshold;
[0051] The loading module is further configured to reload the first configuration data from the first configuration center according to the configuration class of the first failure event when the number of retries of the first failure event is less than a second threshold, wherein the configuration class is used to indicate a type of a configuration model adopted by the first configuration data;
[0052] The construction module is further configured to construct the first configuration object based on the first configuration data if the reloading is successful, and put the first configuration object into the cache management queue for processing;
[0053] The first adding module is used to increase the number of retries of the first failure event by one and add the event to the delay queue for processing if the reloading fails.
[0054] In a possible implementation, placing the first configuration object into a cache management queue for processing includes:
[0055] Determine whether there is a third configuration object in the cache management queue, the third configuration object is used to represent a configuration object with the same configuration center and configuration class as those corresponding to the first configuration object, the configuration class is used to indicate a type of a configuration model, and the configuration model is used to indicate a storage format of configuration data;
[0056] If the third configuration object exists and the version number of the first configuration object is greater than the version number of the third configuration object, putting the first configuration object into the cache queue for processing;
[0057] or,
[0058] If the third configuration object does not exist, the first configuration object is placed in the cache queue for processing.
[0059] In a possible implementation, the device further includes: a second adding module;
[0060] The second adding module also has a function of increasing the retry count of the first configuration object by one and re-putting it into the cache management queue for processing if the first configuration data is not successfully updated to the cache and the retry count of the first configuration object is less than a third threshold.
[0061] In a possible implementation manner, the device further includes:
[0062] an initialization module, used to initialize the first configuration center, and add a configuration change listener to each configuration class of the first configuration center, wherein the configuration class is used to indicate a type of a configuration model, and the configuration model is used to indicate a storage format of configuration data;
[0063] Subscription module, used to subscribe to the event bus;
[0064] The third adding module is used to put the fourth configuration object into the cache management queue for processing when a fourth configuration object is received from the event bus, the fourth configuration object is published to the event bus by the configuration change listener, and the fourth configuration object is generated according to the configuration data updated in the first configuration center.
[0065] In a third aspect, the present application also provides a gateway configuration system, the system comprising a gateway management and control terminal, a configuration center and a gateway engine;
[0066] The gateway control terminal is used to receive control data, the control data is used to configure the gateway, the control data includes data required to configure the gateway and the corresponding configuration mode; assemble the control data into configuration data according to the configuration model, the configuration model is used to indicate the storage format of the configuration data; associate the configuration data, configuration class and version number and store them in the configuration center corresponding to the configuration mode, the configuration class is used to indicate the type of the configuration model;
[0067] The configuration center is used to associate and store configuration data, configuration classes and version numbers, and each configuration center corresponds to a unique configuration mode;
[0068] The gateway engine is used to execute the gateway configuration method of the above-mentioned first aspect or any possible implementation manner of the first aspect.
[0069] In a fourth aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0070] Loading first configuration data by calling an interface of a first configuration center, wherein the first configuration center represents a configuration center matching a first configuration mode, and the first configuration mode represents a configuration mode used by the gateway engine;
[0071] In the case where the first configuration data is successfully loaded, constructing a first configuration object based on the first configuration data, and placing the first configuration object into a cache management queue for processing;
[0072] In the process of processing the cache management queue, when the first configuration object is obtained from the cache management queue, the first configuration data is updated into the cache.
[0073] In a fifth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0074] Loading first configuration data by calling an interface of a first configuration center, wherein the first configuration center represents a configuration center matching a first configuration mode, and the first configuration mode represents a configuration mode used by the gateway engine;
[0075] In the case where the first configuration data is successfully loaded, constructing a first configuration object based on the first configuration data, and placing the first configuration object into a cache management queue for processing;
[0076] In the process of processing the cache management queue, when the first configuration object is obtained from the cache management queue, the first configuration data is updated into the cache.
[0077] In a sixth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0078] Loading first configuration data by calling an interface of a first configuration center, wherein the first configuration center represents a configuration center matching a first configuration mode, and the first configuration mode represents a configuration mode used by the gateway engine;
[0079] In the case where the first configuration data is successfully loaded, constructing a first configuration object based on the first configuration data, and placing the first configuration object into a cache management queue for processing;
[0080] In the process of processing the cache management queue, when the first configuration object is obtained from the cache management queue, the first configuration data is updated into the cache.
[0081] In the above-mentioned gateway configuration method, device and system, configuration data is stored in a configuration center of different configuration modes. The configuration center has high reliability. The gateway engine can load configuration data from the configuration center through the corresponding interface according to the configuration mode used, and update the configuration data to the cache, thereby obtaining configuration data that meets the gateway business needs in real time without the need for monitoring middleware, thereby improving reliability. BRIEF DESCRIPTION OF THE DRAWINGS
[0082] Figure 1 A schematic diagram of the architecture of a gateway configuration system provided in an embodiment of the present application;
[0083] Figure 2 An exemplary schematic diagram of a configuration center provided in an embodiment of the present application;
[0084] Figure 3 An interactive schematic diagram of a gateway configuration method provided in an embodiment of the present application;
[0085] Figure 4A schematic diagram of a flow chart of a gateway configuration method provided in an embodiment of the present application;
[0086] Figure 5 A schematic diagram of a flow chart of a gateway configuration method provided in an embodiment of the present application;
[0087] Figure 6 A schematic diagram of a flow chart of a gateway configuration method provided in an embodiment of the present application;
[0088] Figure 7 A schematic diagram of a flow chart of a gateway configuration method provided in an embodiment of the present application;
[0089] Figure 8 A schematic diagram of a flow chart of a gateway configuration method provided in an embodiment of the present application;
[0090] Fig. 9 A structural block diagram of a configuration device provided in an embodiment of the present application;
[0091] Fig.10 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0092] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0093] Figure 1 This is a schematic diagram of the architecture of the gateway configuration system provided in the embodiment of the present application. Figure 1 As shown, the gateway configuration system includes a gateway management and control terminal, a configuration center, and a gateway engine. Among them, the configuration center can be used to store configuration data, and the gateway management and control terminal can store configuration data to the configuration center. The gateway engine can load configuration data from the configuration center for use.
[0094] like Figure 1 As shown, the terminal can communicate with the gateway control terminal through the network. The user can send control data to the gateway control terminal through the terminal. The control data can be used to configure the gateway, and the control data may include data required to configure the gateway and the corresponding configuration mode. Among them, the terminal can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, Internet of Things devices, etc.
[0095] The gateway control end can be used to receive control data, assemble the control data into configuration data according to the configuration model, and associate the configuration data, configuration class and version number to store in the configuration center corresponding to the configuration model. The gateway control end can be implemented with an independent server or a server cluster composed of multiple servers.
[0096] Among them, the configuration model can be used to indicate the storage format of the configuration data. In an embodiment of the present application, a configuration model can be predefined. In one example, the configuration model may include one or more of a communication container, an application programming interface (API), application information, current limiting, fuse, retry, black and white list, and baffle. There may be multiple predefined configuration models. The fields included in these configuration models may be different. Each configuration model is assigned a configuration class, and the configuration class can be used to identify a unique configuration model. In other words, a configuration model can be determined based on a configuration class. These configuration models uniformly implement the Gateway Base Configuration (GatewayBaseConfig) interface, which defines the above-mentioned configuration class.
[0097] The configuration center can be used to associate and store configuration data, configuration classes, and version numbers, and each configuration center corresponds to a unique configuration mode. The gateway control end can connect to multiple configuration centers. Different configuration centers correspond to different configuration modes. For example, configuration centers can include Apollo Configuration Center (Apoll Config Repository), Nacos Configuration Center (Nacos Config Repository), and File System Configuration Center (File System Config Repository). The user will specify the configuration mode in the control data. After the gateway control end receives the control data, on the one hand, it can assemble the data carried in the control data according to the configuration model to obtain the configuration data, and on the other hand, it can obtain the configuration mode from the control data, so that the configuration data can be stored in the configuration center corresponding to the configuration mode.
[0098] In order to facilitate the use of configuration data, the configuration class corresponding to the configuration data will also be associated when the configuration data is stored. In order to achieve version management, record changes between versions or roll back to historical versions, the version number will also be associated when the configuration data is stored. In one example, the timestamp of generating the configuration data can be used as the version number corresponding to the configuration data. In this way, the configuration data, configuration class and version number are associated and stored in the configuration center corresponding to the configuration mode.
[0099] In the embodiment of the present application, the configuration data is centrally managed through the configuration center, and the configuration data is managed and updated through the gateway management and control end, thereby improving the maintainability and scalability of the configuration data.
[0100] Figure 2 This is an exemplary schematic diagram of the configuration center provided in the embodiment of the present application. Figure 2As shown, first, define the configuration center interface. Then, integrate the Apollo configuration center interface, the Nacos configuration center interface, and the file system configuration center interface in the configuration center interface in the form of a plug-in. Of course, the above integrated configuration center interface is only an exemplary description, and the configuration center interface of other configuration modes can also be integrated. Next, define the configuration center loader. The plug-in defined above is loaded by the configuration center loader, and the implementation method of the plug-in can be a service provider interface (Service Provider Interface, SPI) or automatic assembly (springboot). After that, the configuration center loader registers the loaded configuration center in the configuration center registry. It can be seen that the configuration center registry can indicate all loaded configuration centers. In one example, the configuration center registry can include the interface and configuration mode of the loaded configuration center. In this way, after determining the configuration mode corresponding to the configuration data, the gateway management and control end can find the interface corresponding to the configuration mode from the configuration center registry, so that the configuration data, configuration class and version number are associated and stored in the configuration center through the found interface.
[0101] In one possible implementation, Figure 1 As shown, the gateway configuration system may further include a database. The gateway management and control end is further used to associate and store the configuration data, configuration class, version number and configuration mode in the database.
[0102] In the embodiment of the present application, by storing configuration data, configuration classes, version numbers and configuration mode associations in a database, configuration data can be backed up, thereby improving reliability.
[0103] Optionally, the database may also record the status information of the control data. When the configuration data corresponding to the control data is successfully stored in the corresponding configuration center, the gateway control end may modify the status information of the control data in the database to published. In this way, the manageability of the configuration data can be improved and it is also convenient for users to search.
[0104] Figure 3 This is an interactive diagram of the gateway configuration method provided in the embodiment of the present application. The method can be applied to Figure 1 The gateway configuration system is shown in Figure 1. Figure 3 As shown, the method may include:
[0105] Step S301: The terminal sends control data to the gateway control terminal.
[0106] Step S302: the gateway management and control terminal receives management and control data.
[0107] Step S303: The gateway management and control end assembles the management and control data into configuration data according to the configuration model.
[0108] In step S304, the gateway management and control end associates and stores the configuration data, configuration class, version number and configuration mode in a database.
[0109] Step S305: The gateway management and control end associates and stores the configuration data, configuration class and version number in a configuration center corresponding to the configuration mode.
[0110] Step S306: The gateway management and control end modifies the status information of the management and control data in the database to published.
[0111] In step S307, the gateway management and control end determines whether the configuration center is successfully stored in the corresponding configuration center; if so, execute step S308, otherwise execute step S309.
[0112] Step S308: The gateway management and control end returns a prompt message to the terminal indicating that the publishing is successful.
[0113] Step S309: The gateway management and control end returns a prompt message to the terminal indicating that the publishing has failed.
[0114] After receiving the prompt message indicating the failure of publishing, the terminal can publish the management and control data again until the number of retransmissions exceeds a certain threshold, and then notify the user.
[0115] In the embodiment of the present application, the configuration data is stored in the configuration center through the gateway control end, which realizes the unified management of the configuration data, avoids the decentralized storage and management, and improves the maintainability and scalability of the configuration data. At the same time, the configuration center has its own high availability mechanism, such as the Nacos configuration center supports the registration, discovery and state synchronization of distributed nodes, which ensures the high availability and reliability of the configuration center. In addition, the configuration center can be increased or decreased according to business needs, further improving the scalability. In addition, the version number is stored in association with the storage of configuration data, which reflects the changes between historical versions and is conducive to version management and version rollback.
[0116] The storage of configuration data in the configuration center has been completed. The following is an explanation of the process of the gateway engine reading configuration data from the configuration center. Figure 4 The flowchart of the gateway configuration method provided in the embodiment of the present application is shown in FIG. Figure 4 As shown, this method is applied to Figure 1 Taking the gateway engine shown in FIG. 1 as an example, the gateway configuration method may include:
[0117] Step S401: load first configuration data by calling an interface of a first configuration center.
[0118] The first configuration data may represent configuration data loaded by calling an interface of a first configuration center. The first configuration center may represent a configuration center that matches a first configuration mode. The first configuration mode may represent a configuration mode used by the gateway engine.
[0119] The gateway engine is set to different configuration modes for use according to application requirements. The gateway engine can find the interface of the first configuration center in the configuration center registry according to the currently used configuration mode, and then load the first configuration data by calling the interface of the first configuration center.
[0120] Step S402: when the first configuration data is successfully loaded, construct a first configuration object based on the first configuration data, and put the first configuration object into a cache management queue for processing.
[0121] Among them, the first configuration object can represent a configuration object (event) generated based on the first configuration object. The cache management queue can be used to update the cache of the gateway. The cache management queue can include multiple configuration objects. The first configuration object can be placed in the cache management queue for storage. The process of the gateway engine placing the first configuration object in the cache management queue will be described in detail later, and will not be repeated here.
[0122] Step S403: in the process of processing the cache management queue, when the first configuration object is obtained from the cache management queue, the first configuration data is updated to the cache of the gateway to configure the gateway.
[0123] The cache management queue may include multiple configuration objects. The gateway engine can sequentially obtain configuration objects from the cache management queue for processing. In one example, the gateway engine can sequentially obtain configuration objects from the cache management queue in the order of entering the cache management queue from first to last for processing. Of course, the gateway engine can also obtain configuration objects from the cache management queue for processing in other orders, which is not limited in the embodiments of the present application.
[0124] In the process of processing the cache management queue, when the first configuration object is obtained, the gateway engine can update the first configuration data to the cache. The gateway engine updates the first configuration data to the cache, which means that the gateway engine completes the configuration of the first configuration data. The process of the gateway engine updating the first configuration data to the cache will be described in detail later, and will not be repeated here.
[0125] In an embodiment of the present application, configuration data is stored in a configuration center of different configuration modes. The configuration center has high reliability. The gateway engine can load configuration data from the configuration center through the corresponding interface according to the configuration mode used, and update the configuration data to the cache, thereby obtaining configuration data that meets the gateway business needs in real time without the need for monitoring middleware, thereby improving reliability.
[0126] In addition, the implementation method of the configuration center is also very flexible. The gateway engine can choose different implementation methods according to different business needs to meet the needs of different configuration centers.
[0127] Considering that the gateway engine may have unstable communication with the configuration center at the initial startup. Therefore, in the embodiment of the present application, a local configuration file is introduced so that the gateway engine can complete the configuration normally even if it does not communicate with the configuration center, so that application services can be provided in time. Figure 5 The process of the gateway engine loading configuration data when a local configuration file is introduced. Figure 5 The flowchart of the gateway configuration method provided in the embodiment of the present application is shown in FIG. Figure 5 As shown, the method may include:
[0128] Step S501, determine whether there is a local configuration file; if so, execute step S502, otherwise execute step S505.
[0129] Step S502: Load second configuration data from the local configuration file.
[0130] The second configuration data may represent configuration data loaded from a local configuration file. The local configuration file may be generated by the gateway engine based on configuration data previously loaded from the configuration center. The second configuration data may refer to the first configuration data, which will not be described in detail here.
[0131] Step S503, determining whether the second configuration data is loaded successfully; if so, executing step S504, otherwise executing step S505.
[0132] The local configuration file may be damaged or unavailable. In this case, although the local configuration file exists, the gateway engine may not be able to successfully load the second configuration data. In the case where the gateway engine fails to successfully load the second configuration data, the first configuration data can be loaded from the first configuration center to provide a guarantee for the gateway configuration.
[0133] Step S504: construct a second configuration object based on the second configuration data, and put the second configuration object into the cache management queue for processing.
[0134] Step S505: load the first configuration data by calling the interface of the first configuration center.
[0135] Step S506, determining whether the first configuration data is loaded successfully, if so, executing step S507, otherwise executing step S508.
[0136] Step S507: construct a first configuration object based on the first configuration data, and put the first configuration object into a cache management queue for processing.
[0137] Step S508: construct a first failure event based on the first configuration data, and add the first failure event to a delay queue for processing.
[0138] In the case where the first configuration data is not loaded successfully, the gateway engine can construct a first failure event. The first failure event can be added to a delay queue for processing. The delay queue can include multiple failure events, which can be retried after waiting for a period of time. The processing process of the delay queue will be described in detail later and will not be repeated here.
[0139] In the embodiment of the present application, when the gateway engine is started, it can first check whether there is a local configuration file; if it exists, the configuration data in the local configuration file is loaded first, and if it does not exist, the configuration data is loaded from the configuration center. In this way, on the one hand, the loading speed of the configuration data can be accelerated through the local configuration file, which is conducive to the gateway engine to complete the configuration as soon as possible to provide services for the application; on the other hand, the configuration center provides a guarantee for the gateway engine to complete the configuration.
[0140] Considering factors such as network fluctuations, the gateway engine may fail to load the first configuration data from the configuration center. In the embodiment of the present application, a first failure event can be constructed when the first configuration data fails to load, and the first failure event can be added to the delay queue for processing, thereby realizing automatic reloading of the first configuration data, reducing the impact of network fluctuations and improving reliability. Figure 6 The processing of the delay queue is described. Figure 6 The flowchart of the gateway configuration method provided in the embodiment of the present application is shown in FIG. Figure 6 As shown, the method may include:
[0141] Step S601: when the time length of the first failure event entering the delay queue is greater than a first threshold, obtaining the first failure event from the delay queue.
[0142] Among them, the first threshold can be used to measure whether the time for the first failure event to enter the delay queue is sufficient. The first threshold can be set as needed. When the first threshold is large, the retry frequency is large, and when the first threshold is small, the retry frequency is small. When the time for the first failure event to enter the delay queue is greater than the first threshold, it indicates that the waiting time for the first failure event is long enough and a retry can be performed. At this time, the gateway engine can obtain the first failure event from the delay queue for processing.
[0143] Step S602: Obtain the configuration class and retry count of the first failure event.
[0144] The configuration class may be used to indicate the type of configuration model adopted by the first configuration data. The number of retries may be used to indicate the number of times the first configuration data is reloaded.
[0145] Step S603, determine whether the number of retries of the first failure event is less than a second threshold; if so, execute step S604, otherwise execute step S608.
[0146] Among them, the second threshold can be used to measure whether the number of retries of the first failure event exceeds the upper limit, that is, to measure whether the number of loading times of the first configuration data exceeds the upper limit. The second threshold can be set as needed. When the second threshold is large, the number of retries allowed is large, which can increase the probability of successful loading of the first configuration data. When the second threshold is small, the number of retries allowed is small, and an early warning can be issued as soon as possible.
[0147] Step S604: reload the first configuration data from the first configuration center according to the configuration class center of the first failure event.
[0148] When the number of retries of the first failure event is less than the second threshold, it indicates that the retry upper limit has not been reached, and the first configuration data can be reloaded.
[0149] Step S605, determine whether the reloading is successful; if so, execute step S606, otherwise execute step S607.
[0150] The process of reloading the first configuration data is the same as the process of loading the first configuration data for the first time, which will not be repeated here. Reloading the data may succeed or fail. If the reloading is successful, it means that the gateway engine has successfully obtained the first configuration data, and the configuration data can be updated by subsequently constructing the first configuration object based on the first configuration data and placing the first configuration object into the cache management queue. Among them, the process of constructing the first configuration object based on the first configuration data and the process of placing the first configuration object into the cache management queue for processing can refer to step S402, which will not be repeated here. If the reloading fails, the gateway engine can increase the number of retries of the first failure time by one and add it to the delay queue for processing.
[0151] Step S606: construct the first configuration object based on the first configuration data, and put the first configuration object into the queue management queue for processing.
[0152] Step S607: increase the number of retries of the first failure event by one and add the event to the delay queue for processing.
[0153] Step S608: issuing a warning event.
[0154] When the number of retries of the first failure event is greater than or equal to the second threshold, it indicates that the number of retries of the first failure event has reached the upper limit, and the gateway engine cannot obtain the first configuration data after multiple attempts. At this time, the gateway engine can issue a warning event. The warning time can be recorded as a log or as a monitoring indicator.
[0155] Combine the following Figure 7 The processing process of the cache management queue is described in detail. The processing process of the cache management queue is divided into two parts. The first part is the process of adding the first configuration object to the cache management queue, and the second part is the processing process after obtaining the first configuration object from the cache management queue. Figure 7 The flowchart of the gateway configuration method provided in the embodiment of the present application is shown in FIG. Figure 7 As shown, the method may include:
[0156] Step S701, when placing the first configuration object into the cache management queue for processing, determine whether there is a third configuration object in the cache management queue; if so, execute step S702, otherwise execute step S703.
[0157] The third configuration object may be used to represent a configuration object having the same configuration center and configuration class as the first configuration object. The configuration class may be used to indicate the type of the configuration model. The configuration model may be used to indicate the storage format of the configuration data.
[0158] When a configuration object has the same configuration center and configuration class as the first configuration object, it indicates that the configuration object and the first configuration object come from the same configuration center, correspond to the same configuration mode, use the same configuration model, can meet the same application requirements, and can achieve the same configuration effect. This configuration object can be called a third configuration object.
[0159] Step S702, determine whether the version number of the first configuration object is greater than the version number of the third configuration object; if so, execute step S703, otherwise execute step S704.
[0160] When the third configuration object already exists in the cache management queue, it indicates that the gateway engine has obtained configuration data that can meet the application requirements. Considering that the configuration data may have been updated and a new version has been generated. Therefore, the gateway engine can compare the version numbers of the first configuration object and the third configuration object. It can be understood that the larger the version number, the newer the configuration data.
[0161] When the version number of the first configuration object is greater than the version number of the third configuration object, it indicates that the newly loaded configuration data is newer and a version update may have occurred. Therefore, the first configuration object can be added to the cache management queue for processing to update the latest version of the configuration data to the cache of the gateway engine.
[0162] When the version number of the first configuration object is less than or equal to the version number of the third configuration object, it indicates that the configuration data in the new frame is not the latest version, and may be an intermediate version. Therefore, the first configuration object can be discarded to save computing resources and avoid rolling back the configuration data to a historical version, thereby causing errors.
[0163] Step S703: putting the first configuration object into the cache queue for processing.
[0164] Step S704: discard the first configuration object.
[0165] Step S705: Acquire the first configuration object from the cache management queue.
[0166] Step S706: Generate or update a local configuration file according to the first configuration object.
[0167] When there is no local configuration file before, the first configuration data can be obtained from the first configuration object, and then the local configuration file can be generated based on the first configuration data, so that the configuration data can be quickly obtained the next time the gateway engine is started. When a local configuration file already exists before, after the cache is updated using the local configuration file, the first configuration data can be loaded from the first configuration center to generate a first configuration object, and then the local configuration file can be updated using the first configuration data in the first configuration object, so that the configuration data in the local configuration file can be updated in a timely manner.
[0168] Step S707: update the first configuration data into the cache.
[0169] Step S708, if the first configuration data is not successfully updated to the cache, determine whether the number of retries of the first configuration object is less than a third threshold; if so, execute step S709, otherwise execute step S710.
[0170] The third threshold value can be used to measure whether the number of retries updated based on the first configuration object has reached the upper limit. If the number of retries of the first configuration object is less than the third threshold value, the gateway engine can try to update again. If the number of retries of the first configuration object is greater than or equal to the third threshold value, a warning event can be issued. The third threshold value can be set as needed, and the embodiment of the present application is not limited.
[0171] Step S709: Increase the number of retries of the first configuration object by one and put it back into the cache management queue for processing.
[0172] Step S710: issuing a warning event.
[0173] After the gateway engine is started, the configuration data will be loaded. During the operation of the gateway engine after it is started, the configuration data of the configuration center may change. In the embodiment of the present application, the gateway engine can dynamically monitor the configuration data of the configuration center, so that when the configuration data of the configuration center is updated, the local cache can be updated in time. Figure 8 The process of dynamic monitoring is described below. Figure 8 The flowchart of the gateway configuration method provided in the embodiment of the present application is shown in FIG. Figure 8 As shown, the method may include:
[0174] Step S801: Initialize the first configuration center.
[0175] In an embodiment of the present application, after the gateway engine determines to use the configuration data of the first configuration center according to the configuration mode used, the first configuration data can be initialized.
[0176] Step S802: Add a configuration change listener to each configuration class of the first configuration center.
[0177] Among them, the configuration class can be used to indicate the type of configuration model, and the configuration model is used to indicate the storage format of the configuration data. In an embodiment of the present application, the gateway engine can traverse each configuration class in the first configuration, and then add a configuration change listener for each configuration class. In this way, when the configuration data of any configuration class in the first configuration center changes, the configuration change listener corresponding to the configuration class can listen to the change, thereby generating a fourth configuration object, and publishing the fourth configuration object to the event bus.
[0178] Step S803: subscribe to the event bus.
[0179] The event bus is an implementation of the publish-subscribe model. It is a centralized event processing mechanism that allows different components to communicate with each other without relying on each other, achieving a decoupling purpose. The event bus serves multiple publishers and subscribers at the same time, isolates the direct dependency between publishers and subscribers, takes over the publishing and subscription logic of all events, and is responsible for the transfer of events. In an embodiment of the present application, the configuration center is equivalent to a publisher, and when there are multiple configuration centers, it is equivalent to having multiple publishers, and the gateway engine is equivalent to a subscriber. When the configuration data of each configuration center changes (i.e., updated), each configuration center can publish a configuration object to the event bus. After the gateway engine subscribes to the event bus, it can obtain the configuration objects published by each configuration center, and then put them into the cache management queue for processing.
[0180] In this way, by subscribing to the event bus, we can respond to the update of configuration data in the configuration center in a timely manner, improving the accuracy of the configuration, and isolate the direct dependence on the configuration center, improving reliability.
[0181] Step S804: When a fourth configuration object is received from the event bus, the fourth configuration object is placed in the cache management queue for processing.
[0182] The fourth configuration object is published by the configuration change listener to the event bus, and the fourth configuration object is generated according to the configuration data updated in the first configuration center.
[0183] The gateway engine subscribes to the event bus, so when the fourth configuration object appears in the event bus, the gateway engine can directly obtain the fourth configuration object from the event bus and add the fourth configuration object to the cache management queue for processing. The process of adding the fourth configuration object to the cache management queue and the processing process in the cache management queue can refer to the first configuration object, which will not be repeated here.
[0184] In an embodiment of the present application, the configuration center can dynamically update the configuration data of the gateway, and then through the automatic push or scheduled pull function of the configuration center, the configuration data can take effect in real time and respond to business needs in a timely manner.
[0185] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0186] Based on the same inventive concept, the embodiment of the present application also provides a gateway configuration device for implementing the gateway configuration method involved above. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above method, so the specific limitations in one or more gateway configuration device embodiments provided below can refer to the limitations on the gateway configuration method above, and will not be repeated here.
[0187] In one embodiment, Fig. 9 This is a structural block diagram of a configuration device provided in an embodiment of the present application. The device can be applied to a gateway engine. Fig. 9 As shown, the device 900 includes: a loading module 901, a construction module 902 and an update module 903, wherein:
[0188] A loading module, configured to load first configuration data by calling an interface of a first configuration center, wherein the first configuration center represents a configuration center matching a first configuration mode, and the first configuration mode represents a configuration mode used by the gateway engine;
[0189] A construction module, configured to construct a first configuration object based on the first configuration data when the first configuration data is successfully loaded, and put the first configuration object into a cache management queue for processing;
[0190] An updating module is used to update the first configuration data into the cache of the gateway when the first configuration object is obtained from the cache management queue during processing of the cache management queue, so as to configure the gateway.
[0191] In a possible implementation manner, the device further includes:
[0192] A determination module, used to determine whether a local configuration file exists;
[0193] The loading module is also used to load the second configuration data from the local configuration file when the local configuration file exists; when the second configuration data is successfully loaded, construct a second configuration object based on the second configuration data, and put the second configuration object into the cache management queue for processing.
[0194] In a possible implementation, the loading module is further used for:
[0195] In the case where the local configuration file does not exist, loading the first configuration data by calling an interface of the first configuration center;
[0196] or,
[0197] In the case that the local configuration file exists but the second configuration data is not loaded successfully, the first configuration data is loaded by calling an interface of the first configuration center.
[0198] In a possible implementation, the building block is further used to:
[0199] In the case where the first configuration data is not loaded successfully, a first failure event is constructed based on the first configuration data, and the first failure event is added to a delay queue for processing.
[0200] In a possible implementation, the device further includes: an acquisition module and a first adding module;
[0201] The acquisition module is configured to acquire the first failure event from the delay queue when the time length of the first failure event entering the delay queue is greater than a first threshold;
[0202] The loading module is further configured to reload the first configuration data from the first configuration center according to the configuration class of the first failure event when the number of retries of the first failure event is less than a second threshold, wherein the configuration class is used to indicate a type of a configuration model adopted by the first configuration data;
[0203] The construction module is further configured to construct the first configuration object based on the first configuration data if the reloading is successful, and put the first configuration object into the cache management queue for processing;
[0204] The first adding module is used to increase the number of retries of the first failure event by one and add the event to the delay queue for processing if the reloading fails.
[0205] In a possible implementation, placing the first configuration object into a cache management queue for processing includes:
[0206] Determine whether there is a third configuration object in the cache management queue, the third configuration object is used to represent a configuration object with the same configuration center and configuration class as those corresponding to the first configuration object, the configuration class is used to indicate a type of a configuration model, and the configuration model is used to indicate a storage format of configuration data;
[0207] If the third configuration object exists and the version number of the first configuration object is greater than the version number of the third configuration object, putting the first configuration object into the cache queue for processing;
[0208] or,
[0209] If the third configuration object does not exist, the first configuration object is placed in the cache queue for processing.
[0210] In a possible implementation, the device further includes: a second adding module;
[0211] The second adding module also has a function of increasing the retry count of the first configuration object by one and re-putting it into the cache management queue for processing if the first configuration data is not successfully updated to the cache and the retry count of the first configuration object is less than a third threshold.
[0212] In a possible implementation manner, the device further includes:
[0213] an initialization module, used to initialize the first configuration center, and add a configuration change listener to each configuration class of the first configuration center, wherein the configuration class is used to indicate a type of a configuration model, and the configuration model is used to indicate a storage format of configuration data;
[0214] Subscription module, used to subscribe to the event bus;
[0215] The third adding module is used to put the fourth configuration object into the cache management queue for processing when a fourth configuration object is received from the event bus, the fourth configuration object is published to the event bus by the configuration change listener, and the fourth configuration object is generated according to the configuration data updated in the first configuration center.
[0216] Each module in the above-mentioned gateway configuration device can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.
[0217] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig.10 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store configuration data. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a gateway configuration method is implemented.
[0218] Those skilled in the art will understand that Fig.10 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0219] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above-mentioned method embodiments when executing the computer program.
[0220] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0221] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0222] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0223] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0224] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A gateway configuration method, characterized in that: The method is applied to a gateway engine, and the method includes: Loading first configuration data by calling an interface of a first configuration center, wherein the first configuration center represents a configuration center matching a first configuration mode, and the first configuration mode represents a configuration mode used by the gateway engine; In the case where the first configuration data is successfully loaded, a first configuration object is constructed based on the first configuration data, and it is determined whether a third configuration object exists in the cache management queue, the third configuration object is used to represent a configuration object having the same configuration center and configuration class as those corresponding to the first configuration object, the configuration class is used to indicate a type of a configuration model, and the configuration model is used to indicate a storage format of the configuration data; If the third configuration object exists and the version number of the first configuration object is greater than the version number of the third configuration object, the first configuration object is placed in the cache queue for processing; or, if the third configuration object does not exist, the first configuration object is placed in the cache queue for processing; In the process of processing the cache management queue, when the first configuration object is obtained from the cache management queue, the first configuration data is updated into the cache of the gateway to configure the gateway; In the case that the first configuration data is not loaded successfully, a first failure event is constructed based on the first configuration data, and the first failure event is added to a delay queue for processing, and the first configuration data is automatically reloaded; when the time length of the first failure event entering the delay queue is greater than a first threshold, the first failure event is obtained from the delay queue, and the first threshold is positively correlated with the retry frequency.
2. The method according to claim 1, characterized in that The method further comprises: Determine if a local configuration file exists; If the local configuration file exists, load the second configuration data from the local configuration file; When the second configuration data is successfully loaded, a second configuration object is constructed based on the second configuration data, and the second configuration object is put into the cache management queue for processing.
3. The method according to claim 2, characterized in that The loading of the first configuration data by calling an interface of the first configuration center includes: In the case where the local configuration file does not exist, loading the first configuration data by calling an interface of the first configuration center; or, In the case that the local configuration file exists but the second configuration data is not loaded successfully, the first configuration data is loaded by calling an interface of the first configuration center.
4. The method according to claim 1, characterized in that: The method further comprises: When the number of retries of the first failure event is less than a second threshold, reloading the first configuration data from the first configuration center according to the configuration class of the first failure event, where the configuration class is used to indicate a type of a configuration model adopted by the first configuration data; If the reloading is successful, constructing the first configuration object based on the first configuration data, and putting the first configuration object into the cache management queue for processing; If the reloading fails, the number of retries of the first failure event is increased by one and the event is added to the delay queue for processing.
5. The method according to claim 1, characterized in that The method further comprises: If the first configuration data is not successfully updated to the cache and the number of retries of the first configuration object is less than a third threshold, the number of retries of the first configuration object is increased by one and the first configuration object is put back into the cache management queue for processing.
6. The method according to claim 1, characterized in that The method further comprises: Initialize the first configuration center, and add a configuration change listener to each configuration class of the first configuration center, where the configuration class is used to indicate a type of a configuration model, and the configuration model is used to indicate a storage format of configuration data; Subscribe to the event bus; When a fourth configuration object is received from the event bus, the fourth configuration object is placed in the cache management queue for processing, the fourth configuration object is published to the event bus by the configuration change listener, and the fourth configuration object is generated based on the updated configuration data in the first configuration center.
7. A gateway configuration device, characterized in that: The device is applied to a gateway engine, and the method includes: A loading module, configured to load first configuration data by calling an interface of a first configuration center, wherein the first configuration center represents a configuration center matching a first configuration mode, and the first configuration mode represents a configuration mode used by the gateway engine; a construction module, configured to construct a first configuration object based on the first configuration data when the first configuration data is successfully loaded, and to determine whether a third configuration object exists in the cache management queue, the third configuration object being used to represent a configuration object having the same configuration center and configuration class as those corresponding to the first configuration object, the configuration class being used to indicate a type of a configuration model, and the configuration model being used to indicate a storage format of configuration data; if the third configuration object exists and the version number of the first configuration object is greater than the version number of the third configuration object, the first configuration object is placed in the cache queue for processing; or, if the third configuration object does not exist, the first configuration object is placed in the cache queue for processing; An updating module, configured to update the first configuration data into a cache of a gateway when the first configuration object is obtained from the cache management queue during processing of the cache management queue, so as to configure the gateway; The construction module is also used to: in the case that the first configuration data is not loaded successfully, construct a first failure event based on the first configuration data, add the first failure event to a delay queue for processing, and automatically reload the first configuration data; when the time length of the first failure event entering the delay queue is greater than a first threshold, obtain the first failure event from the delay queue, and the first threshold is positively correlated with the retry frequency.
8. The device according to claim 7, characterized in that The device also includes: A determination module, used to determine whether a local configuration file exists; The loading module is also used to load the second configuration data from the local configuration file when the local configuration file exists; when the second configuration data is successfully loaded, construct a second configuration object based on the second configuration data, and put the second configuration object into the cache management queue for processing.
9. The device according to claim 8, characterized in that The loading module is also used for: In the case where the local configuration file does not exist, loading the first configuration data by calling an interface of the first configuration center; or, In the case that the local configuration file exists but the second configuration data is not loaded successfully, the first configuration data is loaded by calling an interface of the first configuration center.
10. A gateway configuration system, characterized in that: The system includes a gateway management and control terminal, a configuration center and a gateway engine; The gateway control terminal is used to receive control data, the control data is used to configure the gateway, the control data includes data required to configure the gateway and the corresponding configuration mode; assemble the control data into configuration data according to the configuration model, the configuration model is used to indicate the storage format of the configuration data; associate the configuration data, configuration class and version number and store them in the configuration center corresponding to the configuration mode, the configuration class is used to indicate the type of the configuration model; The configuration center is used to associate and store configuration data, configuration classes and version numbers, and each configuration center corresponds to a unique configuration mode; The gateway engine is used to execute the gateway configuration method according to any one of claims 1 to 6.
