Nacos registry implementation principle

Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

Start the Nacos service

Go to the bin directory of the three hosts and run the sh startup.sh or startup. CMD -m cluster command to start the service. If ${nacOS_HOME}/logs/start.out is displayed, the service is successfully started.

INFO Nacos started successfully in cluster mode.
Copy the code

Access the Nacos console at http://${nacos_cluster_ip}:8848/nacos, where you can see which nodes make up the cluster and their status under the node list.

Implementation principle of Nacos

The specific module composition was analyzed through the official Nacos architecture diagram

  • Provider APP: indicates the service Provider

  • Consumer APP: Serves consumers

  • Nacos Server: Nacos Service provider, including OpenAPI, Config Service, Naming Service, Consistency Protocol, For Nacos cluster node data synchronization, note Raft algorithm is used)

  • Nacos Console:Nacos Console

In general, service providers access Nacos Server ha cluster through Virtual IP and complete service registration and service query based on OpenAPI. Nacos Server can support active/standby mode, so data consistency algorithm is adopted at the bottom layer to complete data synchronization between nodes. The same goes for service consumers.

Principles of the Registry

The service registration function is mainly reflected in the following aspects:

  • Service instances are registered with the service registry at startup and unregistered at shutdown.

  • The service consumer queries the service registry for available instances.

  • The service registry needs to invoke the health check API of the service instance to verify that it can handle the request.