2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
Table of contents
Accompanying the entire life cycle of the application
Configuration requires governance
Service discovery and service health check
Dynamic Configuration Management
Service and metadata management
When an application is started and running, it often needs to read some configuration information. The configuration basically accompanies the entire life cycle of the application, such as: database connection parameters, startup parameters, etc.
It is read-only for programmers. The program changes its behavior by reading the configuration, but the program should not change the configuration.
Initialize by reading configuration at startup, and adjust behavior according to configuration at runtime. For example, you need to read the service port number at startup, and read custom policies to execute scheduled tasks during system operation.
Common ones include hard code within the program, configuration files, environment variables, startup parameters, and database-based ones.
The same program needs to have different configurations in different environments (development, testing, production) and different clusters (such as different data centers), so a complete environment and cluster configuration management is required.
In a microservice architecture, when a system is split from a monolithic application into service nodes on a distributed system, the configuration files must be migrated (separated) so that the configuration is dispersed.
The configuration center separates configuration from each application and manages configuration in a unified manner, so the applications themselves do not need to manage configuration themselves.
Alibaba's open source product is a comprehensive solution for service discovery, configuration management, and service governance in microservice architecture.
Official website:https://nocas.io/
Four major functions
Nacos makes it easier to register services and discover other services through DNS or HTTP interfaces. Nacos also provides real-time inspection of services to prevent requests from being sent to unhealthy hosts or service instances.
Dynamic configuration services allow you to manage the configuration of all services in a centralized and dynamic manner across all environments. Nacos eliminates the need to redeploy applications when updating configurations, which makes configuration changes more efficient and flexible.
Automatically define the extended Data Id configuration. The internal configuration has the highest priority. Configuration priority: the larger the n in the extended Data Id, the higher the priority. The loading order of bootstrap.yml takes precedence over application.yml.
Completely turn off configuration: Completely turn off Spring Cloud Nacos Config by setting spring.cloud.nacos.config.enable=false.
nacos can be deployed in a cluster.
The @Value annotation is an annotation provided by the Spring framework. It is used to obtain the value in the configuration file. It can be used to obtain the configuration items in any configuration file (such as application.properties, application.yml). When using the @Value annotation, you need to specify the full path of the configuration item, for example: @Value("${config.key}").
nacos startup command (Windows): startup.cmd -m standalone
Open the browser and enter http://localhost:8848/nacos to access the service. The default account and password are nacos, nacos
Nacos provides service discovery capabilities based on the DNS protocol, which aims to support service discovery in heterogeneous languages and expose endpoints of services registered on Nacos in the form of domain names, so that third-party applications can easily query and discover them.
Nacos allows you to manage all services and metadata in the data center from the perspective of microservice platform construction, including management service description, life cycle, static dependency analysis of services, service health status, service traffic management, routing and security policies.
In a microservice architecture, the entire system is divided into multiple services according to their responsibilities and capabilities, and business goals are achieved through collaboration between services. In this way, remote calls between services are required in our code. The consumer of the service needs to call the producer of the service. In order to complete a request,Consumers need to know the network location of service producers(IP address and port number).
·