In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "Springcloud-nacos how to achieve configuration and registry", the content of the explanation is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "Springcloud-nacos how to achieve configuration and registry" bar!
Springcloud-nacos implementation configuration and registry
Recently, Ali's open source nacos is quite popular and can be shared with springcloud and dubbo, which is very convenient for dubbo to upgrade to springcloud. Here to learn his configuration and registration center. I mainly record how it is used and how it is stepped on.
Brief introduction of nacos
Nacos is dedicated to helping you discover, configure, and manage micro services. Nacos provides an easy-to-use set of features to help you quickly implement dynamic service discovery, service configuration, service metadata, and traffic management.
Nacos helps you build, deliver, and manage micro-service platforms more quickly and easily. Nacos is a service infrastructure for building modern application architectures with "service" as the center, such as micro-service paradigm and cloud native paradigm.
The above is an excerpt from the official website of nacos to sum up the following advantages of nacos:
(1) it supports configuration center management (including graphical interface)
(2) simple deployment and delivery
(3) include the registry, there is no need to build the configuration and registry alone.
(4) perfect integration of spring cloud and dubbo has good expansibility.
How to use nacos. For more information, please see official configuration.
(1) download source code from Github
-git clone https://github.com/alibaba/nacos.git
-cd nacos/
-mvn-Prelease-nacos clean install-U
-ls-al distribution/target/
-cd distribution/target/nacos-server-$version/nacos/bin
(2) decompress and start nacos
-unzip nacos-server-$version.zip or tar-xvf nacos-server-$version.tar.gz
-cd nacos/bin
-sh startup.sh-m standalone
is completed. Please study it yourself when the cluster is highly available. This article will not repeat too much.
Nacos implementation configuration Center
It is easy for springcloud to use nacos as the configuration center. Just add dependencies and configure the registry address using bootstrap.
(1) add the configuration center dependency of nacos
org.springframework.cloud
spring-cloud-starter-alibaba-nacos-config
(2) configure bootstrap.properties file
-# name of the configuration service
-spring.application.name=provider-service
-# address of nacos configuration center
-spring.cloud.nacos.config.server-addr=nacos.ailijie.top
-# Encoding method of nacos configuration
-spring.cloud.nacos.config.encode=utf-8
-# configuration group name. You need to configure it in nacos, otherwise you won't find it.
-spring.cloud.nacos.config.group=PROVIDER_GROUP
-# configure suffix, not required for properties
-spring.cloud.nacos.config.file-extension=yml
-# load multiple nacos configuration files
-spring.cloud.nacos.config.shared-dataids=provider-service.properties,test.properties
-# refresh other loaded environments
-spring.cloud.nacos.config.refreshable-dataids=provider-service.properties,test.properties
(3) A brief introduction. With nacos configuration Center, the client will be configured with a regular heartbeat, and the environment variables will be dynamically refreshed. But in bean, you need to use @ RefreshCode annotation to refresh, otherwise it will not take effect. The database configuration can customize the data source. To load other configuration files, you need to use refres-dataids to refresh the environment.
Nacos implementation registry
Similarly, nacos to implement the registry is also quite simple, after the successful configuration of nacos, we only need to add dependencies, annotations, and configure the registry address.
(1) add dependencies
org.springframework.cloud
spring-cloud-starter-alibaba-nacos-discovery
(2) add @ EnableDiscoveryClient annotation to the startup class
(3) configure the registry address
-# configuration service name
-spring.application.name=xxx-service
-# configure service cluster name
-spring.cloud.nacos.discovery.cluster-name=consumer-service
-# configure registry address
-spring.cloud.nacos.discovery.server-addr=nacos.ailijie.top
It's done. It's that simple.
Experience of nacos Mining Pit
Here are some of the problems I have encountered:
(1) using version management to learn new projects, we first need to understand the version compatibility features, otherwise there will be a lot of problems.
(2) the configuration does not take effect and does not refresh the configuration with @ RefreshCode annotation
(3) distinguishing between registry and configuration center is two concepts, and two addresses need to be configured.
(4) learn to look at the source code and look at the wiki.
Thank you for your reading, the above is the content of "how to achieve the configuration and registration center of Springcloud-nacos". After the study of this article, I believe you have a deeper understanding of how to achieve the configuration and registration center of Springcloud-nacos. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.