A launcher and startup method based on Dubbo-go server
By introducing configuration reader and placeholder replacement mechanism on the Dubbo-go server, combined with a custom configuration center, the flexibility and repetition of configuration management on the Dubbo-go server is solved, and higher configuration adaptability is achieved and maintenance efficiency.
Patent Information
- Application Number
- CN202410313828.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-19
- Publication Date
- 2024-11-29
- Estimated Expiration
- 2044-03-19
AI Technical Summary
The Dubbo-go server lacks flexible configuration management, especially the yaml file configuration does not support the limitations of placeholders and configuration centers, which leads to duplication of configuration values and difficulty in maintaining configuration values.
A launcher and startup method based on Dubbo-go server is designed. The key-value configuration file and yaml configuration file are read through the configuration reader and placeholder replacement is performed. It supports custom configuration center and implements the DubboConfig structure. conversion and loading.
It realizes synchronous use of yaml configuration files and code configurations, supports configuration center, improves configuration flexibility and adaptability, and avoids duplication of configuration values and maintenance difficulties.
Smart Images

Figure CN118018586B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of Dubbo-go services, and in particular to a launcher and a launch method based on a Dubbo-go server. Background Art
[0002] Dubbo is Alibaba's open source Java-based high-performance RPC (remote call) distributed service framework, dedicated to providing high-performance and transparent RPC remote service call solutions, as well as SOA service governance solutions. Users can easily implement microservices based on this framework. Currently, the open source project also provides a go language version, but the go language does not have as rich an ecosystem as the java language. Compared with the java version, there are some problems in its use. First of all, dubbogo can only choose between yaml file configuration and code configuration for configuration, and the two configurations cannot be mixed at the same time (generally, file configuration is directly used in the project, and code configuration is generally a unified configuration added by the architect). Because the java version has the existence of the spring framework, the configuration file of the java version can have placeholders (so that some values can be taken from other configurations), but the yaml file configuration of the go version does not support placeholders (that is, all configurations).
[0003] Currently, if Figure 1 The value of "address:127.0.0.1:2181" is usually determined when the project is started. So a better approach is as follows Figure 2 As shown, the values of address and port are written to the corresponding placeholders, and then when the project is started, the values of dubbo.address and dubbo.port are read from the startup environment as the values of address and port. Finally, dubbogo supports configuration center, but it only supports nacos as its configuration center, and the configuration in nacos is also in yaml file format (such as Figure 1 ). The problem with this is that some configuration values are the same in multiple projects, such as Figure 1 In the configuration center solution of dubbogo, the address value of each project must be written repeatedly. If you want to change this value later, you must change all yaml files at the same time.
[0004] Therefore, there is an urgent need for a launcher and a launch method based on the Dubbo-go server.
[0005] Currently, no effective solution has been proposed for the problems in the related technologies. Summary of the invention
[0006] In view of the problems in the related art, the present invention proposes a launcher and a launch method based on the Dubbo-go server to overcome the above-mentioned technical problems existing in the existing related art.
[0007] The technical solution of the present invention is achieved in this way:
[0008] In one aspect, the present invention:
[0009] A launcher based on Dubbo-go server, including:
[0010] Configuration reader, used to read key-value configuration files and yaml configuration files respectively, and mark them as key-value pairs;
[0011] Key-value pair table key-value, used to store key-value data;
[0012] DubboConfig structure, used to adapt the structure of the yaml configuration file;
[0013] Code configuration API, used to access the configuration center to provide custom configuration structure services.
[0014] Furthermore, the configuration reader includes: storing a preset key-value configuration file path and a yaml configuration file path.
[0015] Another aspect of the present invention is:
[0016] A startup method based on a Dubbo-go server includes the following steps:
[0017] Step S1, the configuration reader pre-reads the key-value configuration file and marks it as a key-value pair table key-value;
[0018] Step S2, the configuration reader reads the YAML configuration file;
[0019] Step S3, replacing the placeholders in the yaml configuration file with the configuration of the key-value pair table key-value, wherein the key character is the identifier of the placeholder and the value character is the replaced value;
[0020] Step S4, marking the replaced yaml configuration file as a DubboConfig structure;
[0021] Step S5, convert the DubboConfig structure into the format of the yaml configuration file;
[0022] Step S6, transfer the format content into the loading configuration of the Dubbo-go server, and start the Dubbo-go service.
[0023] The configuration reader in step 1 pre-reads the key-value configuration file, including the following steps:
[0024] Step S101, pre-set the key-value configuration file path and the yaml configuration file path respectively, and store them in the configuration reader.
[0025] The step of marking as a key-value pair table key-value includes the following steps:
[0026] Step S102, checking whether the ConfigGetApi interface has a structure that implements the ConfigSetApi interface, which includes the following steps:
[0027] Step S103, if the ConfigGetApi interface has a structure that implements the ConfigSetApi interface, call the ConfigGetApi interface to obtain the structure, and merge the structure with the key-value pair table key-value;
[0028] Step S104: If the ConfigGetApi interface does not have a structure that implements the ConfigSetApi interface, the configuration reader reads the yaml configuration file.
[0029] The step of calibrating the DubboConfig structure includes the following steps:
[0030] Step S401, checking whether the ConfigSetApi interface has a structure that implements the ConfigSetApi interface, which includes the following steps:
[0031] Step S402: If the ConfigSetApi interface has a structure that implements the ConfigSetApi interface, call the ConfigSetApi interface to obtain the structure and merge it with the DubboConfig structure to form a new DubboConfig structure.
[0032] Step S403: If the ConfigSetApi interface does not have a structure that implements the ConfigSetApi interface, convert the DubboConfig structure into the format of a yaml configuration file.
[0033] The step of forming a new DubboConfig structure includes the following steps:
[0034] Convert the new DubboConfig structure into the format of a yaml configuration file;
[0035] Transfer the format content to the loading configuration of the Dubbo-go server and start the Dubbo-go service.
[0036] Beneficial effects of the present invention:
[0037] The present invention is based on a launcher and a startup method of a Dubbo-go server. A key-value configuration file is pre-read through a configuration reader and marked as a key-value pair table key-value. The configuration reader reads a yaml configuration file, and replaces the placeholder of the yaml configuration file with the configuration of the key-value pair table key-value. At the same time, the replaced yaml configuration file is marked as a DubboConfig structure, and the DubboConfig structure is converted into the format content of the yaml configuration file. The format content is transferred into the loading configuration of the Dubbo-go server, and the Dubbo-go service is started. The launcher not only supports the synchronous use of yaml configuration files and code configurations, but also supports yaml configuration files with placeholders, and supports customized configuration centers, and has higher adaptability. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0039] Figure 1 This is an example of an existing YAML configuration file scenario. Figure 1 ;
[0040] Figure 2 This is an example of an existing YAML configuration file scenario. Figure 2 ;
[0041] Figure 3 This is a schematic diagram of the principle of a starter based on the Dubbo-go server according to an embodiment of the present invention. Figure 1 ;
[0042] Figure 4 This is a schematic diagram of the principle of a starter based on the Dubbo-go server according to an embodiment of the present invention. Figure 2 ;
[0043] Figure 5 It is a flowchart of a startup method based on a Dubbo-go server according to an embodiment of the present invention.
[0044] In the figure:
[0045] 1. Configuration reader; 2. Key-value pair table key-value; 3. DubboConfig structure; 4. Code configuration api. DETAILED DESCRIPTION
[0046] 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 belong to the scope of protection of the present invention.
[0047] Embodiment 1
[0048] According to an embodiment of the present invention, a launcher based on a Dubbo-go server is provided.
[0049] like Figure 3 As shown, the launcher based on the Dubbo-go server according to an embodiment of the present invention includes:
[0050] Configuration reader 1 is used to read the key-value configuration file and the yaml configuration file respectively, and mark them as key-value pair tables;
[0051] Key-value pair table key-value2, used to store key-value data;
[0052] DubboConfig structure 3, used to adapt the structure of the yaml configuration file;
[0053] Code configuration api4 is used to access the configuration center to provide custom configuration structure services.
[0054] In addition, the configuration reader 1 includes: storing a preset key-value configuration file path and a yaml configuration file path.
[0055] With the help of the above solution, when using it, the user needs to set the path of the key-value configuration file and the path of the yaml configuration file for the launcher, and the path settings will be saved in the configuration reader 1.
[0056] In addition, if the user uses the configuration center, the ConfigGetApi interface needs to be implemented to pass in the configuration read from the key-value configuration file. The user needs to implement how to get the configuration from the configuration center according to the passed configuration, and then convert the configuration into a map[string]string data type and return it to the initiator's configuration reader 1.
[0057] In addition, if the user needs to perform code configuration, he needs to implement the ConfigSetApi interface and pass in a populated DubboConfig type structure, and the user can perform code settings on this structure.
[0058] In addition, for the above DubboConfig structure 3, if Figure 4 As shown, all leaf properties in DubboConfig, such as Figure 4 The values of the Organization, Name, Filter, and Register properties are all strings.
[0059] Embodiment 2
[0060] According to an embodiment of the present invention, a startup method based on a Dubbo-go server is provided.
[0061] like Figure 5 As shown, the startup method based on the Dubbo-go server according to an embodiment of the present invention includes the following steps:
[0062] Step S101, pre-set the key-value configuration file path and the yaml configuration file path respectively, and store them in the configuration reader.
[0063] Step S1, the configuration reader pre-reads the key-value configuration file and marks it as a key-value pair table key-value;
[0064] Step S102, checking whether the ConfigGetApi interface has a structure that implements the ConfigSetApi interface, which includes the following steps:
[0065] Step S103, if the ConfigGetApi interface has a structure that implements the ConfigSetApi interface, call the ConfigGetApi interface to obtain the structure, and merge the structure with the key-value pair table key-value;
[0066] Step S104: If the ConfigGetApi interface does not have a structure that implements the ConfigSetApi interface, the configuration reader reads the yaml configuration file.
[0067] In this technical solution, the key-value configuration file can be a properties, json, or yaml file. To read the key-value configuration file, a third-party open source tool, viper, can be used.
[0068] In addition, if the user has a configuration center, he can implement this interface to get the configuration from the configuration center. Finally, all key-value configuration files are summarized to obtain the key-value pair table key-value.
[0069] Step S2, the configuration reader reads the YAML configuration file;
[0070] Step S3, replacing the placeholders in the yaml configuration file with the configuration of the key-value pair table key-value, wherein the key character is the identifier of the placeholder and the value character is the replaced value;
[0071] Step S4, marking the replaced yaml configuration file as a DubboConfig structure;
[0072] The step of calibrating the DubboConfig structure includes the following steps:
[0073] Step S401, checking whether the ConfigSetApi interface has a structure that implements the ConfigSetApi interface, which includes the following steps:
[0074] Step S402: If the ConfigSetApi interface has a structure that implements the ConfigSetApi interface, call the ConfigSetApi interface to obtain the structure and merge it with the DubboConfig structure to form a new DubboConfig structure.
[0075] With the aid of the above solution, the step of forming a new DubboConfig structure includes the following steps:
[0076] Convert the new DubboConfig structure into the format of a yaml configuration file;
[0077] Transfer the format content to the loading configuration of the Dubbo-go server and start the Dubbo-go service.
[0078] Step S403: If the ConfigSetApi interface does not have a structure that implements the ConfigSetApi interface, convert the DubboConfig structure into the format of a yaml configuration file.
[0079] Step S5, convert the DubboConfig structure into the format of the yaml configuration file;
[0080] Step S6, transfer the format content into the loading configuration of the Dubbo-go server, and start the Dubbo-go service.
[0081] In addition, the launcher converts the content into the DubboConfig structure provided by the present invention, which can be converted using the third-party open source tool koanf. Then the launcher will check whether the ConfigSetApi interface is set. If so, the interface will be called to further set the DubboConfig structure. Users can implement this interface for code configuration.
[0082] Finally, the launcher uses koanf to convert the DubboConfig structure into the content of the yaml configuration file format, passes it to the loading configuration of the Dubbo-go server, and starts the Dubbo-go service.
[0083] To sum up, with the help of the above technical solution of the present invention, the key-value configuration file is pre-read by the configuration reader and marked as the key-value pair table key-value, the configuration reader reads the yaml configuration file, and the placeholder of the yaml configuration file is replaced with the configuration of the key-value pair table key-value, and the replaced yaml configuration file is marked as the DubboConfig structure, and the DubboConfig structure is converted into the format content of the yaml configuration file, and the format content is transferred to the loading configuration of the Dubbo-go server, and the Dubbo-go service is started. The launcher not only supports the synchronous use of yaml configuration files and code configurations, but also supports yaml configuration files with placeholders, and supports customized configuration centers, which has higher adaptability.
[0084] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. After considering the disclosure of the specification and the examples, those skilled in the art will easily think of other embodiments of the present disclosure. This application is intended to cover any modification, use or adaptation of the present disclosure, which follows the general principles of the present disclosure and includes common knowledge or customary technical means in the art that are not disclosed in the present disclosure. The specification and the examples are only regarded as exemplary, and the true scope and spirit of the present disclosure are indicated by the claims.
[0085] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A launcher based on Dubbo-go server, characterized in that: include: Configuration reader (1), used to read key-value configuration files and yaml configuration files respectively, and mark them as key-value pair tables; Key-value pair table key-value(2), used to store key-value data; DubboConfig structure (3) is used to adapt the structure of the yaml configuration file, and replace the placeholders of the yaml configuration file with the configuration of the key-value pair table key-value, where the key character is the identifier of the placeholder and the value character is the replaced value; the replaced yaml configuration file is marked as the DubboConfig structure; Code configuration api (4), used to access the configuration center to provide custom configuration structure services.
2. The launcher based on the Dubbo-go server according to claim 1, characterized in that: The configuration reader (1) stores a preset key-value configuration file path and a YAML configuration file path.
3. A startup method based on a Dubbo-go server, which is used for the launcher based on a Dubbo-go server as described in any one of claims 1-2, characterized in that: The method comprises the following steps: The configuration reader pre-reads the key-value configuration file and marks it as a key-value pair table key-value; The configuration reader reads the YAML configuration file; Replace the placeholders in the yaml configuration file with the key-value pair table key-value configuration, where the key character is the identifier of the placeholder and the value character is the replacement value; Mark the replaced yaml configuration file as the DubboConfig structure; Convert the DubboConfig structure into the format of a yaml configuration file; Transfer the format content to the loading configuration of the Dubbo-go server and start the Dubbo-go service.
4. The startup method based on the Dubbo-go server according to claim 3 is characterized in that: The configuration reader pre-reads the key-value configuration file, including the following steps: The key-value configuration file path and the yaml configuration file path are set in advance and stored in the configuration reader.
5. The startup method based on the Dubbo-go server according to claim 3 is characterized in that: The step of marking as a key-value pair table key-value includes the following steps: Check whether the ConfigGetApi interface has a structure that implements the ConfigSetApi interface, which includes the following steps: If the ConfigGetApi interface has a structure that implements the ConfigSetApi interface, call the ConfigGetApi interface to obtain the structure and merge the structure with the key-value pair table key-value; If the ConfigGetApi interface does not have a structure that implements the ConfigSetApi interface, the configuration reader reads the yaml configuration file.
6. The startup method based on the Dubbo-go server according to claim 5, characterized in that: The step is calibrated as a DubboConfig structure, including the following steps: Check whether the ConfigSetApi interface has a structure that implements the ConfigSetApi interface, which includes the following steps: If the ConfigSetApi interface has a structure that implements the ConfigSetApi interface, call the ConfigSetApi interface to obtain the structure and merge it with the DubboConfig structure to form a new DubboConfig structure; If the ConfigSetApi interface does not have a structure that implements the ConfigSetApi interface, convert the DubboConfig structure into the format of a yaml configuration file.
7. The startup method based on the Dubbo-go server according to claim 6, characterized in that: The steps to form a new DubboConfig structure include the following steps: Convert the new DubboConfig structure into the format of a yaml configuration file; Transfer the format content to the loading configuration of the Dubbo-go server and start the Dubbo-go service.
Citation Information
Patent Citations
Interface switching device of data card equipment based on preinstall drive module and method thereof
CN101526928A
Method for analyzing distributed data in key value library
CN102750353A
