当前位置:网站首页>Simple load balancing with Nacos
Simple load balancing with Nacos
2022-07-01 09:07:00 【The soul of bridge building】
Catalog
One 、 What is? Nacos?
English full name :Dynamic Naming and Configuration Service
It is a dynamic service discovery developed by Alibaba team that is easier to help build cloud native applications 、 Configuration and service management platform
Nacos Provides a range of easy-to-use features , It can help us realize dynamic service discovery quickly 、 Service configuration and other functions .
Two 、Nacos Download and install
—> Reference documents
—> github download
—> Image download
The official recommendation is to download 2.0.3 Stable version
1. Use Windows start-up
cmd Input
startup.cmd -m standalone


2. verification nacos Start successfully or not
http://192.168.10.236:8848/nacos/index.html
account number :nacos , password :nacos
3、 ... and 、Nacos Discovery Service registration / Find out
- First, introduce dependency :
<!-- https://mvnrepository.com/artifact/com.alibaba.cloud/spring-cloud-starter-alibaba-nacos-discovery -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2021.1</version>
</dependency>
- To configure nacos The address of :
nacos.discovery.server-addr=127.0.0.1:8848
- Add... To the startup class
@EnableDiscoveryClientannotation
- see Nacos Service list status
This proves that our port is registered as a service Nacos In the !
- The service list does not show problems
In ensuring that Nacos Normal start , The above operations are also configured , When the service name and other information are not displayed , Please check
spring-boot-starter-parentVersion of :
Four 、 Easy load balancing
You need to create two registrants (9001、9002) And a consumer (8083)
1. Registrant configuration
server:
port: 9001
Spring:
application:
name: nacos-provider
cloud:
discovery:
server-addr: localhost:8848
management:
endpoint:
web:
exposure:
include: '*'
2. Registrant startup class
@EnableDiscoveryClient // Turn on the registration and discovery function of the service
@SpringBootApplication
public class Port9001Application {
public static void main(String[] args) {
SpringApplication.run(Port9001Application.class, args);
}
}
3. Registrant business layer
@RestController
public class Port9001 {
@Value("${server.port}")
private String serverPort;
@GetMapping("/getPort")
public String getServerPort(){
return " Call port " + serverPort + " success !";
}
}
4. Consumer configuration
server:
port: 8083
Spring:
application:
name: nacos-consumer
cloud:
discovery:
server-addr: localhost:8848
# The name of the micro service the consumer is going to visit
service-url:
nacos-user-service: http://nacos-provider
5. Consumer startup class
@EnableDiscoveryClient
@SpringBootApplication
public class NacosConsumer8083Application {
public static void main(String[] args) {
SpringApplication.run(NacosConsumer8083Application.class, args);
}
@Bean
@LoadBalanced
public RestTemplate restTemplate(){
return new RestTemplate();
}
}
6. Consumer business
@RestController
public class Port8083Controller {
@Autowired
private RestTemplate restTemplate;
@Value("${service-url.nacos-user-service}")
private String serverURL;
@GetMapping(value = "consumer/nacos")
public String getDiscovery(){
/* Three parameters : Fill in the name of the visit and url Address + The return value type of the calling interface */
return restTemplate.getForObject(serverURL+"/getPort",String.class);
}
}
7. Start calling the interface
call 8083 Of
/consumer/nacosRefresh the page again
This proves that the remote call is completed , At the same time, it has the effect of load balancing !
8. Solve the problem
java.net.UnknownHostException: nacos-provider
Add... To the dependency spring-cloud-loadbalancer that will do !
边栏推荐
- 【检测技术课案】简易数显电子秤的设计与制作
- Software Engineer Interview Question brushing website and experience method
- Principles of Microcomputer - internal and external structure of microprocessor
- Glitch free clock switching technology
- Shell脚本-case in 和正则表达式
- R语言观察日志(part24)--初始化设置
- 如何解决固定资产管理和盘点的难题?
- Nacos - Configuration Management
- Databinding source code analysis
- Mysql 优化
猜你喜欢

【pytorch】2.4 卷积函数 nn.conv2d

Nacos - 配置管理

如何一站式高效管理固定资产?

Which method is good for the management of fixed assets of small and medium-sized enterprises?

Dynamic proxy

It is designed with high bandwidth, which is almost processed into an open circuit?

Insert mathematical formula in MD document and mathematical formula in typora

Ape anthropology topic 20 (the topic will be updated from time to time)

Nacos - Configuration Management

nacos简易实现负载均衡
随机推荐
Nacos - 配置管理
Differences among tasks, threads and processes
Shell script echo command escape character
集团公司固定资产管理的痛点和解决方案
I would like to know the process of stock registration and account opening by mobile phone? In addition, is it safe to open a mobile account?
Serialization, listening, custom annotation
Shell script - positional parameters (command line parameters)
Principles of Microcomputer - internal and external structure of microprocessor
The jar package embedded with SQLite database is deployed by changing directories on the same machine, and the newly added database records are gone
Shell脚本-特殊变量:Shell $#、$*、[email protected]、$?、$$
Yidian Yidong helps enterprises to efficiently manage equipment and improve equipment utilization
C语言学生信息管理系统
Shell script -while loop explanation
Shell script -read command: read data entered from the keyboard
Shell script - string
Pain points and solutions of fixed assets management of group companies
【ESP 保姆级教程 预告】疯狂Node.js服务器篇 ——案例:ESP8266 + MQ系列 + NodeJs本地服务 + MySql存储
[interview brush 101] linked list
安装Oracle EE
如何一站式高效管理固定资产?






Refresh the page again 