1、feign和ribbon介绍
Feign
Feign是一个声明式的web service客户端。(简化接口调用)
Ribbon
Ribbon是客户端负载均衡工具
2、环境搭建
由于feign集成了ribbon的方法,因此简单搭建时只需要一个openfeign依赖即可
2.1、pom添加依赖(基于消费者端项目)
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
2.2、application.yml
server:
port: 8200
spring:
application:
name: consumer-server
profiles: dev
eureka:
client:
serviceUrl:
defaultZone: http://localhost:7001/eureka/
instance:
prefer-ip-address: true
feign:
hystrix:
enabled: true #开启HYSTRIX,不然降级无法使用