SpringCloud——Hystrix 知识篇

目录

Hystrix- 注意

Hystrix-0 Hystrix 的官方简介

Hystrix-1 Hystrix 的开发步骤

Hystrix-1.1 Hystrix fallbackMethod进入

Hystrix-2.1 Health——commandProperties 

Hystrix-2.2 Health——autuactor

Indicator及Metrics Stream

Hystrix——feign和fallback方法的@Component

如何禁用单个FegionClient的Hystrix的支持

Feign使用fallbackFactory属性打印fallback异常


  • Hystrix- 注意

使用Hystrix必须注入autuactor依赖,不然启动不起来

  • Hystrix-0 Hystrix 的官方简介

  1. 官方文档:https://projects.spring.io/spring-cloud/spring-cloud.html#_circuit_breaker_hystrix_clients
  2. javanica文档:https://github.com/Netflix/Hystrix/tree/master/hystrix-contrib/hystrix-javanica
  • Hystrix-1 Hystrix 的开发步骤

  1. 1、添加pom.xml依赖
<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
  1. 2、 启动类添加注解@EnableCircuitBreaker
@SpringBootApplication
@EnableEurekaClient
@EnableCircuitBreaker
public class Hystrix001Application {

   @Bean
   public RestTemplate restTemplate() {
      return new RestTemplate();
   }
   public static void main(String[] args) {
      SpringApplication.run(Hystrix001Application.class, args);
   }

}
  1. 3、方法名称中添加注解@HystrixCommand,并且自定义返回方法【返回方法的参数返回值、入参一定要和注解相同】
@RestController
public class MovieController {
    @Autowired
    private RestTemplate restTemplate;

    @Value("${user.userServicePath}")
    private String userServicePath;

    @GetMapping("/movie/{id}")
    @HystrixCommand(fallbackMethod = "findByIdfallback")
    public User findById(@PathVariable Long id) {
        return this.restTemplate.getForObject(this.userServicePath + id, User.class);
    }

    public User findByIdfallback() {
        User user = new User();
        user.setId(1110504125L);
        user.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值