Rabbion+RestTemplate实现负载均衡
1 过程
本次博客借助我另一篇博客搭的SpringCloud架子做:
SpringBoot-SpringCloud Netflix——基于idea的简单架构
首先负载均衡,需要至少两个提供者,这些提供者完全一样!
配置Rabbion负载均衡
修改配置文件
2 新建Ribbon消费者
2.1 新建springboot项目
勾选依赖:
ribbon、web、eureka client
2.2 配置yml配置文件
server:
port: 8901
eureka:
client:
service-url:
defaultZone: http://10.8.157.32:8761/eureka/ #对应注册中心配置中的defaultZone
instance:
lease-renewal-interval-seconds: 3 #心跳连接
spring:
application:
name: HelloConsumerRibbon #显示在注册中心需要喊的名字
2.3 配置负载均衡
- config配置文件
新建配置类RibbonConfig
import com.netflix.loadbalancer.*;
import org.springframework.cloud.client.loadbalan