current position:Home>Nacos of spring cloud Alibaba, introduction CD of Java project development

Nacos of spring cloud Alibaba, introduction CD of Java project development

2022-01-27 01:40:42 m0_ sixty-four million eight hundred and sixty-seven thousand e


Alibaba open source Nacos From last year 7 The first of the month release The version has been released to 1.1.3 edition , The official version is planned as :Nacos from 0.8.0 Start supporting production availability ,1.0 Version available for mass production .

About Nacos name : The first four letters are Naming and Configuration The first two letters of , final  s  by Service.

Nacos What is it?

Nacos What is it? ? Haven't you heard of it . but Eureka Those who have done micro services must know , stay SpringCloud In doing Service registry components , similar Duboo Of Zookeeper, also Consul.

Nacos It is also a registry component , But it It's not just the registry .Nacos It is also a configuration center , such as SpringCloud Medium Config, Versioning configuration files .

that Nacos What is it , In a word, the official website is :

A dynamic service discovery that is easier to build cloud native applications 、 Configuration management and service management platform .

Simply speaking Nacos It's the registry + A combination of configuration centers , Provide an easy to use feature set , Help us solve Microservice development must involve service registration and discovery , Service configuration , Service management Other questions .

Nacos still Spring Cloud Alibaba One of the components , Responsible for service registration and discovery .

Why Nacos

Now in the micro service ecosystem , There are many open source components that have been registered and discovered by services , Such as Eurka,ZooKeeper,Consul, Why use Nacos Well , Let's look at a simple comparison of these frameworks :

It is said that Nacos There are more than 10 The instance of Wan runs , It has passed the test of all kinds of large traffic such as double 11

by comparison , current Nacos Whether it's deployment , It's still easy to use , More importantly, the documentation is complete , High community activity .

also Nacos And the current mainstream open source ecosystem provides good support :

1、Nacos yes Specially designed for Dubbo Registration center and configuration center

2、Nacos Meeting Fully compatible with Spring Cloud

3、Nacos Support Service Mesh Integrate ,Kubernetes Integrate

besides , Alibaba is going through Dubbo + Nacos And a series of open source projects to create service discovery 、 Service and traffic management 、 Service sharing platform , The future is still developing and evolving , I believe there will be more places to use it in the future Nacos.

Single deployment

Prepare the environment

Nacos rely on Java Environment to run , So we need to ensure the environmental requirements before deployment :

1、64 bit OS, Support Linux/Unix/Mac/Windows, We recommend Linux/Unix.

2、64 bit JDK 1.8+

Go to github On the search nacos, Find out releases The release

Unzip run

here Nacos Single machine deployment uses commands  -m standalone , If it is Windows command , You can double-click directly  startup.cmd  File can .

browser visit http://{ip}:8848/nacos/index.html, Click to enter Nacos Visual management interface , Need account password login access , The default is ****nacos

After logging in, you can log in to the website See... On the sidebar Nacos The main function menu of : Configuration Management , Service management , Cluster management , Namespace .

Service providers

Take a simple example to experience How to register a service to Nacos, Actually sum Eureka No big difference


Create a project named shop-goods-service Our service provider project ,pom.xml The configuration is as follows :

notes : Because we use Dubbo Of RPC, So I also quote Dubbo; I'll talk about this later


adopt **@EnableDiscoveryClient annotation Show is a Nacos client , The annotation yes Spring Cloud Native annotations provided **![](

《 A big factory Java Analysis of interview questions + Back end development learning notes + The latest architecture explanation video + Practical project source code handout 》

【】 Full content open source sharing


Define interface implementation

Be careful :GoodsServiceImpl Interface implementation class of It has @Service annotation , yes org.apache.dubbo.config.annotation.Service


Start the project

Access... Through a browser, namely Nacos Server website

You will find that a service is already registered in the service , The service name is goods-provider. This process is actually quite simple , Before dubbo There is no difference in the use of .

Of course, this is the service provider , To see the effect , Let's start again Serving consumers

Serving consumers


This POM Files and providers are very similar , Because consumers, we will use web demonstration , So add a dependency package

Service consumer


This POM Files and providers are very similar , Because consumers, we will use web demonstration , So add a dependency package


copyright notice
author[m0_ sixty-four million eight hundred and sixty-seven thousand e],Please bring the original link to reprint, thank you.

Random recommended