Application dynamic configuration unified loading and hot update system

By dynamically configuring the unified loading and hot update system, using the listening and subscription service module and loader components, combined with the configuration database, dynamic management and hot update of application configuration are realized, solving the flexibility and availability of traditional configuration management, and improving the System continuity and scalability.

CN118963863BActive Publication Date: 2024-12-27SHENZHEN UXUN INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411427482.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-14
Publication Date
2024-12-27
Estimated Expiration
2044-10-14

AI Technical Summary

Technical Problem

Traditional application configuration management has problems such as inflexible configuration loading, strong system dependence and great impact on restarting services. It is difficult to achieve unified configuration management and flexible changes, which affects the continuous availability and modular design of the system.

Method used

Design a unified loading and thermal update system for application dynamic configuration, including monitoring and subscription service modules, loader components and configuration databases, dynamic update of configuration information through reflection mechanisms, realizing dynamic configuration management and thermal update of applications, and decoupling of application systems and Configuration management system.

Benefits of technology

It realizes unified configuration management and flexible changes, avoids restarting services, improves the continuous availability and modular design of the system, reduces maintenance costs, and enhances the decoupling and scalability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118963863B_ABST
    Figure CN118963863B_ABST
Patent Text Reader

Abstract

The present invention relates to a system for unified loading and hot updating of dynamic configuration of applications, comprising a monitoring and subscription service module, a loader component, and a configuration database; the monitoring and subscription service module and the loader component are both configured in the application, and the configuration database has a configuration subscription service; the monitoring and subscription service module determines the required configuration items of the application, and registers a subscription request of the required configuration items corresponding to the application with the configuration subscription service; the configuration subscription service receives the subscription request of the required configuration items registered by the monitoring and subscription service module of each application, and sends an update notification to the loader component corresponding to the subscription request when there is an update to the required configuration items; the loader component receives the update notification sent by the configuration subscription service, and according to the configuration item identifier carried in the update notification, queries the corresponding configuration information from the configuration database by reflection and dynamically updates it to the memory of the application, thereby realizing unified loading and hot updating of dynamic configuration of the application.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of application development technology, and in particular to a system for unified loading and hot updating of dynamic application configuration. Background Art

[0002] With the rapid development of information technology, enterprise-level application systems are becoming increasingly complex, and the configuration management behind them has become a key link in maintaining and optimizing system performance. Traditional application configurations are usually hard-coded in source code or stored in static configuration files, which has many disadvantages. First, the decentralized management of configurations makes it difficult to achieve unified configuration monitoring and adjustment from a global perspective, increasing the difficulty of operation and maintenance. Secondly, whenever the configuration changes, it is often necessary to restart the application for the new configuration to take effect, which not only affects the continuous availability of the system, but also limits the system's ability to respond quickly to environmental changes. In addition, if application systems directly rely on configuration files, they will form a high degree of coupling, which is not conducive to the modular design and expansion of the system.

[0003] At present, although the configuration management system can realize centralized management and change of configuration, the following problems still exist:

[0004] 1. Inflexible configuration loading: Most systems use static loading, which means that configuration information is loaded when the application starts and cannot be changed dynamically afterwards.

[0005] 2. Strong system dependency: The application system is tightly coupled with the configuration management system. Once a problem occurs in the configuration management system, the application system will also be affected.

[0006] 3. Restarting services has a significant impact: When configuration information changes, the application service needs to be restarted for the new configuration to take effect, which may cause service interruption and affect business continuity. Summary of the invention

[0007] The purpose of the present invention is to provide a unified loading and hot update system for dynamic application configuration, aiming to solve the problem of unified management and flexible change of configuration, realize the decoupling of application system and configuration management system, and the function of hot loading configuration without restarting.

[0008] In order to achieve the above-mentioned purpose, the embodiment of the present disclosure provides a system for unified loading and hot updating of dynamic configuration of applications, the system comprising:

[0009] Listening and subscription service modules, loader components, and configuration databases;

[0010] Wherein, the monitoring and subscription service module and the loader component are both configured in the application, and the configuration database has a configuration subscription service;

[0011] The monitoring and subscription service module is used to determine the required configuration items of the application each time the application is started, and register a subscription request for the required configuration items corresponding to the application with the configuration subscription service in the configuration database;

[0012] The configuration subscription service is used to receive subscription requests for the required configuration items registered by the monitoring and subscription service module of each application, and send update notifications to the loader component corresponding to the subscription request when there is an update to the required configuration items;

[0013] The loader component is used to receive an update notification sent by the configuration subscription service, and according to the configuration item identifier carried in the update notification, query the corresponding configuration information from the configuration database by reflection and dynamically update it to the memory of the application, so as to realize the unified loading and hot update of the dynamic configuration of the application, wherein the configuration item identifier and the configuration information are stored in the configuration database in the form of a key-value pair.

[0014] In a preferred embodiment, the loader component is used to query the corresponding configuration value from the configuration database by reflection and update it to the memory of the application according to the configuration item identifier carried in the update notification, so as to realize the unified loading and hot update of the dynamic configuration of the application, including:

[0015] The loader component is used to dynamically map the configuration item identifier carried in the update notification to the mapping of the field of the class in the memory of the application by scanning the annotation on the class;

[0016] If the target class field corresponding to the configuration item identifier is found in the mapping of the class field, accessing the target class field of the application by using reflection to obtain the type of the target class field;

[0017] Converting a new value corresponding to the configuration item identifier queried from the configuration database into a type of the target class field of the application;

[0018] By using reflection, the value of the target class field in the application memory is updated according to the new value after type conversion.

[0019] In a preferred embodiment, the loader component is used to dynamically map the configuration item identifier carried in the update notification to the mapping of the field of the class in the memory of the application by scanning the annotation on the class, including:

[0020] The loader component is used to scan annotations on all classes of the application through a scanner, wherein the application uses annotations to mark fields whose values ​​need to be read from the configuration;

[0021] For each annotation on the scanned class, record the configuration item identifier of the annotation and the corresponding field;

[0022] Dynamically map the configuration item identifier carried in the update notification to the recorded mapping of the fields of the in-memory class of the application.

[0023] In a preferred embodiment, the loader component is used to scan annotations on all classes of the application through a scanner, including:

[0024] Access the Spring context of the application by implementing the Application Context Aware interface;

[0025] Traverse all beans in the context environment through a custom Bean Post Processor to check whether the Config Value annotation is used on the field of each bean;

[0026] Use Environment or Property Sources Placeholder Configurer to read the fields marked on the application that need to read values ​​from the configuration.

[0027] In a preferred embodiment, the configuration subscription service is also used to:

[0028] Receiving an access modification request from any permission account, wherein the access modification request carries the access and modification permissions of the permission account, and the access and modification permissions are used to determine the corresponding configuration scope to be accessed and modified in the configuration database;

[0029] According to the configuration range corresponding to the access and modification authority carried in the access modification request, find the corresponding modification target location, and record the configuration change information carried in the access modification request through the authority control and audit log of the configuration database;

[0030] The old value of the configuration information corresponding to the modification target position is queried, and the old value is replaced with the corresponding new value in the configuration change information, so as to generate the update notification for the existence of an update for the required configuration item.

[0031] In a preferred embodiment, the configuration subscription service is further used to generate a new version number according to the new value based on the operation of replacing the old value with the corresponding new value in the configuration change information, and associate the version number corresponding to the old value with the version number of the new value and save it as a historical version;

[0032] The loader component is further configured to generate a rollback request according to the new value when the new value causes an abnormality in the application system;

[0033] The configuration subscription service is also used to receive a rollback request sent by any of the applications, and query the corresponding abnormal version number based on the new value carried in the rollback request, and query the corresponding target historical version based on the abnormal version number, and send the old value corresponding to the target historical version as a new rollback value to the application with the system abnormality, so that the application with the system abnormality can be reconfigured according to the new rollback value.

[0034] In a preferred implementation, the configuration database stores the configuration item identifier and the configuration information in the form of a key-value pair, including:

[0035] The configuration database generates a key-value pair including the configuration item identifier and the configuration information using any one of a string, a Boolean value, a number, and a JSON object, wherein the configuration information includes at least one of the following: a dictionary tag, a configuration value, a configuration description, an effective range, and a version number.

[0036] In a preferred embodiment, the configuration subscription service is used to send an update notification to the loader component corresponding to the subscription request when the required configuration item is updated, including:

[0037] In the case where the required configuration item is updated, a message queue of the loader component corresponding to the subscription request is constructed based on a persistently stored database table according to the time when the subscription request is received, wherein the database table includes a database table creation time, a subscription time, and a subscription status;

[0038] Sending the update notification to the loader components in the message queue in sequence;

[0039] When a feedback message is received from the loader component regarding the update notification, the subscription status is changed from processing to completed; or, when no feedback message is received from the loader component regarding the update notification within a preset time period, the subscription status is changed from processing to failed.

[0040] In a preferred embodiment, the configuration subscription service is further used to: upon receiving a subscription request sent by any of the monitoring and subscription service modules, query whether there is a corresponding trigger in the configuration database according to the subscribed configuration item identifier carried in the subscription request; if no corresponding trigger is found in the configuration database, create a trigger in the configuration database using an SQL statement, and set the trigger on the configuration item identifier corresponding to the subscription request; or, if a corresponding trigger is found in the configuration database, set the queried trigger on the configuration item identifier corresponding to the subscription request;

[0041] The configuration subscription service is used to send an update notification to the loader component corresponding to the subscription request when the required configuration item is updated, including: when the required configuration item is updated, sending an update notification to the loader component corresponding to the subscription request through the trigger set on the configuration item identifier.

[0042] The present invention provides a unified loading and hot update system for dynamic application configuration. Compared with the prior art, it has the following beneficial effects:

[0043] By configuring both the monitoring and subscription service module and the loader component in the application, a configuration subscription service is created in the configuration database. The monitoring and subscription service module can determine the required configuration items of the application each time the application is started, and register the subscription request of the required configuration items corresponding to the application to the configuration subscription service in the configuration database; the subscription request of the required configuration items registered by the monitoring and subscription service module of each application is received through the configuration subscription service, and when there is an update to the required configuration items, an update notification is sent to the loader component corresponding to the subscription request; the update notification sent by the configuration subscription service is received through the loader component, and according to the configuration item identifier carried in the update notification, the corresponding configuration information is queried from the configuration database by reflection and dynamically updated to the memory of the application, so as to realize the unified loading and hot update of the dynamic configuration of the application, wherein the configuration item identifier and the configuration information are stored in the form of key-value pairs in the configuration database. The unified management and flexible change of configuration can be realized, the decoupling of the application system and the configuration management system can be realized, and the function of hot loading configuration without restarting can be realized.

[0044] Other features and advantages of the present disclosure will be described in detail in the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] The accompanying drawings are used to provide a further understanding of the present disclosure and constitute a part of the specification. Together with the following specific embodiments, they are used to explain the present disclosure but do not constitute a limitation of the present disclosure. In the accompanying drawings:

[0046] Figure 1 It is a block diagram of a system for unified loading and hot updating of dynamic application configuration according to an embodiment of the specification.

[0047] Figure 2 It is a flow chart of a method for unified loading and hot updating of dynamic configuration of an application according to an embodiment of the specification.

[0048] Figure 3 According to the embodiment of the specification, an implementation Figure 2 Flowchart of step S13 in FIG.

[0049] Figure 4 According to the embodiment of the specification, an implementation Figure 3 Flowchart of step S21 in FIG. DETAILED DESCRIPTION

[0050] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0051] The specific implementation of the present disclosure is described in detail below in conjunction with the accompanying drawings. It should be understood that the specific implementation described herein is only used to illustrate and explain the present disclosure, and is not used to limit the present disclosure.

[0052] The present disclosure provides a unified loading and hot update system for dynamic application configuration. Figure 1 As shown, the system comprises:

[0053] Listening and subscription service modules, loader components, and configuration databases;

[0054] Wherein, the monitoring and subscription service module and the loader component are both configured in the application, and the configuration database has a configuration subscription service;

[0055] Among them, the application can be an application configured in a terminal such as a mobile phone, wearable device, tablet computer, laptop computer, etc., and the configuration database can be configured in a cloud server. The monitoring and subscription service module is responsible for monitoring the startup events of the application, and determining the required configuration items when the application starts, and then registering subscription requests for these configuration items to the configuration subscription service in the configuration database. The loader component is responsible for receiving update notifications sent by the configuration subscription service, and querying the corresponding configuration information from the configuration database according to the configuration item identifier in the notification, and then dynamically updating it to the memory of the application. The configuration database is a database that stores configuration information, usually in the form of key-value pairs to store configuration item identifiers and corresponding configuration information. The configuration subscription service is responsible for receiving configuration item subscription requests registered by the monitoring and subscription service modules of each application, and sending update notifications to the corresponding loader components when there are updates to the configuration items.

[0056] See also Figure 2 As shown, in step S11, the monitoring and subscription service module is used to determine the required configuration items of the application each time the application is started, and register a subscription request for the required configuration items corresponding to the application with the configuration subscription service in the configuration database;

[0057] In the disclosed embodiment, during the application startup phase, the monitoring and subscription service module will traverse the configuration requirements of the application and identify all configuration items that need to be dynamically loaded. Based on the identified configuration items, a subscription request is sent to the subscription service in the configuration database. These requests usually contain information such as the application identifier, the configuration item identifier (such as the name or ID of the configuration item), and possible version requirements. In addition, the monitoring and subscription service module may need to continue to monitor additional configuration subscription requirements or unsubscription requests from the application.

[0058] In step S12, the configuration subscription service is used to receive a subscription request for the required configuration item registered by the monitoring and subscription service module of each application, and send an update notification to the loader component corresponding to the subscription request when there is an update to the required configuration item;

[0059] In the disclosed embodiment, the configuration subscription service may maintain a subscription list to record which applications have subscribed to which configuration items. Changes in configuration items may be detected periodically or in real time (e.g., through database triggers, polling, etc.). Once a change in a configuration item is detected, an update notification is sent to the loader component of the relevant application according to the subscription list, and the notification includes a configuration item identifier and possible update details.

[0060] In step S13, the loader component is used to receive the update notification sent by the configuration subscription service, and according to the configuration item identifier carried in the update notification, query the corresponding configuration information from the configuration database by reflection and dynamically update it to the memory of the application, so as to realize the unified loading and hot update of the dynamic configuration of the application, wherein the configuration item identifier and the configuration information are stored in the configuration database in the form of a key-value pair.

[0061] In the disclosed embodiment, the loader component listens to update notifications from the configuration subscription service. The configuration item identifier is extracted from the notification. Reflection or other mechanisms are used to query the latest configuration information from the configuration database according to the configuration item identifier, and dynamically update it to the memory of the application. Ensure that the relevant parts of the application (such as the user interface, service logic, etc.) are updated accordingly according to the new configuration information.

[0062] Among them, dynamic configuration means that the application can dynamically obtain and update configuration information as needed during runtime without restarting the application. Unified loading means centrally managing and loading all required configuration information to ensure that one or more applications can obtain all necessary configurations at the same time. Hot update means updating the configuration information of the application in real time without restarting the application, so that the new configuration takes effect immediately.

[0063] Each data item in a key-value pair consists of a unique key and a corresponding value. In a configuration database, the key is usually the identifier of the configuration item, and the value is the specific configuration information.

[0064] The above system realizes the dynamic configuration unified loading and hot update of the application through the collaborative work of the monitoring and subscription service module, the loader component and the configuration database. The monitoring and subscription service module determines the required configuration items and registers the subscription request when the application starts. The configuration subscription service notifies the loader component when the configuration items are updated. The loader component dynamically updates the configuration information to the application memory through the reflection mechanism. It ensures the real-time push of configuration changes without manual intervention or service restart.

[0065] In other words, the above system configures both the monitoring and subscription service module and the loader component in the application, creates a configuration subscription service in the configuration database, and can determine the required configuration items of the application through the monitoring and subscription service module each time the application is started, and register the subscription request of the required configuration items corresponding to the application to the configuration subscription service in the configuration database; receive the subscription request of the required configuration items registered by the monitoring and subscription service module of each application through the configuration subscription service, and send an update notification to the loader component corresponding to the subscription request when there is an update to the required configuration item; receive the update notification sent by the configuration subscription service through the loader component, and query the corresponding configuration information from the configuration database through reflection according to the configuration item identifier carried in the update notification, and dynamically update it to the memory of the application, so as to realize the unified loading and hot update of the dynamic configuration of the application, wherein the configuration item identifier and the configuration information are stored in the form of key-value pairs in the configuration database. It can realize the unified management and flexible change of configuration, realize the decoupling of the application system and the configuration management system, and realize the function of hot loading configuration without restarting.

[0066] In a preferred embodiment, see Figure 3 As shown, the loader component is used to query the corresponding configuration value from the configuration database by reflection according to the configuration item identifier carried in the update notification and update it to the memory of the application, so as to realize the unified loading and hot update of the dynamic configuration of the application, including:

[0067] The loader component is used to, in step S21, dynamically map the configuration item identifier carried in the update notification to the mapping of the field of the class in the memory of the application by scanning the annotation on the class;

[0068] In the disclosed embodiment, the loader component first establishes a mapping relationship between the configuration item identifier and the field in the class by scanning the annotations on the class in the application, and associates the configuration items in the configuration database with the internal data structure of the application at runtime.

[0069] Specifically, define one or more annotations to mark which fields in the class can be dynamically updated through configuration. These annotations can contain information such as configuration item identifiers and default values. Use reflection or bytecode manipulation libraries (such as Java's ASM, CGLIB, etc.) to traverse the application's class definitions, find fields with specific annotations, and create a mapping table from configuration item identifiers to these fields.

[0070] For example, suppose there is a Product Display Config class, which has a field layout marked with a custom annotation @Config Value("product_display_layout"). The loader component will scan this annotation and record the mapping relationship between the configuration item identifier product_display_layout and the layout field in the Product Display Config class.

[0071] In the embodiment of the present disclosure, after receiving the update notification, the loader component will search for the corresponding target class field in the previously established mapping table according to the configuration item identifier carried in the notification. Use the configuration item identifier as a key to search for the corresponding class field information in the mapping table. If the corresponding field is found, proceed to the next step; if not found, it may be necessary to record an error or take other fallback measures.

[0072] For example, after the loader component receives the update notification about product_display_layout, it looks up the layout field of the Product Display Config class in the mapping table.

[0073] In step S22, if the target class field corresponding to the configuration item identifier is found in the mapping of the class field, the target class field of the application is accessed by using reflection to obtain the type of the target class field;

[0074] In the disclosed embodiment, after determining the target class field, the loader component uses the reflection API to access this field to obtain its type information. This is to ensure that the configuration value read from the configuration database can be correctly converted to the type required by the field. The type of the field is obtained through the getType() method of the java.lang.reflect.Field class. For example, the loader component obtains the type of the layout field in the Product Display Config class through reflection, assuming that it is of type String.

[0075] In step S23, converting the new value corresponding to the configuration item identifier queried from the configuration database into the type of the target class field of the application;

[0076] In the disclosed embodiment, the configuration value read from the configuration database is usually in the form of a string, so it is necessary to convert this string value into a corresponding type according to the type of the target class field. This may require the use of Java's type conversion mechanism, such as Integer.parse Int(), Boolean.parse Boolean(), etc., or a custom type converter. Select an appropriate converter for conversion according to the field type.

[0077] For example, suppose the new value read from the configuration database is the string "new_layout_123", and the loader component converts this string value to the String type (in this example, no type conversion actually occurs because the field itself is of type String). But in other cases, you may need to convert a string to an integer, floating point number, or enumeration type, etc.

[0078] In step S24, the value of the target class field in the application memory is updated according to the new value after type conversion by using reflection.

[0079] In the disclosed embodiment, the loader component uses the reflection API to set the converted new value to the target class field, thereby realizing dynamic update of the configuration. The new value is set to the field through the set(Object obj, Object value) method of the java.lang.reflect.Field class. Here, obj is an instance of the target class, and value is the new value after conversion. If the target class field is not static, it is also necessary to obtain the instance object of the class first.

[0080] For example, the loader component obtains an instance of the Product Display Config class (perhaps automatically injected by a dependency injection framework such as Spring), and then uses reflection to set the converted new value "new_layout_123" to the layout field of the instance.

[0081] In a preferred embodiment, the loader assembly is used to Figure 4 As shown, in step S21, by scanning the annotations on the class, the configuration item identifier carried in the update notification is dynamically mapped to the mapping of the field of the class in the memory of the application, including:

[0082] The loader component is used to, in step S211, scan annotations on all classes of the application through a scanner, wherein the application uses annotations to mark fields whose values ​​need to be read from the configuration;

[0083] In the disclosed embodiment, the loader component uses a scanner to traverse the class path of the application, find and load all class files. Then, it checks whether there are annotations on these classes for marking fields that need to read values ​​from the configuration. This scanning process is usually performed during the startup phase of the application or the configuration update preparation phase.

[0084] Class path traversal: The scanner traverses the application's class path through Java's class loading mechanism or a specific library (such as Google's Reflections library) to find all accessible class files.

[0085] Annotation checking: For each loaded class, the scanner checks whether its definition contains certain annotations. These annotations are designed to mark fields whose values ​​should come from external configuration.

[0086] For example, suppose there is a @Config Value annotation, which is used to mark the fields that need to be updated dynamically. The scanner will traverse all classes and find fields with @Config Value annotations.

[0087] In step S212, for each annotation on the scanned class, the configuration item identifier and the corresponding field of the annotation are recorded;

[0088] In the disclosed embodiment, after scanning a field with a specific annotation, the loader component needs to record the configuration item identifiers in these annotations and their corresponding field information. This is usually achieved by building a mapping table (Map), where the key is the configuration item identifier and the value is an object containing field information (which may be the java.lang.reflect.Field object of the field, or a custom object containing information such as the field name and type).

[0089] Mapping table construction: The loader component initializes a mapping table to store the mapping relationship between configuration item identifiers and fields.

[0090] Information recording: For each scanned annotation, the loader component extracts the configuration item identifier in the annotation and obtains the corresponding field information (such as field name, field type, class to which the field belongs, etc.), and then records this information in the mapping table.

[0091] For example, if a layout field annotated with @Config Value("product_display_layout") is scanned, the loader component will use "product_display_layout" as the key and the Field object of the layout field (or a custom object containing its information) as the value and store it in the mapping table.

[0092] In step S213, the configuration item identifier carried in the update notification is dynamically mapped to the recorded mapping of the fields of the in-memory class of the application.

[0093] In the disclosed embodiment, after receiving the update notification, the loader component needs to parse the notification and extract the configuration item identifier carried therein. Then, it uses the configuration item identifier as a key to search for the corresponding field information in the previously constructed mapping table. If the corresponding field is found, it is considered that the configuration item identifier has established a mapping relationship with a field of the application.

[0094] Parsing update notifications: The loader component parses the update notification and extracts the list of configuration item identifiers.

[0095] Mapping lookup: For each configuration item identifier, the loader component looks up the corresponding field information in the mapping table.

[0096] Establishing dynamic mappings: Although this step itself does not directly "establish" new mappings, it is the process of dynamically identifying and applying these mappings at runtime based on update notifications. The loader component now knows which configuration item identifiers correspond to which fields of the application, and can then update the application configuration based on this information.

[0097] For example, the loader component receives an update notification containing "product_display_layout". It uses this configuration item identifier to look up in the mapping table and finds the layout field of the Product Display Config class. Now, the loader component knows that it needs to update the layout field of the Product Display Config instance with the new value of this configuration item.

[0098] In a preferred embodiment, the loader component is used to, in step S211, scan annotations on all classes of the application through a scanner, including:

[0099] In step S2111, the Spring context environment of the application is accessed by implementing the Application Context Aware interface;

[0100] In the disclosed embodiment, by implementing the Application Context Aware interface, the Spring framework can automatically inject the context environment of the current application when creating and managing the Bean of this implementation class.

[0101] Interface implementation: Create a class and implement the Application Context Aware interface. This interface contains a method set Application Context (Application Context application Context). When the Spring container creates this bean, it automatically calls this method and passes in the context of the current application.

[0102] Context acquisition: In the set Application Context method, save the passed ApplicationContext object to the member variables of the class for use in subsequent steps.

[0103] In step S2112, all beans in the context are traversed through the custom Bean Post Processor to check whether the Config Value annotation is used on the field of each bean;

[0104] In the disclosed embodiment, the extension point in Spring's Bean life cycle, Bean PostProcessor, is used to traverse all beans in the context and check whether their fields are annotated with @Config Value.

[0105] Bean Post Processor definition: Create a class to implement the Bean Post Processor interface, which contains two methods: post Process Before Initialization and post Process After Initialization. Here, you can choose to scan the beans in the post Process After Initialization method, because the beans have already completed the pre-initialization settings.

[0106] Bean traversal and annotation check: In the post Process After Initialization method, get the bean name and instance of a specific type or all types through methods such as application Context.get Beans Of Type() or application Context.get Bean NamesFor Type(). Then, use the Java reflection API to traverse the fields of these beans and check whether there is a @Config Value annotation.

[0107] In step S2113, Environment or Property Sources PlaceholderConfigurer is used to read the fields on the application that are marked as needing to read values ​​from the configuration.

[0108] In the disclosed embodiment, Spring's Environment interface or Property SourcesPlaceholder Configurer (or its modern alternatives, such as @Configuration Properties combined with @EnableConfiguration Properties) is used to read the value corresponding to the @Config Value annotated field in the external configuration.

[0109] Environment usage: If you are using the Environment interface, you can get the value of the configuration item by injecting the Environment Bean and calling its get Property(String key) method. Here, key can be the configuration item identifier extracted from the @Config Value annotation.

[0110] Property Sources Placeholder Configurer (or its modern alternatives): For traditional placeholder configuration, you can use Property Sources Placeholder Configurer or related mechanisms, or use @Configuration Properties in conjunction with @Enable Configuration Properties, which can bind configuration directly to Java objects and integrate more conveniently with annotated fields.

[0111] In a preferred embodiment, the configuration subscription service is also used to:

[0112] In step S31, an access modification request of any permission account is received, wherein the access modification request carries the access and modification permissions of the permission account, and the access and modification permissions are used to determine the corresponding configuration scope to be accessed and modified in the configuration database;

[0113] In the disclosed embodiment, the configuration subscription service first needs to be able to receive access modification requests from any authorized account. These requests are usually sent through HTTP API, message queues or other remote communication mechanisms. The request must contain sufficient information to verify the identity of the account, the authority, and the specific content of the request.

[0114] Configuring the subscription service first verifies the identity of the account sending the request, for example through JWT (JSON Web Tokens), OAuth tokens, or basic authentication (such as username and password).

[0115] Permission verification: Verify that the account has permission to perform the action specified in the request. This typically involves checking the account's role, permission set, or specific access control list (ACL).

[0116] Request parsing: Parse the request body or query parameters to obtain specific information about access and modification permissions, including configuration scope (such as the key name and grouping of configuration items).

[0117] In step S32, according to the configuration range corresponding to the access and modification permissions carried in the access modification request, the corresponding modification target location is searched, and the configuration change information carried in the access modification request is recorded through the permission control and audit log of the configuration database;

[0118] In the disclosed embodiment, the configuration subscription service searches the configuration database for the specific modification target location according to the configuration scope corresponding to the access and modification permissions carried in the request. Once found, the service will perform the following operations:

[0119] Permission control: Confirm again whether the account has the permission to modify the target configuration item. This is an additional security step to prevent any potential permission bypass.

[0120] Old value query: query and record the current old value of the target configuration item.

[0121] Mutation execution: Replace the old value with the new value provided in the request. This usually involves updating the record in the database.

[0122] Audit log records: record all relevant change information, including change time, executor, values ​​before and after the change, etc.

[0123] In step S32, the old value of the configuration information corresponding to the modification target position is queried, and the old value is replaced with the corresponding new value in the configuration change information, so as to generate the update notification for the existence of an update for the required configuration item.

[0124] In the disclosed embodiment, after the configuration change is executed, the configuration subscription service may need to notify all subscribers who are interested in the configuration item change. This is usually achieved through a publish-subscribe model, where the configuration subscription service acts as a publisher and the subscriber can be an application.

[0125] Subscriber Management: The configuration subscription service needs to maintain a list of subscribers that have registered their interest in changes to a particular configuration item.

[0126] Notification sending: When a configuration item changes, the configuration subscription service will send an update notification to all relevant subscribers. The notification can contain detailed information about the change, such as the key name, old value, and new value of the configuration item.

[0127] Notification Mechanism: Notifications can be sent via a variety of mechanisms, such as HTTP callbacks, message queues, or real-time communication protocols such as Web Sockets.

[0128] Users with different roles can access and modify different configuration ranges. Every configuration change is recorded through database permission control and audit logs to ensure the traceability and security of configuration operations.

[0129] In a preferred embodiment, the configuration subscription service is further used to generate a new version number according to the new value based on the operation of replacing the old value with the corresponding new value in the configuration change information, and associate the version number corresponding to the old value with the version number of the new value and save it as a historical version;

[0130] In the embodiment of the present disclosure, during the configuration change process, whenever the old value of a configuration item is replaced by a new value, in order to support version control and rollback functions, it is necessary to generate a new version number for the new value, and associate the old value and its version number with the version number of the new value and save them as a historical version.

[0131] Version number generation: The version number generation strategy can be designed according to actual needs, and can include incremental numbers, timestamps, UUIDs, etc. Ensuring the uniqueness of each version number is the key.

[0132] Historical version records: In the configuration database, in addition to storing the current configuration value, a historical version table or structure needs to be maintained to record the historical version information of each configuration item. The historical version record should include the key name of the configuration item, the old value, the version number of the old value, the new value, the version number of the new value, and the change time.

[0133] Association preservation: Whenever a configuration change occurs, the old value and its version number are associated with the new value's version number and saved together in the historical version record. In this way, the change history of the configuration item can be traced at any time by querying the historical version record.

[0134] The loader component is further configured to generate a rollback request according to the new value when the new value causes an abnormality in the application system;

[0135] In the disclosed embodiment, when an exception occurs when an application uses a new configuration value, the loader component needs to be able to detect the exception and generate a corresponding rollback request.

[0136] Anomaly detection: The loader component needs to integrate anomaly detection mechanisms, such as capturing anomalies, monitoring application performance, or analyzing logs to identify system anomalies that may be caused by configuration changes.

[0137] Rollback request generation: Once an exception is detected that is related to a configuration change, the loader component needs to generate a rollback request. The rollback request should contain enough information to identify the configuration item that needs to be rolled back and its new value (or version number of the new value).

[0138] Request sending: The loader component sends a rollback request to the configuration subscription service or the corresponding rollback processing service.

[0139] The configuration subscription service is also used to receive a rollback request sent by any of the applications, and query the corresponding abnormal version number based on the new value carried in the rollback request, and query the corresponding target historical version based on the abnormal version number, and send the old value corresponding to the target historical version as a new rollback value to the application with the system abnormality, so that the application with the system abnormality can be reconfigured according to the new rollback value.

[0140] In the disclosed embodiment, the configuration subscription service receives a rollback request from the application system, and queries and applies the corresponding historical version according to the information in the request.

[0141] Rollback request reception: Configure the subscription service to provide an interface to receive rollback requests.

[0142] Query the abnormal version number: Based on the new value of the configuration item (or the version number of the new value) carried in the rollback request, query the historical version record to determine the version number that caused the abnormality.

[0143] Query the target historical version: Once an abnormal version number is found, query the historical version record corresponding to the version number to obtain the old value of the target historical version.

[0144] Perform rollback: Send the old value of the target historical version as the new rollback value to the application system that requested the rollback so that it can be reconfigured.

[0145] Implement the configuration version management function, automatically increase the version number each time the configuration changes and save the historical version. When the new configuration causes system abnormalities, you can quickly roll back to the last stable version to reduce the risk caused by configuration errors.

[0146] In a preferred implementation, the configuration database stores the configuration item identifier and the configuration information in the form of a key-value pair, including:

[0147] The configuration database generates a key-value pair including the configuration item identifier and the configuration information using any one of a string, a Boolean value, a number, and a JSON object, wherein the configuration information includes at least one of the following: a dictionary tag, a configuration value, a configuration description, an effective range, and a version number.

[0148] The configuration database is a system component used to store various configuration information. It can generate key-value pairs in a variety of data types, including strings, Boolean values, numbers, and JSON objects. This flexibility enables it to adapt to different types of configuration requirements.

[0149] Build a dedicated configuration database table structure, including but not limited to fields such as configuration item ID, dictionary key, dictionary tag, configuration value, configuration description, effective scope, version number, etc. Use key-value pairs to store configuration information, support multiple data types (string, Boolean value, number, JSON object, etc.), and ensure configuration flexibility and diversity.

[0150] Configuration item identifier: is a key that uniquely identifies a specific configuration. It can be a meaningful name or code that is used to quickly locate and retrieve a specific configuration item in the database.

[0151] Configuration information: Contains detailed information related to the configuration items, including the following aspects:

[0152] Dictionary tags: can be understood as a classification label for configuration items, which is used to classify different configuration items for easy management and search. For example, there can be different dictionary tags such as "system settings", "user preferences", and "security configuration".

[0153] Configuration value: This is the specific value of the configuration item. Depending on the type of the configuration item, the configuration value can be a string (such as text content), a Boolean value (true or false), a number (integer or decimal), or a more complex JSON object (used to represent structured data).

[0154] Configuration description: A text that explains the function and meaning of a configuration item. It can help users better understand the purpose of each configuration item so that they can make configuration adjustments correctly.

[0155] Scope: Specifies the scope of a configuration item in the system. For example, some configurations may only be effective for specific modules or functions, while some configurations may affect the entire system. Clarifying the scope can avoid configuration conflicts and errors.

[0156] Version number: used to track changes in configuration items. When a configuration item is modified, the version number can help the system determine whether corresponding updates and adjustments are required. At the same time, the version number can also be used to roll back to a specific configuration version to deal with possible problems.

[0157] In the disclosed embodiment, when a configuration item needs to be stored in a database, a suitable data type (string, Boolean value, number or JSON object) is selected to represent the configuration value according to the content and type of the configuration item. Then, the configuration item identifier and the configuration information including the dictionary tag, configuration value, configuration description, effective range and version number are combined into a key-value pair and stored in the configuration database. In this way, when the configuration information needs to be obtained, the corresponding key-value pair can be quickly found through the configuration item identifier, and the required configuration information can be extracted.

[0158] In a preferred embodiment, the configuration subscription service is used to send an update notification to the loader component corresponding to the subscription request when the required configuration item is updated, including:

[0159] In the case where the required configuration item is updated, a message queue of the loader component corresponding to the subscription request is constructed based on a persistently stored database table according to the time when the subscription request is received, wherein the database table includes a database table creation time, a subscription time, and a subscription status;

[0160] In the disclosed embodiment, the configuration subscription service needs to query the persistent storage database table, which records all subscription request information, including subscription time, subscription status and subscribed configuration items. By matching the updated configuration items with the configuration items in the subscription request, the service can identify all loader components that have subscribed to the configuration item.

[0161] Build a message queue: For each identified loader component, the service creates a message queue item. These items contain update notification details, such as the updated configuration item name, new value, update time, etc., as well as the loader component identifier (such as IP address, port number, or unique ID) so that the service can send the update notification to the correct loader component.

[0162] Database table support: In addition to basic subscription information (such as database table creation time, subscription time, and subscription status), the database table may also contain other fields required to build a message queue, such as the communication information of the loader component (IP, port), the subscribed configuration item identifier, etc.

[0163] By querying the database table, all subscription requests related to the updated configuration items can be quickly retrieved. Then, based on the information of these subscription requests, the service can dynamically build a message queue, where each queue item is targeted at a specific loader component. This method of dynamically building a message queue ensures that update notifications can be accurately sent to all relevant loader components.

[0164] Sending the update notification to the loader components in the message queue in sequence;

[0165] In the disclosed embodiment, the subscription service is configured to traverse the message queue and send update notifications to each loader component in turn. This is usually achieved through network communication, such as using HTTP requests, Web Socket connections, or message queue systems (such as Rabbit MQ, Kafka, etc.).

[0166] When sending update notifications, configured subscription services may need to implement retry mechanisms to handle network failures or temporary unavailability of the loader component. Additionally, services can log sends to facilitate tracking and debugging if problems occur.

[0167] By traversing the message queue and sending update notifications in sequence, it can ensure that all relevant loader components can receive update information in a timely manner. At the same time, by implementing a retry mechanism and recording sending logs, the service can improve the reliability and maintainability of communication.

[0168] When a feedback message is received from the loader component regarding the update notification, the subscription status is changed from processing to completed; or, when no feedback message is received from the loader component regarding the update notification within a preset time period, the subscription status is changed from processing to failed.

[0169] In the disclosed embodiment, after sending the update notification, the subscription service is configured to wait for the loader component to send a feedback message. These feedback messages indicate whether the loader component has successfully received the update notification and performed corresponding processing.

[0170] Update subscription status: If the service receives feedback from the loader component within the preset time, and the feedback indicates that the processing is successful, the service will change the subscription status from "Processing" to "Completed". If the preset time has passed and no feedback is received, the service will change the subscription status to "Failed" and may trigger the corresponding alarm or notification mechanism.

[0171] By receiving feedback messages from the loader component and updating the subscription status, the configuration subscription service can track the processing of update notifications and take appropriate measures. This mechanism helps ensure the reliable delivery and processing of update notifications, while improving the maintainability and user experience of the system. In actual applications, the setting of the preset duration needs to be adjusted according to the actual situation and needs of the system to ensure that the alarm is not triggered too frequently and the waiting time for the unresponsive loader component is too long.

[0172] In a preferred embodiment, the configuration subscription service is further used to: upon receiving a subscription request sent by any of the monitoring and subscription service modules, query whether there is a corresponding trigger in the configuration database according to the subscribed configuration item identifier carried in the subscription request; if no corresponding trigger is found in the configuration database, create a trigger in the configuration database using an SQL statement, and set the trigger on the configuration item identifier corresponding to the subscription request; or, if a corresponding trigger is found in the configuration database, set the queried trigger on the configuration item identifier corresponding to the subscription request;

[0173] In the disclosed embodiment, in the configuration subscription service, when a subscription request sent by the monitoring and subscription service module is received, the service needs to check whether there is a corresponding trigger in the configuration database, and take corresponding actions based on the check result to ensure that notifications can be sent to subscribers when configuration items are updated.

[0174] Parsing subscription request: The configuration subscription service first parses the subscription request sent by the listening and subscription service module, and extracts the subscribed configuration item identifier (such as the name or ID of the configuration item) from it.

[0175] Query triggers: Use the configuration item identifier as the query condition to query the configuration database for triggers associated with the configuration item. This usually involves executing an SQL query to check whether the trigger table (if there is a dedicated trigger table in the system) or the configuration item table contains relevant information about the trigger.

[0176] Create a trigger (if it does not exist): If the corresponding trigger is not found in the configuration database, the configuration subscription service will use SQL statements to create a new trigger in the configuration database. This trigger will be set on the configuration item identifier corresponding to the subscription request so that it will be automatically triggered when the data of the configuration item changes. The trigger creation statement will define the trigger triggering time (such as after INSERT, UPDATE, DELETE operations), the triggering conditions, and the operations to be performed when the trigger is triggered (such as adding update notifications to the message queue).

[0177] Set existing trigger (if it exists): If the corresponding trigger is found in the configuration database, the configuration subscription service will confirm that the trigger has been set on the configuration item identifier corresponding to the subscription request. This step is mainly to ensure the correct association of the trigger with the configuration item, although in most cases, if the trigger already exists and is correctly associated, no additional setup operation is required.

[0178] By querying and creating triggers, the configuration subscription service can ensure that a series of actions are automatically triggered when a configuration item is updated, thereby sending update notifications to subscribers. The use of triggers reduces the need for services to poll for configuration item update events, improving the system's responsiveness and efficiency.

[0179] The configuration subscription service is used to send an update notification to the loader component corresponding to the subscription request when the required configuration item is updated, including: when the required configuration item is updated, sending an update notification to the loader component corresponding to the subscription request through the trigger set on the configuration item identifier.

[0180] In specific implementation, triggers are activated: When the data of a configuration item changes in the configuration database (such as through other services or manual updates by administrators), the previously set triggers will be activated.

[0181] Execute trigger action: When the trigger is activated, the action defined in it is executed. In this scenario, the trigger action is usually to add an update notification to the message queue, which contains the updated configuration item identifier, new value, and possibly other relevant information.

[0182] Notify loader components: Configure the subscription service (or another service that collaborates with it) to listen to the message queue. When a new update notification is detected, it is taken out of the queue and the loader components that need to receive the notification are determined based on the information in the notification. The service then sends update notifications to these loader components through an appropriate communication mechanism (such as HTTP requests, Web Socket connections, etc.).

[0183] Through the automatic triggering of triggers and the asynchronous processing mechanism of message queues, the subscription service can efficiently send update notifications to subscribers. This approach not only reduces the coupling of the system, but also improves the scalability and reliability of the system. At the same time, since the trigger is a database-level function, it can ensure the consistency and integrity of data at the database level.

[0184] The technical solution provided by the present disclosure not only significantly improves the efficiency and flexibility of application configuration management, but also realizes a unified view of application configuration through centralized database storage, which is convenient for operation and maintenance personnel to perform global management and monitoring. It also supports dynamic loading of configuration information, and the hot loading mechanism ensures that configuration changes can take effect in real time without restarting the application system, which greatly reduces maintenance costs and improves the continuous availability of the system, and can achieve immediate effect and zero downtime updates. The application system no longer directly relies on configuration files, but obtains configurations through service subscriptions, which enhances the decoupling between the modules of the system, promotes the scalability and maintainability of the system, and enhances decoupling and modularization. Strict permission management and version control mechanisms ensure the security of configuration operations, and also provide the ability to quickly recover from faults, ensuring the stability and traceability of configuration information. Security and controllability are improved. Reduce the number of service interruptions and restarts caused by configuration changes, improve operation and maintenance efficiency and business continuity, and improve operation and maintenance efficiency.

[0185] The preferred embodiments of the present disclosure are described in detail above in conjunction with the accompanying drawings; however, the present disclosure is not limited to the specific details in the above embodiments; within the technical concept of the present disclosure, various changes, modifications, substitutions and variations may be made to these embodiments, and these changes, modifications, substitutions and variations all fall within the protection scope of the present disclosure.

[0186] It should also be noted that the various specific technical features described in the above specific embodiments can be combined in any appropriate manner without contradiction, which should also be regarded as the content disclosed by this disclosure. In order to avoid unnecessary repetition, this disclosure will not further explain various possible combinations. The technical scope of this application is not limited to the content in the specification.

Claims

1. A system for unified loading and hot updating of dynamic application configuration, characterized in that: The system comprises: Listening and subscription service modules, loader components, and configuration databases; Wherein, the monitoring and subscription service module and the loader component are both configured in the application, and the configuration database has a configuration subscription service; The monitoring and subscription service module is used to determine the required configuration items of the application each time the application is started, and register a subscription request for the required configuration items corresponding to the application with the configuration subscription service in the configuration database; The configuration subscription service is used to receive subscription requests for the required configuration items registered by the monitoring and subscription service module of each application, and send update notifications to the loader component corresponding to the subscription request when there is an update to the required configuration items; The loader component is used to receive the update notification sent by the configuration subscription service, and query the corresponding configuration information from the configuration database by reflection according to the configuration item identifier carried in the update notification, and dynamically update it to the memory of the application, so as to realize the unified loading and hot update of the dynamic configuration of the application, wherein the configuration item identifier and the configuration information are stored in the configuration database in the form of a key-value pair; The loader component is used to query the corresponding configuration value from the configuration database and update it to the memory of the application by reflection according to the configuration item identifier carried in the update notification, so as to realize the unified loading and hot update of the dynamic configuration of the application, including: The loader component is used to dynamically map the configuration item identifier carried in the update notification to the mapping of the field of the class in the memory of the application by scanning the annotation on the class; If the target class field corresponding to the configuration item identifier is found in the mapping of the class field, accessing the target class field of the application by using reflection to obtain the type of the target class field; Converting a new value corresponding to the configuration item identifier queried from the configuration database into a type of the target class field of the application; Using reflection, updating the value of the target class field in the application memory according to the new value after type conversion; The loader component is used to dynamically map the configuration item identifier carried in the update notification to the mapping of the field of the class in the memory of the application by scanning the annotation on the class, including: The loader component is used to scan annotations on all classes of the application through a scanner, wherein the application uses annotations to mark fields whose values ​​need to be read from the configuration; For each annotation on the scanned class, record the configuration item identifier of the annotation and the corresponding field; Dynamically mapping the configuration item identifier carried in the update notification to the recorded mapping of the fields of the in-memory class of the application; The loader component is used to scan annotations on all classes of the application through a scanner, including: Access the Spring context of the application by implementing the Application Context Aware interface; Traverse all beans in the context environment through a custom Bean Post Processor to check whether the Config Value annotation is used on the field of each bean; Use Environment or Property Sources Placeholder Configurer to read the fields marked on the application that need to read values ​​from the configuration.

2. The system according to claim 1, characterized in that The configuration subscription service is also used to: Receiving an access modification request from any permission account, wherein the access modification request carries the access and modification permissions of the permission account, and the access and modification permissions are used to determine the corresponding configuration scope to be accessed and modified in the configuration database; According to the configuration range corresponding to the access and modification authority carried in the access modification request, find the corresponding modification target location, and record the configuration change information carried in the access modification request through the authority control and audit log of the configuration database; The old value of the configuration information corresponding to the modification target position is queried, and the old value is replaced with the corresponding new value in the configuration change information, so as to generate the update notification for the existence of an update for the required configuration item.

3. The system according to claim 2, characterized in that The configuration subscription service is further used to generate a new version number according to the new value based on the operation of replacing the old value with the corresponding new value in the configuration change information, and associate the version number corresponding to the old value with the version number of the new value and save it as a historical version; The loader component is further configured to generate a rollback request according to the new value when the new value causes an abnormality in the application system; The configuration subscription service is also used to receive a rollback request sent by any of the applications, and query the corresponding abnormal version number based on the new value carried in the rollback request, and query the corresponding target historical version based on the abnormal version number, and send the old value corresponding to the target historical version as a new rollback value to the application with the system abnormality, so that the application with the system abnormality can be reconfigured according to the new rollback value.

4. The system according to claim 1, characterized in that The configuration database stores the configuration item identifier and the configuration information in the form of a key-value pair, including: The configuration database generates a key-value pair including the configuration item identifier and the configuration information using any one of a string, a Boolean value, a number, and a JSON object, wherein the configuration information includes at least one of the following: a dictionary tag, a configuration value, a configuration description, an effective range, and a version number.

5. The system according to any one of claims 1 to 4, characterized in that: The configuration subscription service is used to send an update notification to the loader component corresponding to the subscription request when the required configuration item is updated, including: In the case where the required configuration item is updated, a message queue of the loader component corresponding to the subscription request is constructed based on a persistently stored database table according to the time when the subscription request is received, wherein the database table includes a database table creation time, a subscription time, and a subscription status; Sending the update notification to the loader components in the message queue in sequence; When a feedback message is received from the loader component regarding the update notification, the subscription status is changed from processing to completed; or, when no feedback message is received from the loader component regarding the update notification within a preset time period, the subscription status is changed from processing to failed.

6. The system according to any one of claims 1 to 4, characterized in that: The configuration subscription service is further used to: upon receiving a subscription request sent by any of the monitoring and subscription service modules, query whether a corresponding trigger exists in the configuration database according to the subscribed configuration item identifier carried in the subscription request; If no corresponding trigger is found in the configuration database, a trigger is created in the configuration database using an SQL statement, and the trigger is set on the configuration item identifier corresponding to the subscription request; Alternatively, if a corresponding trigger is found in the configuration database, the found trigger is set on the configuration item identifier corresponding to the subscription request; The configuration subscription service is used to send an update notification to the loader component corresponding to the subscription request when the required configuration item is updated, including: when the required configuration item is updated, sending an update notification to the loader component corresponding to the subscription request through the trigger set on the configuration item identifier.

Citation Information

Patent Citations

  • Process-oriented service configuration management and integration tool and method

    CN112114893A

  • Data subscription method and system, electronic equipment and storage medium

    CN116915846A