Mastering Nacos: Dynamic Service Discovery and Configuration for Cloud‑Native Apps
Learn how Nacos, Alibaba’s open‑source platform, enables cloud‑native applications to perform dynamic service registration, discovery, and configuration, offering health checks, DNS routing, metadata management, and a user‑friendly UI, with step‑by‑step integration examples for Spring Cloud projects.
Overview
Nacos is an open‑source project launched by Alibaba that provides a simple and easy‑to‑use feature set to help you quickly achieve dynamic service discovery, service configuration, service metadata, and traffic management. Nacos is pronounced /nɑ:kəʊs/, and its full name is:
Na me and Co nfig S ervice
The core function of Nacos is service registration and dynamic configuration.
In Spring Cloud terms, you can think of it as:
Nacos = Spring Cloud Eureka + Spring Cloud Config
Service Registration
Nacos provides service registration and discovery capabilities. Service instances register on startup and deregister on shutdown, while clients query the registry to find available instances.
The service registry can also invoke health‑check APIs of service instances to verify they can handle requests.
Nacos supports the AP side of the CAP model, similar to Eureka, and offers a management console that is more active than Eureka’s community.
Usage steps:
(1) Add dependency spring-cloud-starter-alibaba-nacos-discovery (2) Add annotation to the main class @EnableDiscoveryClient (3) Configure core settings: service name and Nacos server address.
Dynamic Configuration
Dynamic configuration eliminates the need to redeploy applications when configuration changes, making configuration management more efficient and agile.
Centralized configuration simplifies building stateless services and enables elastic scaling on demand.
Nacos provides a simple UI console to help manage all service and application configurations.
Usage steps:
(1) Add dependency spring-cloud-starter-alibaba-nacos-config (2) Add automatic refresh annotation @RefreshScope (3) Configure core settings: service name and Nacos server address.
(4) Publish configuration via Nacos API.
Other Features
Health Check
Nacos provides real‑time health checks for services, preventing requests from being sent to unhealthy hosts or instances.
It supports transport‑layer (PING or TCP) and application‑layer (e.g., HTTP, MySQL, custom) health checks.
Nacos offers both agent‑reporting and server‑initiated health‑check modes.
A unified health‑check dashboard helps you manage service availability and traffic based on health status.
Dynamic DNS
Supports weighted routing, making it easier to implement middle‑layer load balancing, flexible routing policies, traffic control, and simple DNS resolution within data‑center networks.
It also simplifies DNS‑based service discovery.
Metadata Management
Metadata includes service endpoints, tags, version numbers, instance weights, routing rules, security policies, and other descriptive data.
Nacos can manage all services and metadata from a micro‑service platform perspective, covering service descriptions, lifecycle, static dependency analysis, health status, traffic management, routing, security policies, SLA, and key metrics.
Summary
Nacos centers on service and supports almost all mainstream service types, such as:
k8s
gRPC
Dubbo
Spring Cloud
Docker
It also provides a convenient Open‑API for extensions, and its documentation is relatively rich:
Official site: https://nacos.io/zh-cn/index.html
Source code: https://github.com/alibaba/nacos
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java High-Performance Architecture
Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
