CN118158086A - Distributed microservice updating method and device, electronic equipment and storage medium - Google Patents
Distributed microservice updating method and device, electronic equipment and storage medium Download PDFInfo
- Publication number
- CN118158086A CN118158086A CN202410189850.4A CN202410189850A CN118158086A CN 118158086 A CN118158086 A CN 118158086A CN 202410189850 A CN202410189850 A CN 202410189850A CN 118158086 A CN118158086 A CN 118158086A
- Authority
- CN
- China
- Prior art keywords
- configuration
- configuration file
- file
- service
- distributed
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 56
- 238000012544 monitoring process Methods 0.000 claims abstract description 12
- 238000013507 mapping Methods 0.000 claims description 12
- 238000004458 analytical method Methods 0.000 claims description 10
- 230000008859 change Effects 0.000 description 10
- 230000006870 function Effects 0.000 description 9
- 238000012545 processing Methods 0.000 description 9
- 238000012423 maintenance Methods 0.000 description 8
- 238000007726 management method Methods 0.000 description 7
- 230000008569 process Effects 0.000 description 7
- 238000012360 testing method Methods 0.000 description 5
- 238000010586 diagram Methods 0.000 description 4
- 230000004048 modification Effects 0.000 description 4
- 238000012986 modification Methods 0.000 description 4
- 238000004590 computer program Methods 0.000 description 3
- 241000412611 Consul Species 0.000 description 2
- 230000005540 biological transmission Effects 0.000 description 2
- 238000004891 communication Methods 0.000 description 2
- 238000005516 engineering process Methods 0.000 description 2
- 230000007246 mechanism Effects 0.000 description 2
- 238000004806 packaging method and process Methods 0.000 description 2
- 230000002093 peripheral effect Effects 0.000 description 2
- 230000009471 action Effects 0.000 description 1
- 230000006399 behavior Effects 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000008901 benefit Effects 0.000 description 1
- 230000001413 cellular effect Effects 0.000 description 1
- 238000004883 computer application Methods 0.000 description 1
- 238000013500 data storage Methods 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 238000011835 investigation Methods 0.000 description 1
- 238000011022 operating instruction Methods 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000000750 progressive effect Effects 0.000 description 1
- 238000010926 purge Methods 0.000 description 1
- 230000009467 reduction Effects 0.000 description 1
- 230000008439 repair process Effects 0.000 description 1
- 230000003068 static effect Effects 0.000 description 1
- 230000009466 transformation Effects 0.000 description 1
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L41/00—Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
- H04L41/08—Configuration management of networks or network elements
- H04L41/0803—Configuration setting
- H04L41/0823—Configuration setting characterised by the purposes of a change of settings, e.g. optimising configuration for enhancing reliability
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
- G06F8/427—Parsing
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/60—Software deployment
- G06F8/65—Updates
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/445—Program loading or initiating
- G06F9/44505—Configuring for program initiating, e.g. using registry, configuration files
- G06F9/4451—User profiles; Roaming
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/10—Protocols in which an application is distributed across nodes in the network
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/2866—Architectures; Arrangements
- H04L67/30—Profiles
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Computer Security & Cryptography (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The application discloses a method, a device, electronic equipment and a storage medium for updating distributed micro-services, wherein the method comprises the following steps: monitoring the configuration files of the configuration center through a monitor of the distributed micro-service; acquiring a changed configuration file when the configuration file of the configuration center is monitored to be changed; analyzing the changed configuration file through a file analyzer corresponding to the file type of the configuration file to obtain an update parameter of the distributed micro service, and loading the update parameter to the distributed micro service to update the distributed micro service.
Description
Technical Field
The present application relates to the field of computer applications, and in particular, to a method and apparatus for updating distributed microservices, an electronic device, and a storage medium.
Background
The distributed micro-service is an architecture model designed based on a distributed architecture and a micro-service concept, and the system is split into a plurality of service units, and each service unit is independent from the other service units. At present, a maintenance stopping mode is generally adopted for updating distributed micro-services, and the maintenance stopping mode comprises a series of operations of stopping service, downloading, modifying, testing, packaging, redeploying, uploading and the like on source codes.
However, the operation flow of repairing through stopping service is complicated, and a great deal of time and labor are consumed, so that the repairing, testing and updating equivalent rate of the system in the operation and maintenance stage is reduced, and the user experience is further affected.
Disclosure of Invention
The embodiment of the application aims to provide a method, a device, electronic equipment and a storage medium for updating distributed micro-services, which are used for solving the problems of repair, test and update efficiency reduction and influence on user experience in the existing updating process of the distributed micro-services.
In order to achieve the above object, the embodiment of the present application adopts the following technical scheme:
in a first aspect, an embodiment of the present application provides a method for updating a distributed microservice, including:
Monitoring the configuration files of the configuration center through a monitor of the distributed micro-service;
Acquiring a changed configuration file when the configuration file of the configuration center is monitored to be changed;
Analyzing the changed configuration file through a file analyzer corresponding to the file type of the configuration file to obtain an update parameter of the distributed micro service, and loading the update parameter to the distributed micro service to update the distributed micro service.
In a second aspect, an embodiment of the present application provides an update apparatus for a distributed microservice, including:
the monitoring unit is used for monitoring the configuration file of the configuration center through a distributed microservice monitor;
The acquisition unit is used for acquiring the changed configuration file when the configuration file of the configuration center is monitored to be changed;
the analysis unit is used for analyzing the changed configuration file through a file analyzer corresponding to the file type of the configuration file to obtain the update parameters of the distributed micro-service, and loading the update parameters to the distributed micro-service to update the distributed micro-service.
In a third aspect, an embodiment of the present application provides an electronic device, including: a processor; a memory for storing the processor-executable instructions; wherein the processor is configured to execute the instructions to implement the method of updating a distributed microservice as described in the first aspect.
In a fourth aspect, embodiments of the present application provide a computer readable storage medium, which when executed by a processor of an electronic device, enables the electronic device to perform the method of updating a distributed microservice as described in the first aspect.
The above at least one technical scheme adopted by the embodiment of the application can achieve the following beneficial effects: by sensing the change of the configuration file of the configuration center, under the condition that the change of the configuration file of the configuration center is monitored, the changed configuration file is obtained from the configuration center, the file analyzer corresponding to the file type of the configuration file is utilized to analyze the configuration file to obtain update parameters, the update parameters are loaded to the distributed micro-service, the distributed micro-service is updated without stopping, going offline, modifying source code files and other operations, dynamic update can be realized during service operation, in addition, a plurality of services can simultaneously load the configuration file of the configuration center to realize the uniformity of service configuration by uniformly and centrally managing the configuration file of the distributed micro-service by the configuration center, each micro-service can obtain the changed configuration file from the configuration center and update the configuration file without independently configuring one configuration file for different micro-services or performing stopping service modification for each micro-service, and further realizing the thermal update of each micro-service in the distributed system.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this specification, illustrate embodiments of the application and together with the description serve to explain the application and do not constitute a limitation on the application. In the drawings:
FIG. 1 is a flow chart of a method for updating distributed microservices according to an embodiment of the present application;
fig. 2 is a schematic application scenario diagram of another method for updating distributed microservices according to an embodiment of the present application;
FIG. 3 is a schematic diagram of a distributed microservice update device according to an embodiment of the present application;
Fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the technical solutions of the present application will be clearly and completely described below with reference to specific embodiments of the present application and corresponding drawings. It will be apparent that the described embodiments are only some, but not all, embodiments of the application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
The terms first, second and the like in the description and in the claims, are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate to implement embodiments of the application in a sequence other than those illustrated or described herein. Furthermore, in the present specification and claims, "and/or" means at least one of the connected objects, and the character "/" generally means a relationship in which the associated object is an "or" before and after.
The following describes in detail the technical solutions provided by the embodiments of the present application with reference to the accompanying drawings.
Distributed microservices are one design way to combine distributed systems and microservice architectures. Under this architecture, a large system is split into multiple small, independently running micro-services, which may be distributed across different computers or physical locations. At present, a maintenance stopping mode is generally adopted for updating distributed micro-services, and the maintenance stopping mode comprises a series of operations of stopping service, downloading, modifying, testing, packaging, redeploying, uploading and the like on source codes.
However, the operation flow of repairing through stopping service is complicated, and a great deal of time and labor are consumed, so that the repairing, testing and updating equivalent rate of the system in the operation and maintenance stage is reduced, and the user experience is further affected.
In view of this, the embodiment of the present application provides a method for updating distributed micro services, by sensing a change of a configuration file of a configuration center, acquiring the changed configuration file from the configuration center when the configuration file of the configuration center is monitored, analyzing the configuration file by using a file analyzer corresponding to a file type of the configuration file to obtain an update parameter, loading the update parameter to the distributed micro service, and updating the distributed micro service, without operations such as stopping service, going offline, modifying a source code file, and the like, and also implementing dynamic update during service operation.
Specifically, referring to fig. 1, a flowchart of a method for updating a distributed microservice according to an embodiment of the present application is shown. As shown in fig. 1, a method for updating a distributed micro service according to an embodiment of the present application may include the following steps:
S102, monitoring the configuration files of the configuration center through the monitors of the distributed micro-service.
The distributed micro-service is an architecture mode, and by splitting a large application program into a plurality of small and autonomous service units, each service unit can be independently deployed, expanded and managed, and is focused on executing specific business functions and interacting with other micro-services through a network communication protocol.
Where a listener is a mechanism for monitoring and responding to events, changes, or messages, either internal or external to the system.
Wherein the configuration center is a service or tool for centrally managing configuration information. In distributed microservices, it is often necessary to configure a series of parameters, such as database connection information, log levels, cache configuration, etc., which are centrally stored, managed by a configuration center, and provide a mechanism for the distributed microservices to obtain these parameters from the configuration center. In the embodiment of the application, the configuration center can be Nacos distributed service discovery and configuration management system or Consul distributed service discovery and management system. Wherein Nacos is an open-source platform for service discovery, configuration management, and service management, providing a simple and efficient way to perform dynamic service discovery, service configuration, and service metadata management; consul is an open-source distributed service grid solution that provides powerful service discovery and configuration management tools that help build reliable, resilient distributed systems. Specifically, an appropriate configuration center may be selected according to the requirement of the project, which is not particularly limited in the embodiment of the present application.
According to the embodiment of the application, the configuration files of the configuration center are monitored through the monitor of the distributed micro service, so that the change of the configuration files of the configuration center is perceived in real time, and further the distributed micro service is updated thermally according to the changed configuration files in the configuration center. Specifically, the following steps or examples will be explained.
As another alternative embodiment, before S102, the method may further include the following steps: acquiring a server address of a configuration center;
connecting a registry of the configuration center based on the server address;
The listeners of the distributed microservice are registered to a registry of the configuration center.
The server address of the configuration center refers to a network address or a domain name of the configuration center, such as an IP address, and is used to identify or locate the position of the configuration center, so that the distributed micro service can establish a connection with the configuration center and perform communication.
The registry of the configuration center records information of each micro service, and the information comprises configuration files for configuring each micro service. The server address of the configuration center is connected to the registry of the configuration center, and relevant information is obtained by accessing the registry.
According to the embodiment of the application, the configuration files for configuring the distributed micro-services are stored in the configuration center, the configuration center is used for uniformly managing and adjusting the configuration of the system, a plurality of services can simultaneously load the configuration files of the configuration center, the uniformity of the configuration of each service is realized, only one configuration file needs to be modified, each micro-service obtains the changed configuration file from the configuration center for updating, one configuration file does not need to be configured for different micro-services independently, and the shutdown modification is not needed for each micro-service, so that the thermal updating of each micro-service in the distributed system is realized. The configuration file for configuring the distributed micro-service may be in xml format or other format, for example: yaml, html, text, or the like, or may be stored in the configuration center in the form of key value pairs.
Specifically, as another alternative embodiment, in the case where the existing form of the configuration file of the configuration center includes the key value pair, the following steps may be further included before S102: acquiring a configuration file for configuring the distributed micro-service;
based on a preset coding mode, coding the configuration file to obtain a character string corresponding to the configuration file;
And storing the file identification of the configuration file and the character string in the form of key value pairs to a configuration center, wherein the character string is a value of the key value pairs, and the file identification of the configuration file is a key of the key value pairs.
The configuration file is encoded, so that the system is prevented from being attacked due to data leakage in the configuration file, the safety and stability of the system are improved, meanwhile, whether the configuration file is changed or not can be monitored more conveniently by encoding the configuration file into character strings, and if the configuration file is changed, the obtained character strings are different from the character strings corresponding to the configuration file before the history change, and the configuration file is judged to be changed. Common coding schemes, for example: base64 coding, hex coding, UTF-8 (Unicode Transformation Format-8-bit), and so on. The Base64 codes are coded by using printable character sets, are easier to process and transmit, have compactness and higher security, are widely used, have libraries or functions for providing corresponding codes and decoding in most programming languages and applications, are easier to exchange data between different systems and platforms, and are very important as a lossless coding mode for application scenes requiring accurate restoration of original data. Based on the above, the embodiment of the application preferentially adopts Base64 coding to code the configuration file.
As an alternative, if a higher security level storage mode is considered, an encryption algorithm such as: symmetric encryption algorithms AES (Advanced Encryption Standard) and AES (Advanced Encryption Standard), asymmetric encryption algorithms RSA (Rivest-Shamir-Adleman) and ECC (Elliptic Curve Cryptography), and the like encrypt the configuration files, and store the encrypted configuration files in a configuration center for each micro-service to acquire. Specifically, the configuration may be set according to actual needs, and the embodiment of the present application is not particularly limited thereto.
Where file identification refers to information or tags that are used to uniquely identify or identify a configuration file. May be a file name or other parameter that can be used to uniquely identify a configuration file.
The key value pair is a data storage and expression mode, and consists of a key and a value. The key is an identifier or name of the target storage data for uniquely identifying the target storage data. The value is the target storage data. The content data of the configuration file is used as the value of the key value pair, and the file identification of the configuration file is used as the key of the key value pair, so that unified management and adjustment of the configuration file by the configuration center are realized, and the configuration file is conveniently searched and compared to find whether the configuration file is updated and changed.
The embodiment of the application obtains the corresponding character string by coding the configuration file for configuring the distributed micro-service, stores the corresponding character string in the configuration center in the form of key value pairs, and is convenient for searching and comparing the configuration file in the configuration center according to the key value pairs while ensuring the safety of data in the configuration file so as to find out whether the configuration file of the configuration center is updated and changed.
Specifically, as an alternative embodiment, in a case where the existing form of the configuration file of the configuration center includes a key value pair, the step S102 may include the following steps: acquiring the latest key value pair from a configuration center through the monitor;
acquiring a history key value pair from a configuration center, wherein the key of the history key value pair is the same as the key of the latest key value pair;
Comparing the value of the latest key value pair with the value of the historical key value pair;
based on the comparison result, it is determined whether a change has occurred in the configuration file of the configuration center.
The history key value pair is obtained by storing and configuring the center in the form of key value pair based on the configuration file before modification.
It should be understood that when the configuration file is stored in the configuration center in the form of a key value pair, a corresponding configuration item is formed in a registry of the configuration center, the distributed micro service senses the newly added configuration item through the monitor, finds a history key value pair identical to a key of the latest key value pair according to the key value pair corresponding to the newly added configuration item, namely the latest key value pair, and judges whether the configuration file of the configuration center is changed by comparing the value of the latest key value pair with the value of the history key value pair. As an alternative way, if the value of the latest key value pair is the same as the value of the historical key value pair, determining that the configuration file of the configuration center is not changed; if the value of the latest key value pair is different from the value of the historical key value pair, the configuration file of the configuration center is determined to be changed.
As an alternative implementation manner, in the case of performing an encoding operation on a configuration file for configuring a distributed micro service to obtain a corresponding character string, and storing the corresponding character string as a value of a key value pair in a configuration center in the form of a key value, the configuration file of the configuration center may be determined not to be changed by comparing the character string corresponding to the value of the latest key value pair with the character string corresponding to the value of the historical key value pair if the character strings are the same; if the character strings are different, the configuration file of the configuration center is determined to be changed.
As an alternative, the value of the latest key value pair is compared with the value of the history key value pair, and the comparison result may include changed data, newly added data, missing data, and the like. If the comparison result has changed data, or newly added data, or missing data, the configuration file of the configuration center is determined to be changed; if the comparison result has no changed data, no newly added data, no missing data and the like, the configuration file of the configuration center is determined to be unchanged.
In the embodiment of the application, under the condition that the configuration file of the configuration center exists in the form of key value pairs, the latest key value pairs are acquired in real time through the monitors of the distributed micro-service, so that the micro-service can acquire the relevant information of the configuration file in time, the latest key value pairs are compared with the historical key value pairs which are the same as keys, whether the configuration file of the configuration center is changed or not is determined, and further the distributed micro-service is subjected to hot update, meanwhile, the micro-service is facilitated to know the change content, the later investigation of problems, rollback configuration and other operations are facilitated, and the real-time performance and efficiency of system maintenance are improved.
S104, when the configuration file of the configuration center is monitored to be changed, the changed configuration file is acquired.
Specifically, in the case where the configuration file of the configuration center is a character string obtained after encoding, as an optional implementation manner, in S104, the obtaining the changed configuration file may include the following steps: acquiring a character string corresponding to the changed configuration file from a configuration center;
And decoding the acquired character strings based on a preset decoding mode to obtain a changed configuration file.
Wherein the decoding mode corresponds to the aforementioned encoding mode, and the decoding operation can be understood as the inverse operation of the encoding operation. Specifically, according to the selected coding mode, a decoding operation is performed by selecting a decoding mode corresponding to the selected coding mode.
According to the embodiment of the application, the configuration file is encoded, so that the system is prevented from being attacked due to data leakage in the configuration file, and the character strings corresponding to the changed configuration file are decoded in a corresponding decoding mode, so that the accuracy of the acquired data in the changed configuration file is ensured, and the stability and the safety of updating of the distributed micro-service system are further improved.
S106, analyzing the changed configuration file through a file analyzer corresponding to the file type of the configuration file to obtain update parameters of the distributed micro service, and loading the update parameters to the distributed micro service to update the distributed micro service.
Wherein the file type of the configuration file is related to the format of the configuration file, such as, but not limited to, xml, yaml, html, text formats. The files of different formats need to be parsed by using corresponding file parsers, for example: for xml files, XMLMapperBuilder resolvers can be used for resolving the changed configuration files to obtain parameters in the configuration files, and the parameters are loaded into the distributed micro-services to update the distributed micro-services.
Wherein the update parameters are a series of parameters required for distributed microservice update, such as database connection information, log level, cache configuration, etc.
It should be understood that in a stand-alone version, the distributed microservices need to be modified for the configuration files of each service, and the configuration files need to be modified are more, so that each update needs to consume a great deal of time and manpower, and the cost of the operation and maintenance of the distributed microservices is increased.
According to the embodiment of the application, under the condition that the configuration file of the configuration center is monitored to change, the changed configuration file is obtained from the configuration center, the configuration file is analyzed by the file analyzer corresponding to the file type of the configuration file to obtain the update parameters, the update parameters are loaded to the distributed micro-service, the distributed micro-service is updated without stopping, going off line, modifying the source code file and other operations, and the dynamic update can be realized during service operation.
Specifically, as an optional implementation manner, in S106, the step of analyzing, by the file analyzer corresponding to the file type of the configuration file, the changed configuration file to obtain the updated parameters of the distributed micro service may include the following steps:
creating a mapping object in an analysis method of a file analyzer, and loading the changed configuration file into the mapping object;
and executing an analysis method, and analyzing the changed configuration file to obtain the updated parameters of the distributed micro-service.
Wherein a mapping object refers to a data structure created when parsing a configuration file, for example: dictionary mapping, etc. for storing information in the configuration file for subsequent use, associating various configuration items in the configuration file with the mapping objects, and obtaining relevant data in the configuration file by querying the mapping objects after parsing.
The embodiment of the application stores the configuration file by creating the mapping object, so that the configuration information is more organized, is convenient to inquire and access, and can load the update parameters obtained through analysis to the distributed micro-service or delete the update parameters from the distributed micro-service through the mapping object, thereby being easy to manage, enabling the system to respond to the configuration change quickly and realizing the dynamic update of the distributed micro-service.
As another optional embodiment, in S106, before loading the update parameter into the distributed micro service to update the distributed micro service, the method may further include the following steps: determining target cache data related to the distributed micro-service from a local cache of the distributed micro-service based on the file identification of the changed configuration file;
clearing the target cache data from the local cache;
and loading the update parameters to the local cache.
Wherein, the cache refers to a quick access layer for storing temporary data.
The target cache data related to the distributed micro service may be a parameter obtained by analyzing the history configuration file, or may be other data that may affect the update.
It should be appreciated that the distributed microservices may use caches to store parameters and other data needed for configuration during operation, and if historical data in the caches is not cleared in time, historical parameters or expired data may continue to be used, resulting in uncertain behavior and causing system errors.
Before loading the update parameters into the distributed micro-service, the embodiment of the application firstly analyzes the parameters obtained by analyzing the history configuration file and the data which possibly influence the update, clears the parameters from the local of the distributed micro-service, ensures the consistency of system configuration, and avoids continuously using the history parameters or the expiration data, thereby enabling the latest configuration information or parameters to be obtained from the local cache before updating the distributed micro-service, realizing dynamic update without restarting the service.
The following describes the method for updating the distributed microservice provided by the embodiment of the present application by a complete example, which should not be construed as limiting the method of the embodiment of the present application. Referring to fig. 2, a flow chart of another method for updating distributed microservices according to an embodiment of the present application is shown.
In this example, the distributed micro-services can be developed and implemented by using Spring Boot or the like in Java, namely, java services; nacos is a configuration center; the configuration file for configuring the Java service is in an xml format, that is, an xml file, a corresponding character string is obtained after encoding by Base64 and is stored in the configuration center Nacos in the form of a key value pair, a key of the key value pair is a file identifier of the configuration file, such as a file name, and a value of the key value pair is a character string corresponding to the configuration file.
First, the Java service registers the listener to Nacos, and when it is detected that there is a newly added key value pair in Nacos, it compares whether the values between the newly added key value pair and the history key value pair are the same according to the key of the key value pair, and determines whether the configuration file is changed. When the configuration file in Nacos is monitored to be changed, base64 decoding is carried out on the value of the newly added key value pair, the changed configuration file is obtained, the updated parameter is obtained through analysis by an xml file analyzer, the historical parameter and related data of Java service in a local cache are cleared according to the key of the newly added key value pair, the updated parameter is loaded into the cache, and the updated parameter is obtained from the cache in the running process of the Java service, so that dynamic updating is realized.
The foregoing describes specific embodiments of the present disclosure. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims can be performed in a different order than in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
Corresponding to the above-mentioned method for updating the distributed micro-service shown in fig. 1, the embodiment of the application also provides a device for updating the distributed micro-service. Referring to fig. 3, a schematic structural diagram of a distributed micro-service updating apparatus 300 according to an embodiment of the application is shown, where the apparatus 300 includes: listening unit 310, acquisition unit 320 and parsing unit 330.
The monitoring unit 310 is configured to monitor, by using a monitor of the distributed microservice, a configuration file of the configuration center.
The obtaining unit 320 is configured to obtain the changed configuration file when it is monitored that the configuration file of the configuration center is changed.
The parsing unit 330 is configured to parse the changed configuration file through a file parser corresponding to the file type of the configuration file to obtain an update parameter of the distributed micro service, and load the update parameter to the distributed micro service to update the distributed micro service.
Optionally, the obtaining unit 320 is further configured to, before the listening unit 310 listens for the configuration file of the configuration center by using the listeners of the distributed micro service, perform the following steps: acquiring a server address of the configuration center;
Connecting a registry of the configuration center based on the server address;
registering listeners of the distributed microservice to a registry of the configuration center.
Optionally, in the case that the existing form of the configuration file of the configuration center includes a key value pair, the obtaining unit 320 is further configured to perform, before the listening unit 310 listens for the configuration file of the configuration center by the listener of the distributed micro service, the following steps: acquiring a configuration file for configuring the distributed micro-service;
based on a preset coding mode, coding the configuration file to obtain a character string corresponding to the configuration file;
and storing the file identification of the configuration file and the character string into the configuration center in the form of key value pairs, wherein the character string is the value of the key value pairs, and the file identification of the configuration file is the key of the key value pairs.
Optionally, when the listener of the distributed micro service listens to the configuration file of the configuration center, the listening unit 310 performs the following steps: acquiring, by the listener, a latest key value pair from the configuration center;
acquiring a history key value pair from the configuration center, wherein the key of the history key value pair is the same as the key of the latest key value pair;
Comparing the value of the most recent key value pair with the value of the historical key value pair;
and determining whether the configuration file of the configuration center is changed or not based on the comparison result.
Optionally, the obtaining unit 320 performs the following steps when obtaining the changed configuration file: acquiring a character string corresponding to the changed configuration file from the configuration center;
and decoding the acquired character strings based on a preset decoding mode to obtain the changed configuration file.
Optionally, when the parsing unit 330 parses the changed configuration file by using a file parser corresponding to the file type of the configuration file to obtain the updated parameters of the distributed micro service, the following steps are executed: creating a mapping object in an analysis method of the file analyzer, and loading the changed configuration file into the mapping object;
and executing the analysis method, and analyzing the changed configuration file to obtain the updated parameters of the distributed micro-service.
Optionally, the apparatus 300 further comprises a purge unit;
The clearing unit is configured to, before the parsing unit 330 loads the update parameter to the distributed micro service to update the distributed micro service, perform the following steps: determining target cache data related to the distributed micro-service from a local cache of the distributed micro-service based on the file identification of the changed configuration file;
Clearing the target cache data from the local cache;
and loading the update parameters to the local cache.
It is obvious that the update apparatus of the distributed micro service provided in the embodiment of the present application can be used as an execution subject of the update method of the distributed micro service shown in fig. 1, for example, in the update method of the distributed micro service shown in fig. 1, the step S102 may be executed by the listening unit 310 in the update apparatus 300 of the distributed micro service shown in fig. 3, the step S104 may be executed by the obtaining unit 320 in the update apparatus 300 of the distributed micro service shown in fig. 3, and the step S106 may be executed by the parsing unit 330 in the update apparatus 300 of the distributed micro service shown in fig. 3.
According to another embodiment of the present application, each unit in the distributed micro-service updating apparatus shown in fig. 3 may be separately or completely combined into one or several other units, or some unit(s) thereof may be further split into a plurality of units with smaller functions, which may achieve the same operation without affecting the implementation of the technical effects of the embodiments of the present application. The above units are divided based on logic functions, and in practical applications, the functions of one unit may be implemented by a plurality of units, or the functions of a plurality of units may be implemented by one unit. In other embodiments of the present application, the updating apparatus of the distributed microservice may also include other units, and in practical applications, these functions may also be implemented with assistance of other units, and may be implemented by cooperation of multiple units.
According to another embodiment of the present application, the updating apparatus of the distributed micro service as shown in fig. 3 may be constructed by running a computer program (including a program code) capable of executing the steps involved in the corresponding method as shown in fig. 1 on a general-purpose computing device such as a computer including a processing element such as a central processing unit (Central Processing Unit, CPU), a random access storage medium (Random Access Memory, RAM), a Read-Only Memory (ROM), and a storage element, and the updating method of the distributed micro service of the embodiment of the present application may be implemented. The computer program may be recorded on, for example, a computer readable storage medium, transferred to, and run in, an electronic device via the computer readable storage medium.
Fig. 4 is a schematic structural view of an electronic device according to an embodiment of the present application. Referring to fig. 4, at the hardware level, the electronic device includes a processor, and optionally an internal bus, a network interface, and a memory. The Memory may include a Memory, such as a Random-Access Memory (RAM), and may further include a non-volatile Memory (non-volatile Memory), such as at least 1 disk Memory. Of course, the electronic device may also include hardware required for other services.
The processor, network interface, and memory may be interconnected by an internal bus, which may be an ISA (Industry Standard Architecture ) bus, a PCI (PERIPHERAL COMPONENT INTERCONNECT, peripheral component interconnect standard) bus, or EISA (Extended Industry Standard Architecture ) bus, among others. The buses may be classified as address buses, data buses, control buses, etc. For ease of illustration, only one bi-directional arrow is shown in FIG. 4, but not only one bus or type of bus.
And the memory is used for storing programs. In particular, the program may include program code including computer-operating instructions. The memory may include memory and non-volatile storage and provide instructions and data to the processor.
The processor reads the corresponding computer program from the nonvolatile memory into the memory and then runs, forming the data processing device on a logic level. The processor is used for executing the programs stored in the memory and is specifically used for executing the following operations:
Monitoring the configuration files of the configuration center through a monitor of the distributed micro-service;
Acquiring a changed configuration file when the configuration file of the configuration center is monitored to be changed;
Analyzing the changed configuration file through a file analyzer corresponding to the file type of the configuration file to obtain an update parameter of the distributed micro service, and loading the update parameter to the distributed micro service to update the distributed micro service.
The method performed by the distributed micro-service updating apparatus disclosed in the embodiment of fig. 3 of the present application may be applied to a processor or implemented by a processor. The processor may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware in a processor or by instructions in the form of software. The processor may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU), a network processor (Network Processor, NP), etc.; but may also be a digital signal Processor (DIGITAL SIGNAL Processor, DSP), application SPECIFIC INTEGRATED Circuit (ASIC), field-Programmable gate array (Field-Programmable GATE ARRAY, FPGA) or other Programmable logic device, discrete gate or transistor logic device, discrete hardware components. The disclosed methods, steps, and logic blocks in the embodiments of the present application may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present application may be embodied directly in the execution of a hardware decoding processor, or in the execution of a combination of hardware and software modules in a decoding processor. The software modules may be located in a random access memory, flash memory, read only memory, programmable read only memory, or electrically erasable programmable memory, registers, etc. as well known in the art. The storage medium is located in a memory, and the processor reads the information in the memory and, in combination with its hardware, performs the steps of the above method.
The electronic device may also execute the method of fig. 1 and implement the functions of the embodiment shown in fig. 1 and 3 of the update apparatus of the distributed microservice, which are not described herein.
Of course, other implementations, such as a logic device or a combination of hardware and software, are not excluded from the electronic device of the present application, that is, the execution subject of the following processing flows is not limited to each logic unit, but may be hardware or a logic device.
The embodiments of the present application also provide a computer-readable storage medium storing one or more programs, the one or more programs comprising instructions, which when executed by a portable electronic device comprising a plurality of application programs, enable the portable electronic device to perform the method of the embodiment of fig. 1, and in particular to perform the operations of:
Monitoring the configuration files of the configuration center through a monitor of the distributed micro-service;
Acquiring a changed configuration file when the configuration file of the configuration center is monitored to be changed;
Analyzing the changed configuration file through a file analyzer corresponding to the file type of the configuration file to obtain an update parameter of the distributed micro service, and loading the update parameter to the distributed micro service to update the distributed micro service.
In summary, the foregoing description is only of the preferred embodiments of the present application, and is not intended to limit the scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the protection scope of the present application.
The system, apparatus, module or unit set forth in the above embodiments may be implemented in particular by a computer chip or entity, or by a product having a certain function. One typical implementation is a computer. In particular, the computer may be, for example, a personal computer, a laptop computer, a cellular telephone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
Computer readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of storage media for a computer include, but are not limited to, phase change memory (PRAM), static Random Access Memory (SRAM), dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), read Only Memory (ROM), electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices, or any other non-transmission medium, which can be used to store information that can be accessed by a computing device. Computer-readable media, as defined herein, does not include transitory computer-readable media (transmission media), such as modulated data signals and carrier waves.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article or apparatus that comprises the element.
In this specification, each embodiment is described in a progressive manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for system embodiments, since they are substantially similar to method embodiments, the description is relatively simple, as relevant to see a section of the description of method embodiments.
Claims (10)
1. A method for updating a distributed microservice, comprising:
Monitoring the configuration files of the configuration center through a monitor of the distributed micro-service;
Acquiring a changed configuration file when the configuration file of the configuration center is monitored to be changed;
Analyzing the changed configuration file through a file analyzer corresponding to the file type of the configuration file to obtain an update parameter of the distributed micro service, and loading the update parameter to the distributed micro service to update the distributed micro service.
2. The method of claim 1, wherein prior to the listening of the configuration file by the listener of the distributed microservice to the configuration center, the method further comprises:
acquiring a server address of the configuration center;
Connecting a registry of the configuration center based on the server address;
registering listeners of the distributed microservice to a registry of the configuration center.
3. The method of claim 1, wherein the configuration file of the configuration center exists in a form including key-value pairs, and wherein the method further comprises, prior to listening to the configuration file of the configuration center by the listeners of the distributed microservice:
acquiring a configuration file for configuring the distributed micro-service;
based on a preset coding mode, coding the configuration file to obtain a character string corresponding to the configuration file;
and storing the file identification of the configuration file and the character string into the configuration center in the form of key value pairs, wherein the character string is the value of the key value pairs, and the file identification of the configuration file is the key of the key value pairs.
4. The method of claim 3, wherein the listening of the configuration file of the configuration center by the listener of the distributed microservice comprises:
acquiring, by the listener, a latest key value pair from the configuration center;
acquiring a history key value pair from the configuration center, wherein the key of the history key value pair is the same as the key of the latest key value pair;
Comparing the value of the most recent key value pair with the value of the historical key value pair;
and determining whether the configuration file of the configuration center is changed or not based on the comparison result.
5. A method according to claim 3, wherein said obtaining a modified profile comprises:
acquiring a character string corresponding to the changed configuration file from the configuration center;
and decoding the acquired character strings based on a preset decoding mode to obtain the changed configuration file.
6. The method according to claim 1, wherein the parsing the changed configuration file by the file parser corresponding to the file type of the configuration file to obtain the update parameters of the distributed micro service includes:
creating a mapping object in an analysis method of the file analyzer, and loading the changed configuration file into the mapping object;
and executing the analysis method, and analyzing the changed configuration file to obtain the updated parameters of the distributed micro-service.
7. The method of claim 1, wherein prior to said loading the update parameters to the distributed microservice to update the distributed microservice, the method further comprises:
Determining target cache data related to the distributed micro-service from a local cache of the distributed micro-service based on the file identification of the changed configuration file;
Clearing the target cache data from the local cache;
and loading the update parameters to the local cache.
8. An apparatus for updating a distributed microservice, comprising:
the monitoring unit is used for monitoring the configuration file of the configuration center through a distributed microservice monitor;
The acquisition unit is used for acquiring the changed configuration file when the configuration file of the configuration center is monitored to be changed;
the analysis unit is used for analyzing the changed configuration file through a file analyzer corresponding to the file type of the configuration file to obtain the update parameters of the distributed micro-service, and loading the update parameters to the distributed micro-service to update the distributed micro-service.
9. An electronic device, comprising:
A processor;
A memory for storing the processor-executable instructions;
wherein the processor is configured to execute the instructions to implement the method of updating a distributed microservice as claimed in any one of claims 1 to 7.
10. A computer readable storage medium, characterized in that instructions in the storage medium, when executed by a processor of an electronic device, enable the electronic device to perform the method of updating a distributed microservice according to any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202410189850.4A CN118158086A (en) | 2024-02-20 | 2024-02-20 | Distributed microservice updating method and device, electronic equipment and storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202410189850.4A CN118158086A (en) | 2024-02-20 | 2024-02-20 | Distributed microservice updating method and device, electronic equipment and storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN118158086A true CN118158086A (en) | 2024-06-07 |
Family
ID=91296015
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202410189850.4A Pending CN118158086A (en) | 2024-02-20 | 2024-02-20 | Distributed microservice updating method and device, electronic equipment and storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN118158086A (en) |
-
2024
- 2024-02-20 CN CN202410189850.4A patent/CN118158086A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US10769228B2 (en) | Systems and methods for web analytics testing and web development | |
Syer et al. | Continuous validation of performance test workloads | |
US20230237356A1 (en) | Configuration assessment based on inventory | |
CN110908910B (en) | Block chain-based test monitoring method and device and readable storage medium | |
US11373004B2 (en) | Report comprising a masked value | |
US11227051B2 (en) | Method for detecting computer virus, computing device, and storage medium | |
CN110569089A (en) | Plug-in expansion method, device and storage medium for management platform | |
CN111209606A (en) | Method, device and equipment for early warning of hard disk change behind RAID card | |
US10372513B2 (en) | Classification of application events using call stacks | |
CN113094283A (en) | Data acquisition method, device, equipment and storage medium | |
CN112882948A (en) | Stability testing method, device and system for application and storage medium | |
CN111597093B (en) | Exception handling method, device and equipment thereof | |
CN111435327B (en) | Log record processing method, device and system | |
CN114238244B (en) | Result set generation method, device, equipment and storage medium | |
CN118158086A (en) | Distributed microservice updating method and device, electronic equipment and storage medium | |
CN107562790B (en) | Method and system for realizing batch warehousing of data processing | |
CN113672233B (en) | Server out-of-band management method, device and equipment based on Redfish | |
CN112416875B (en) | Log management method, device, computer equipment and storage medium | |
CN116126891A (en) | Database query method and device, electronic equipment and readable storage medium | |
CN109634931B (en) | Log uploading method and device | |
CN109491699B (en) | Resource checking method, device, equipment and storage medium of application program | |
CN108459940B (en) | Configuration information modification method and device of application performance management system and electronic equipment | |
CN113778800A (en) | Error reporting information processing method, device, system, equipment and storage medium | |
CN113553587B (en) | File detection method, device, equipment and readable storage medium | |
CN115842716B (en) | Method, device, equipment and storage medium for determining fault server |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |