首先我们先来了解负载均衡:
负载均衡是为了缓解网络压力的,服务器端进行扩容的重要手段
实现有两种方式:硬件F5 、 软件nginx、Dubbo
为了实现负载均衡的原理,我们基于以下两篇随笔继续学习
创建多个提供者的角色存在。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
server:
port: 80
#EurekaServer配置
eureka:
client:
register-with-eureka: false #不注册到其他的注册中心
fetch-registry: true #从其他中心中心拉取服务器信息
service-url:
defaultZone: http://eureka6001.com:6001/eureka,http://eureka6002.com:6002/eureka #注册中心访问地址
@Configuration
public class ConfigBean {
@LoadBalanced
@Bean
public RestTemplate getConfigBean(){
return new RestTemplate();
}
}
(4) 修改控制层的类,修改eureka的中心注册地址,名字全部大写
这个是提供者配置文件中的名字

消费者中的这个改为这个名字的全部大写

原文:https://www.cnblogs.com/xiaoyuer0506/p/11823674.html