文章目录
Spring Cloud 学习 | - 07 - Feign方式断路器Hystrix
学习
Spring Cloud
之路,文中Spring Boot
版本为2.1.3.RELEASE
,Spring Cloud
版本为Greenwich.SR1
。因能力有限,难免会有不足或者错误之处,还望不吝指正,谢!
接上篇 Spring Cloud 学习 | - 06 - Ribbon整合断路器Hystrix,我们用Ribbon的方式整合了Hystrix,这里,我们用Feign的方式整合断路器Hystrix。
Feign默认有对Hystix的集成:
开始代码
1. 启动Eureka注册中心和服务提供者
1.1 Eureka注册中心
详细情况参阅 Spring Cloud 学习 | - 01 - Eureka服务注册与发现,启动注册中心。
1.2 服务提供者
之前的篇幅已经讲解过,这里贴一下主要代码及配置等。
1.2.1 依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
1.2.2 配置
server:
port: 8090
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka
instance:
prefer-ip-address: true # 返回ip而不是host名称
# ip-address: 127.0.0.1 # 指定自己的ip信息
lease-expiration-duration-in-seconds: 15 # 服务失效时间,默认值90秒
lease-renewal-interval-in-seconds: 5 # 服务续约(renew)的间隔,默认为30秒
spring<