SpringCloud: How to build Nacos services for service discovery

Author platform:

| CSDN:blog.csdn.net/qq_41153943

| Nuggets: juejin.cn/user/651387…

| Zhihu: www.zhihu.com/people/1024…

| GitHub: github.com/JiangXia-10…

| WeChat public account: 1024 notes

This article is about 1400 words, and the estimated reading time is 10 minutes

1. What is Nacos

1. The basic concept of Nacos

Nacos is a new open source project launched by Alibaba. It is a dynamic service discovery, configuration management and service management platform that makes it easier to build cloud-native applications. 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. Nacos helps you build, deliver and manage microservice platforms more agilely and easily. Nacos is a service infrastructure for building a "service"-centric modern application architecture (such as microservice paradigm, cloud native paradigm).

2. Common registration centers

1. Eureka: The native component of springcloud, but the incubation encountered a performance bottleneck in version 2.0, and the maintenance has been stopped

2. Zookeeper: support, professional independent product. Example: dubbo

3. Consul: native components, GO language development

4. Nacos: Compared with Spring Cloud Eureka, Nacos is more powerful. Nacos = Spring Cloud Eureka + Spring Cloud Config. And Nacos can be integrated with Spring, Spring Boot, Spring Cloud, and can replace Spring Cloud Eureka, Spring Cloud Config. Realize service registration and discovery through Nacos Server and spring-cloud-starter-alibaba-nacos-discovery.

3. Main functions of Nacos

Nacos is a middleware whose main service object is service. Nacos supports all mainstream service discovery, configuration and management.

Nacos mainly provides the following four functions:

  1. Service discovery and service health monitoring

  2. Dynamic configuration service

  3. Dynamic DNS service

  4. Services and their metadata management

4. Structure diagram of Nacos

image.png

The picture comes from the Internet, invade and delete!

2. Download and install Nacos

1. Download address and version

Download address: github.com/alibaba/nac…

Download version: nacos-server-1.1.0.tar.gz or nacos-server-1.1.0.zip, just unzip any directory

image.png

2. The startup of nacos

Linux/Unix/Mac

Startup command: sh startup.sh -m standalone

Startup command (standalone represents stand-alone mode operation, non-cluster mode)

Windows

Start command: cmd startup.cmd or double-click startup.cmd to run the file.

Then access the address: http://localhost:8848/nacos

The username and password are both nacos: nacos/nacos

image.png

image.png

3. Use nacos for service registration

Register the service1 microservice to the registration center

1. Configure pom in the service module

First, you need to configure the pom dependencies of the Nacos client

<!--服务注册-->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
复制代码

2. Add service configuration information

Then configure application.properties, and add configuration information for registering Nacos services in the client microservice

# nacos服务地址
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
复制代码

3. Add Nacos client annotations

Add annotations to the client microservice startup class

@EnableDiscoveryClient
复制代码

4. Start the client microservice

Finally, start the registration center, start the registered microservices, and you can see the registered microservices in the Nacos service list

image.png

Summarize

The above is the basic process of how to use nacos for microservice service registration. If there is a project that needs microservice, the registration process can be as above!

related suggestion

Guess you like

Origin blog.csdn.net/qq_41153943/article/details/125165143