# spring-boot-hystrix-fallback
**Repository Path**: zclget/spring-boot-hystrix-fallback
## Basic Information
- **Project Name**: spring-boot-hystrix-fallback
- **Description**: hystrix熔断demo
- **Primary Language**: Java
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2021-10-15
- **Last Updated**: 2021-10-15
## Categories & Tags
**Categories**: Uncategorized
**Tags**: SpringCloud
## README
# spring-boot-hystrix-fallback
#### 介绍
hystrix熔断demo
#### 软件架构
软件架构说明
#### 安装教程
1. 新建eureka-server服务,添加eureka-server依赖,添加yml配置
```xml
org.springframework.cloud
spring-cloud-starter-netflix-eureka-server
```
```yml
server:
port: 8081
eureka:
instance:
hostname: 127.0.0.1
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
```
- 启动,访问http://localhost:8081/
2. 新建spring-boot-spring-feign-hystrix项目,添加hystrix,openfeign,eureka-server依赖,添加yml配置
```xml
org.springframework.boot
spring-boot-starter-parent
2.2.6.RELEASE
org.zcl
boot-spring-feign-hystrix
0.0.1-SNAPSHOT
boot-spring-feign-hystrix
boot-spring-feign-hystrix
1.8
Hoxton.SR1
org.springframework.cloud
spring-cloud-starter-hystrix
1.4.6.RELEASE
org.springframework.cloud
spring-cloud-starter-openfeign
org.springframework.cloud
spring-cloud-starter-netflix-eureka-server
org.projectlombok
lombok
true
org.springframework.boot
spring-boot-starter-test
test
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
```
```yml
spring:
application:
name: movie
server:
port: 8083
eureka:
client:
serviceUrl:
defaultZone: http://127.0.0.1:8081/eureka
feign:
hystrix:
enabled: true
```
- springcloud2020已经移除了hystrix,这里用的是Hoxton.SR1版本
- 启动类添加配置,开启feign,开启hystrix,开启服务注册
```java
@EnableEurekaClient
@SpringBootApplication
@EnableFeignClients
@EnableHystrix
```
- 调用feign接口userFeignClient.findById(id)
- @FeignClient(name = "spring-boot-user", fallbackFactory = HystrixClientFallbackFactory.class),配置调用服务应用名,配置熔断fallback
- HystrixClientFallbackFactory实现FallbackFactory接口,重写create方法
3. 新建调用端服务spring-boot-user
#### 使用说明
1. 先启动spring-boot-eureka-server服务作为注册中心服务端
2. 然后启动spring-boot-spring-feign-hystrix
3. 发请求调用http://localhost:8083/movie/1,如果spring-boot-user服务调用失败,会走fallback,返回兜底值
#### 参与贡献
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request
#### spring-cloud相关依赖
1. spring-cloud-starter-netflix-eureka-server
2. spring-cloud-starter-openfeign
3. spring-cloud-starter-hystrix