Ali Nacos first experience

Nacos from open source has now been 18 releases, and update soon, is also very active in the community, the number of nails light group that is a lot, every point a button to see all the members of my nail will get stuck, there are Maybe I did not update the latest version.

Sentinel wrote a front for some time, recently or intend to study at Nacos, currently do not it does not matter, the key is first to experience and know the advantages of this framework, it is important for technology selection.

Github Address: github.com/alibaba/nac...

Star remember the next Oh. . .

In fact, official documents Nacos is very detailed, but also the Chinese version, the domestic development is simply the Gospel. In fact, this involves another problem, since it is so detailed, it is also necessary to write these articles?

The main thing is the accumulation of their own learning process, maybe I'll have some problems in the process, perhaps these questions useful for some people new to it, and that was enough. In addition to the fact there are many official documents Daniel also wrote many articles, we should learn from these people more than willing to share.

Details

Nacos is mainly used for service discovery and health monitoring services, dynamic configuration services, dynamic DNS services and other scenes.

The figure is official, we can fully understand Nacos by the following figure.

Nacos map

Characteristics big picture: from the features, non-functional characteristics of a comprehensive introduction to the characteristics of the problem domain we want solutions to the demands of architecture big picture: The clear architecture, allowing you to quickly enter the business world Nacos Big Picture: with the current characteristics can support business scenarios , best practices and ecological big Picture: comb Nacos system and mainstream ecological relationships advantages big Picture: show Nacos core competitiveness of strategic big picture: from the strategic to the tactical level macro advantages speak Nacos

Fast Experience

Many frameworks in order to allow users to quickly experience, will provide a quick start package, easy and convenient.

We can github.com/alibaba/nac... download page version of the package you need:

Download the zip on it on Windows, download the tar package on linux. Windows are an example, after unzip into the bin directory, run directly startup.cmd script to start Nacos service. Sh startup.sh -m standalone execution start the services on Linux / Unix / Mac, standalone represents stand-alone mode, non-clustered mode.

login page

The default account password is nacos / nacos, you can see the main page after login.

main page

Spring Boot Configuration Management Integration

Because it is the first article, we start to learn this configuration, the first to experience at how to integrate in Spring Boot configuration in detail later re-introduced one by one.

Add dependency:

<dependency>
	<groupId>com.alibaba.boot</groupId>
	<artifactId>nacos-config-spring-boot-starter</artifactId>
	<version>0.2.1</version>
</dependency>
复制代码

Note : The version 0.2.x.RELEASE corresponds Spring Boot 2.x version, version 0.1.x.RELEASE corresponds Spring Boot 1.x version.

View version list the following address:

mvnrepository.com/artifact/co…

In Nacos background create a new profile:

Data ID: ID of a configuration set Nacos in. Configuration Set ID is one of the dimensions of organizational division configuration. Data ID is typically used to configure divide tissue collection system. A system or application may comprise a plurality of configuration sets, each set can be configured to identify a meaningful name. Data ID usually based Java package (e.g. com.taobao.tc.refund.log.level) naming rules to ensure the global uniqueness. This naming non-mandatory.

Data ID specified in the startup class:

@NacosPropertySource(dataId = "nacos-springboot", autoRefreshed = true)
@SpringBootApplication
public class NacosSpringBootApp {
	public static void main(String[] args) {
		SpringApplication.run(NacosSpringBootApp.class, args);
	}
}
复制代码

Test code:

@RestController
public class ConfigController {

	@NacosValue(value="${name}", autoRefreshed=true)
	private String name;
	
	@GetMapping("/name")
	public String getName() {
		return this.name;
	}
}
复制代码

Use @NacosValue to injection configuration, autoRefreshed default is false, the background is not going to change the refresh value needs to be set to true only be refreshed.

The first article on here, more features, behind us explain one by one.

Ape world

Guess you like

Origin juejin.im/post/5d0c3ba7f265da1b855c5d96