Configuration Center Overview
The configuration center is used to manage microservice application configurations. Microservices connect to the configuration center to obtain the information and changes of configurations. The configuration center is also the core component for the management functions of other microservices. For example, service governance rules are delivered through the configuration center.
Microservice engines support config-center and kie.
- For microservice engine 1.x, the configuration center is config-center.
- For microservice engine 2.x, the configuration center is kie (recommended) or config-center.
This section describes the development details of different microservice development frameworks using the configuration center, including how to configure dependencies and connect to configuration items related to the configuration center, and how to read configurations and respond to configuration changes in microservice applications.
- Microservice engines use kie as the configuration center.
By default, microservices read application configurations, service configurations, and custom configurations from the configuration center. Application configuration refers to the configuration of the same environment and application as the microservice. Service configuration refers to the configuration of the same environment, application, and microservice name as the microservice. A microservice can specify a specific label and label value in the configuration file. Custom configuration refers to the configuration of the same label and label value as the microservice.
Application- and service-level configurations are applicable to simple scenarios. The application-level configuration is shared by all microservices of the application. The service-level configuration is exclusive and takes effect only for specific microservices.
In complex scenarios, customLabel and customLabelValue can be used to define configurations. For example, if some configurations are shared by all applications, this method can be used. Add the following configuration to the configuration file (Spring Cloud is used as an example):spring: cloud: servicecomb: config: kie: customLabel: public # The default value is public. customLabelValue: default # The default value is a null string.
If a configuration item has the public label and the label value is default, the configuration item takes effect for the microservice.
- The configuration center is considered as the table tbl_configurations of the database. The key is the primary key, and each label is an attribute.
- The client queries the configuration based on the following search criteria:
- Custom configuration
select * from tbl_configurations where customLabel=customLabelValue & match=false
- Application-level configuration
select * from tbl_configurations where app=demo_app & environment=demo_environment & match=true
- Service-level configuration
select * from tbl_configurations where app=demo_app & environment=demo_environment & service=demo_service & match=true
When match is set to true, only the attributes specified in the condition are available. When match is set to false, all attributes except those in the condition are allowed. You can also specify multiple applications for label app or services for label service. In this way, the configuration item takes effect for multiple services and applications.
- Custom configuration
For microservice engines of the TEXT and XML types, SDK uses the content as key-value pairs. For CSE of the YAML and Properties types, SDK parses the content and the application uses the content as the actual application configuration items. For example,
Type: TEXT key: cse.examples.hello value: World
One configuration item is found in the application: cse.examples.hello = World.
Type: YAML key: cse.examples.hello value: | cse: key1: value1 key2: value2
Two configuration items are found in the application: cse.key1 = value1 and cse.key2 = value2.
- Microservice engines use config-center as the configuration center.
By default, microservices read global configurations and service configurations from the configuration center. Global configuration refers to the environment shared by the microservice engine and microservice. Service configuration refers to the microservice engine's environment, application, and microservice name that are the same as the microservice's.
Microservice engines support only key-value configuration items. To use a configuration file in YAML format, you can use the fileSource function provided by SDK. After the key list of fileSource is specified in the configuration file, SDK parses the values of these keys as YAML files. The following uses Spring Cloud as an example to describe how to add a configuration item to the bootstrap.yml file.
spring: cloud: servicecomb: config: fileSource: file1.yaml,file2.yaml
In addition, create configurations in the configuration center. The following table lists the configuration items and their values. The value is in YAML format.
Item
Value
file1.yaml
cse.example.key1: value1 cse.example.key2: value2
file2.yaml
cse.example.key3: value3 cse.example.key4: value4
For details about how to create a microservice, see Configuration Management (Applicable to Engine 1.x).
Four configuration items are found in the application: cse.example.key1=value1, cse.example.key2=value2, cse.example.key3=value3, and cse.example.key4=value4.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot