当前位置:网站首页>Nacos Development Manual

Nacos Development Manual

2022-07-06 07:59:00 Frog at the bottom of the well

1.Nacos brief introduction

Nacos Provides an easy-to-use feature set , Realize dynamic service discovery 、 Service configuration 、 Service metadata and traffic management . To replace the previously used registry (zookeeper , eureka wait ), And the configuration center (spring cloud config wait ).

2.Nacos Key features

Service discovery and service health monitoring

Service registration :

Spring Cloud Nacos Discovery follow Spring Cloud General standards , And implemented three interfaces :AutoServiceRegistration,ServiceRegistry and Registration. stay Spring Cloud The startup phase of the application , Will monitor WebServerInitializedEvent event . Initializing Web Received after container WebServerInitializedEvent When an event is , The registration operation will be triggered , And call ServiceRegistry register Method to register the service to Nacos Server.

Service discovery :

NacosServerList Realization com.netflix.loadbalancer.ServerList Interface , And automatically inject it into @ConditionOnMissingBean Next . The ribbon defaults to integration . More customizable if needed , You can use @Autowired Inject NacosRegistration Bean, And directly through its own NamingService The contents of the field call Nacos API.
Dynamic configuration services
Services and metadata management

3.Nacos Cluster deployment description

stay nacos Unzip directory nacos/ Of conf Under the table of contents , There are configuration files cluster.conf, Please configure each line to ip:port.

Reference documents :https://nacos.io/zh-cn/docs/cluster-mode-quick-start.html

4.Nacos To configure

4.1 Custom namespace

Namespace : Used for tenant granularity configuration isolation . Under different namespaces , There can be the same Group or Data ID Configuration of .Namespace One of the most common scenarios is the separation of configurations between different environments , For example, develop the resources of test environment and production environment ( Such as configuration 、 service ) Isolation etc. .
 Insert picture description here

4.2 Customize Group To configure

 Insert picture description here

4.3 Custom extended data id To configure

 Insert picture description here
 Insert picture description here
 Insert picture description here

4.4 Configure the refresh

Configure refresh usage @RefreshScope annotation . Code example :
 Insert picture description here

The results :
 Insert picture description here

After updating the configuration , Call again and return the result :
 Insert picture description here

5. Service startup

Start the loaded configuration file
 Insert picture description here

among :blade.ymal Configure the server in the configuration file 、spring To configure 、feign To configure 、hystrix To configure 、ribbon Configuration and other public configuration
blade-dev.yaml This is done in the configuration file redis、 Database connection and other configurations ( You can also add )

原网站

版权声明
本文为[Frog at the bottom of the well]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131849398467.html