preface

Article content output source: Pull hook education Java high salary training camp;

Spring Cloud is a one-stop microservices solution. Many companies are using Spring Cloud components. If we want to learn about the Spring Cloud microservices architecture, we need to learn about their components. These include: registry, load balancing, fuse processing, procedure call, gateway services, configuration center, message bus, call link, data monitoring, and more.

This article takes you through using Nacos. What is Nacos? Is a micro service component launched by Ali, which can be used as a service registry and configuration center. It’s Eureka and Config combined, and has good support for Dubbo. What matters is that Ali made it. Get it.

Throughout this article you will learn:

  1. Nacos introduction
  2. Nacos single-server deployment
  3. Nacos client
  4. Nacos data model
  5. Nacos data persistence
  6. Nacos cluster
  7. Nacos configuration center

Nacos introduction

Nacos (Dynamic Naming and Configuration Service) is an open source platform of Alibaba for Service discovery, configuration management and Service management in micro-service architecture.

Nacos is the combination of registry + configuration center (Nacos=Eureka+Confifig+Bus)

Website:

https://nacos.io 
Copy the code

Download address:

https://github.com/alibaba/Nacos
Copy the code

Nacos features

  • Service discovery and health check

  • Dynamic configuration Management

  • Dynamic DNS Service

  • Service and metadata management (from a management platform perspective, NacOS also has a UI page where you can see registered services and their instance information (metadata information), etc.), dynamic service weighting, and dynamic service graceful downsizing can be done

NacosSingleton service deployment

1. Download the package and decompress it

https://github.com/alibaba/nacos/releases
Copy the code

2. Modify the configuration

In the conf directory are configuration files, which can be modified according to your own needs.

3. Start NACOS

Let’s start them all alone.

##linux
sh startup.sh -m standalone

## windows
cmd startup.cmd -m standalone
Copy the code

4. Access the NACOS management interface:

http://127.0.0.1:8848/nacos (the default port 8848, account number and password nacos/nacos)Copy the code

Nacos client

Like Eureka, NACOS is divided into client side and server side. The server side is used for monitoring and management, and the client side is used for registration, which is our business service. Now that we’ve set up the NacOS server, let’s create a NacOS client demo.

You can see that the required Spring Boot version is greater than 2.2 and less than 2.3. So let’s go with the Spring Boot version 2.2.9

The overall POM.xml file is as follows:

<? The XML version = "1.0" encoding = "utf-8"? > < project XMLNS = "http://maven.apache.org/POM/4.0.0" XMLNS: xsi = "http://www.w3.org/2001/XMLSchema-instance" Xsi: schemaLocation = "http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion > 4.0.0 < / modelVersion > < the parent > < groupId > org. Springframework. Boot < / groupId > The < artifactId > spring - the boot - starter - parent < / artifactId > < version > 2.2.9. RELEASE < / version > < relativePath / > <! -- lookup parent from repository --> </parent> <groupId>cn.quellanan</groupId> < artifactId > service - demo - the client - nacos - 9100 < / artifactId > < version > 1.0.0 < / version > <name>service-demo-client-nacos-9100</name> <description>Demo project for Spring Boot</description> <properties> < Java version > 1.8 < / Java version > < spring - cloud - alibaba. Version > 2.2.1. RELEASE < / spring - cloud - alibaba. Version > </properties> <dependencies> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency>  <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>${spring-cloud-alibaba.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>Copy the code

Here the version of Spring-cloud-Alibaba is 2.2.1.release.

Rely on

Introduce a dependency for nacOS service registry.

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
Copy the code

configuration

server: port: 9100 spring: application: name: service-demo-client cloud: nacos: discovery: Server-addr: 127.0.0.1:8848 Management: endpoints: web: exposure: include: "*"Copy the code

Start the class

The startup class adds the @enableDiscoveryClient annotation. Start with the Edgware version of SpringCloud without comments

@springBootApplication @enableDiscoveryClient // Start the registry client (common annotations, such as register to Eureka, Nacos, etc.) // Starting with the Edgware version of SpringCloud, unannotated is ok, But suggest that we add public class ServiceDemoClientNacos9100Application {public static void main (String [] args) { SpringApplication.run(ServiceDemoClientNacos9100Application.class, args); }}Copy the code

test

We start the project next, and when the startup is complete, we visit

http://127.0.0.1:8848/nacos/#/serviceManagement?dataId=&group=&appName=&namespace=&pageSize=&pageNo=
Copy the code

You can see that our service has been registered.

Click Details to view details

Protection threshold: can be set to a floating point number between 0 and 1, which is actually a scale value (current health instances of the service/total current instances of the service)

The meaning of the protection threshold is as follows: When the number of healthy instances/total instances of service A is less than the protection threshold, it indicates that there are not many healthy instances and the protection threshold will be triggered (state true). The goal is to avoid an avalanche effect where a single service becomes unavailable and the entire upstream service collapses as well.

Nacos will provide all the instance information (healthy + unhealthy) of the service to the consumer, who may access an unhealthy instance and fail, but this is better than causing an avalanche, sacrificing some requests and ensuring that the entire system is available. Ali often adjusts this protection threshold parameter when using NACOS internally.

Nacos data model

The data model is the namespace we see on the interface.

Namespace, Namespace, Group, and cluster are used for categorizing and managing services and configuration files. After categorizing services and configuration files, certain effects, such as isolation, can be achieved. For example, in the case of services, services in different namespaces cannot call each other

Namespace: A Namespace that isolates different environments, such as development, test, and production

Group: Grouping several services or configuration sets into a Group. Usually, one system is grouped into one Group

Service: a Service, such as a resume micro-service

DataId: A configuration set or you can think of it as a configuration file

Namespace + Group + Service is similar to the GAV coordinates in Maven. The GAV coordinates are used to lock the Jar, in this case, to lock the Service

Namespace + Group + DataId is similar to the GAV coordinates in Maven. The GAV coordinates are used to lock the Jar, in this case, to lock the configuration file

Best practices

Nacos abstracts the concepts of Namespace, Group, Service, DataId, and so on, depending on how it is used (very flexible). Recommended usage is as follows:

A hierarchical model of Nacos services

Nacos data persistence

To build libraries built table

Create a nacOS_Config database. The construction of the sentence, when downloading nacos.

/*
 * Copyright 1999-2018 Alibaba Group Holding Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = config_info   */
/******************************************/
CREATE TABLE `config_info` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `data_id` varchar(255) NOT NULL COMMENT 'data_id',
  `group_id` varchar(255) DEFAULT NULL,
  `content` longtext NOT NULL COMMENT 'content',
  `md5` varchar(32) DEFAULT NULL COMMENT 'md5',
  `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
  `src_user` text COMMENT 'source user',
  `src_ip` varchar(20) DEFAULT NULL COMMENT 'source ip',
  `app_name` varchar(128) DEFAULT NULL,
  `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段',
  `c_desc` varchar(256) DEFAULT NULL,
  `c_use` varchar(64) DEFAULT NULL,
  `effect` varchar(64) DEFAULT NULL,
  `type` varchar(64) DEFAULT NULL,
  `c_schema` text,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_configinfo_datagrouptenant` (`data_id`,`group_id`,`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info';

/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = config_info_aggr   */
/******************************************/
CREATE TABLE `config_info_aggr` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `data_id` varchar(255) NOT NULL COMMENT 'data_id',
  `group_id` varchar(255) NOT NULL COMMENT 'group_id',
  `datum_id` varchar(255) NOT NULL COMMENT 'datum_id',
  `content` longtext NOT NULL COMMENT '内容',
  `gmt_modified` datetime NOT NULL COMMENT '修改时间',
  `app_name` varchar(128) DEFAULT NULL,
  `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_configinfoaggr_datagrouptenantdatum` (`data_id`,`group_id`,`tenant_id`,`datum_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='增加租户字段';


/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = config_info_beta   */
/******************************************/
CREATE TABLE `config_info_beta` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `data_id` varchar(255) NOT NULL COMMENT 'data_id',
  `group_id` varchar(128) NOT NULL COMMENT 'group_id',
  `app_name` varchar(128) DEFAULT NULL COMMENT 'app_name',
  `content` longtext NOT NULL COMMENT 'content',
  `beta_ips` varchar(1024) DEFAULT NULL COMMENT 'betaIps',
  `md5` varchar(32) DEFAULT NULL COMMENT 'md5',
  `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
  `src_user` text COMMENT 'source user',
  `src_ip` varchar(20) DEFAULT NULL COMMENT 'source ip',
  `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_configinfobeta_datagrouptenant` (`data_id`,`group_id`,`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info_beta';

/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = config_info_tag   */
/******************************************/
CREATE TABLE `config_info_tag` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `data_id` varchar(255) NOT NULL COMMENT 'data_id',
  `group_id` varchar(128) NOT NULL COMMENT 'group_id',
  `tenant_id` varchar(128) DEFAULT '' COMMENT 'tenant_id',
  `tag_id` varchar(128) NOT NULL COMMENT 'tag_id',
  `app_name` varchar(128) DEFAULT NULL COMMENT 'app_name',
  `content` longtext NOT NULL COMMENT 'content',
  `md5` varchar(32) DEFAULT NULL COMMENT 'md5',
  `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
  `src_user` text COMMENT 'source user',
  `src_ip` varchar(20) DEFAULT NULL COMMENT 'source ip',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_configinfotag_datagrouptenanttag` (`data_id`,`group_id`,`tenant_id`,`tag_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info_tag';

/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = config_tags_relation   */
/******************************************/
CREATE TABLE `config_tags_relation` (
  `id` bigint(20) NOT NULL COMMENT 'id',
  `tag_name` varchar(128) NOT NULL COMMENT 'tag_name',
  `tag_type` varchar(64) DEFAULT NULL COMMENT 'tag_type',
  `data_id` varchar(255) NOT NULL COMMENT 'data_id',
  `group_id` varchar(128) NOT NULL COMMENT 'group_id',
  `tenant_id` varchar(128) DEFAULT '' COMMENT 'tenant_id',
  `nid` bigint(20) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`nid`),
  UNIQUE KEY `uk_configtagrelation_configidtag` (`id`,`tag_name`,`tag_type`),
  KEY `idx_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_tag_relation';

/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = group_capacity   */
/******************************************/
CREATE TABLE `group_capacity` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `group_id` varchar(128) NOT NULL DEFAULT '' COMMENT 'Group ID,空字符表示整个集群',
  `quota` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '配额,0表示使用默认值',
  `usage` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '使用量',
  `max_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '单个配置大小上限,单位为字节,0表示使用默认值',
  `max_aggr_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '聚合子配置最大个数,,0表示使用默认值',
  `max_aggr_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值',
  `max_history_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '最大变更历史数量',
  `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_group_id` (`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='集群、各Group容量信息表';

/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = his_config_info   */
/******************************************/
CREATE TABLE `his_config_info` (
  `id` bigint(64) unsigned NOT NULL,
  `nid` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `data_id` varchar(255) NOT NULL,
  `group_id` varchar(128) NOT NULL,
  `app_name` varchar(128) DEFAULT NULL COMMENT 'app_name',
  `content` longtext NOT NULL,
  `md5` varchar(32) DEFAULT NULL,
  `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `src_user` text,
  `src_ip` varchar(20) DEFAULT NULL,
  `op_type` char(10) DEFAULT NULL,
  `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段',
  PRIMARY KEY (`nid`),
  KEY `idx_gmt_create` (`gmt_create`),
  KEY `idx_gmt_modified` (`gmt_modified`),
  KEY `idx_did` (`data_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='多租户改造';


/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = tenant_capacity   */
/******************************************/
CREATE TABLE `tenant_capacity` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `tenant_id` varchar(128) NOT NULL DEFAULT '' COMMENT 'Tenant ID',
  `quota` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '配额,0表示使用默认值',
  `usage` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '使用量',
  `max_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '单个配置大小上限,单位为字节,0表示使用默认值',
  `max_aggr_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '聚合子配置最大个数',
  `max_aggr_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值',
  `max_history_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '最大变更历史数量',
  `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='租户容量信息表';


CREATE TABLE `tenant_info` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `kp` varchar(128) NOT NULL COMMENT 'kp',
  `tenant_id` varchar(128) default '' COMMENT 'tenant_id',
  `tenant_name` varchar(128) default '' COMMENT 'tenant_name',
  `tenant_desc` varchar(256) DEFAULT NULL COMMENT 'tenant_desc',
  `create_source` varchar(32) DEFAULT NULL COMMENT 'create_source',
  `gmt_create` bigint(20) NOT NULL COMMENT '创建时间',
  `gmt_modified` bigint(20) NOT NULL COMMENT '修改时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_tenant_info_kptenantid` (`kp`,`tenant_id`),
  KEY `idx_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='tenant_info';

CREATE TABLE `users` (
	`username` varchar(50) NOT NULL PRIMARY KEY,
	`password` varchar(500) NOT NULL,
	`enabled` boolean NOT NULL
);

CREATE TABLE `roles` (
	`username` varchar(50) NOT NULL,
	`role` varchar(50) NOT NULL,
	UNIQUE INDEX `idx_user_role` (`username` ASC, `role` ASC) USING BTREE
);

CREATE TABLE `permissions` (
    `role` varchar(50) NOT NULL,
    `resource` varchar(255) NOT NULL,
    `action` varchar(8) NOT NULL,
    UNIQUE INDEX `uk_role_permission` (`role`,`resource`,`action`) USING BTREE
);

INSERT INTO users (username, password, enabled) VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', TRUE);

INSERT INTO roles (username, role) VALUES ('nacos', 'ROLE_ADMIN');

Copy the code

Add Mysql data source configuration

Modify the ${nacoshome} / conf/application. The properties, increase the mysql configuration

After restarting the server, the configuration and operations of the server can be recorded.

Nacos cluster

The service side

The steps for building a server cluster are as follows:

1. Install three or more Nacos. Copy the decompressed nacOS folders and name them nacOS_01, nacOS_02, and nacOS_03

2. Modify the configuration file application.properties

On the same machine, change server.port in application.properties to 8848, 8849, 8850 respectively

Bind IP to the current instance node at the same time, because the server can bind multiple IP’s

Nacos. Inetutils. IP address = 127.0.0.1Copy the code

3. Modify cluster.conf

127.0.0.1:8848
127.0.0.1:8849
127.0.0.1:8850
Copy the code

Start these servers separately.

startup.cmd -m cluster
Copy the code

View cluster management

The client

To register clients with the cluster, you only need to modify the following configuration:

Cloud: nacos: discovery: serveraddr: 127.0.0.1:8848127.00 0.1:8849127.00 0.1:8850Copy the code

NacosConfiguration center

With Nacos, distributed configuration is also easy

1. Go to the Nacos Server and add the configuration information

2. Transform specific microservices into Nacos Confifig Client, which can obtain configuration information from Nacos Server

Nacos Server Adds a configuration set

The server and client need to be modified. The server needs to add a configuration file, and the client needs to obtain the corresponding configuration file.

Official website tutorial:

https://nacos.io/zh-cn/docs/quick-start-spring-cloud.html
Copy the code

The service side

Add the configuration in NACOS.

Take this gateway-nacos-HW. yaml for example; Once configured, access the address to test:

http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=gateway-nacos-hw.yaml&group=DEFAULT_GROUP&content=useLocalCache=true
Copy the code

The access to the configuration indicates that the Nacos server is built, so we can enable Nacos configuration management in our microservices

The client

Rely on

Add dependencies first:

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
Copy the code

Increase the configuration

We need it in bootstrap.yml

Spring: cloud: nacos: config: server - addr: 127.0.0.1:8848127.00 0.1:8849127.00 0.1:8850 file - the extension: yaml group: DEFAULT_GROUP prefix: gateway-nacos-hwCopy the code

How to lock configuration files in Nacos Server in microservices (dataId)

Lock configuration files with Namespace + Group + dataId. If Namespace is not specified, the default is public; if Group is not specified, the default is DEFAULT_GROUP

The full format of the dataId is as follows

${prefix}-${spring.profile.active}.${file-extension}
Copy the code
  • Prefix for spring. The default application. The name of the value, but can be by spring configuration items. The cloud. Nacos. Config. The prefix to configuration.

  • Spring.profile. active is the profifile corresponding to the current environment. Note: When spring.profile.active is null, the corresponding hyphen – will also not exist, and the dataId concatenation format becomes prefix.{prefix}.prefix.{file-extension}.

  • File – exetension as the configuration of content data format, can be configured a spring. Cloud. Nacos. Config. The file – the extension to the configuration. Currently, only properties and YAML types are supported

@RefreshScope

The configuration is automatically updated via the Spring Cloud native annotation @refreshScope

@springBootApplication @enableDiscoveryClient // Start the registry client (common annotations, such as register to Eureka, Nacos, etc.) // Starting with the Edgware version of SpringCloud, unannotated is ok, But suggest you add @ RefreshScope public class ServiceDemoClientNacos9100Application {public static void main (String [] args) { SpringApplication.run(ServiceDemoClientNacos9100Application.class, args); }}Copy the code

So the whole thing is done.

DataId extension

A microservice wants to obtain configuration information for multiple dataids from the configuration center Nacos Server and, if possible, extend multiple Dataids

Modify the configuration:

# nacos config config: server-addr 127.0.0.1:8848127.00 0.1:8849127.00 0.1:8850 # to lock the configuration file on the server configuration items (read it) namespace: public id # namespace group: DEFAULT_GROUP # DEFAULT_GROUP # DEFAULT_GROUP Yaml ext-config[0]: data-id: abc.yaml group: DEFAULT_GROUP refresh: true # enable dataId dynamic refresh ext-config[1]: data-id: def.yaml group: DEFAULT_GROUP refresh: true # enable dataId dynamic refresh ext-config[1]: data-id: def.yaml group: DEFAULT_GROUP refresh: True # Enable dynamic refresh of the extended dataIdCopy the code

Priority: dataId generated according to the rule > extended dataId (for extended dataId, [n] larger n has higher priority)

conclusion

Nacos, as the service registry and configuration center for the microservices architecture launched by Ali, integrates the advantages of Eureka and Config, as well as its own flexible configuration. Visual interface management and so on. But in some places the interaction is not very friendly. If you’re interested, you can try it. There are plenty of companies using Nacos.So feel good partners can try, the overall deployment, whether it is a single or cluster is very convenient.

Ok, that’s all. Remember to like and collect your favorite friends