nacos configuration center and service registration center


foreword

Nacos is a dynamic service discovery, configuration management and service management platform that is easier to build cloud-native applications. it is spring

One of Cloud Alibaba components, responsible for service registration discovery and service configuration. [The role of service governance and microservice configuration management]

Nacos is dedicated to helping you discover, configure and manage microservices. Nacos provides a set of easy-to-use feature sets to help you quickly

Realize dynamic service discovery, service configuration, service metadata and traffic management.


1. Service Registration and Discovery Center

First add dependencies on the microservice modules to be managed

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

Modify the configuration file

# nacos注册中心的配置
spring.cloud.nacos.discovery.server-addr=localhost:8848
spring.application.name=my-product

This completes the unified management of services 

 

2. Configuration Center

Common Configuration Center

Apollo* *------> a lot of use of apollo**

Apollo is a distributed configuration center open sourced by Ctrip. There are many features, such as: the configuration update can take effect in real time, supports the grayscale release function, and can perform version management and operation auditing functions for all configurations, and provides an open platform API. And the information is also very detailed.

l Disconf

Disconf is a distributed configuration center open sourced by Baidu. It is based on Zookeeper to realize real-time notification and effective after configuration changes.

l SpringCloud Config

This is the configuration center component in Spring Cloud. It is seamlessly integrated with Spring, it is very convenient to use, and its configuration storage supports Git<git didn't learn>. However, it does not have a visual operation interface, and the configuration does not take effect in real time, and needs to be restarted or refreshed.

l Nacos

This is a component in the SpingCloud alibaba technology stack, and we have used it as a service registry before. In fact, it also integrates the function of service configuration, and we can directly use it as a service configuration center.

Realize nacos configuration registration center

Introduce dependencies

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

 Create a file in the configuration center to be consistent with the name of the service

Then create a new bootstrap.properties configuration file to identify external configuration

#应用名字
spring.application.name=xin-spring-cloud-product
#配置中心
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
#额外的配置
spring.cloud.nacos.config.extension-configs[0].data-id=datasource.properties
spring.cloud.nacos.config.extension-configs[0].group=DEFAULT_GROUP
spring.cloud.nacos.config.extension-configs[0].refresh=true

#指定命名空间 开发环境命名空间的id号
spring.cloud.nacos.config.namespace=4d4a61ea-7e78-4d94-a744-2d3a15f67b0b
#指定组名
spring.cloud.nacos.config.group=DEFAULT_GROUP

#配置熔断器
spring.cloud.sentinel.transport.dashboard=localhost:8888
#控制面板修改规则后,可以通过该端口把规则发给微服务
spring.cloud.sentinel.transport.port=8719

It needs to be added on the control layer of each microservice module

@RefreshScope to achieve the refresh of the external configuration file and the corresponding refresh of the microservice

 

 Additional configuration can extract the announcement part of each microservice, such as optimization configuration, data source, etc.

 


Summarize

Guess you like

Origin blog.csdn.net/qq_55648724/article/details/129088811