hystrix简介

647 阅读1分钟

一、hystrix简介

1. hystrix是什么?

  1. hystrix是一个熔断器组件,目前已经处于维护状态
  2. 它设计用来当分布式系统发生不可避免的异常的时候去隔离当前服务和远程服务、系统、三方包的联系,防止出现级联失败的情况,从而导致整个系统奔溃

2. hystrix文档

  1. wiki介绍:github.com/Netflix/Hys…
  2. API介绍:netflix.github.io/Hystrix/jav…

3. hystrix主要功能有哪些

3.1 延迟和容错

  1. 无级联失败;失败转移和优雅降级;快速失败和恢复
  2. 失败时基于线程和信号量的断路器隔离

3.2 实时响应

  1. 实时监控并更改相关配置,例如触发熔断机制等
  2. 秒级别的触发报警、作出决定以及查看结果

3.3 并发

  1. 并发执行

4. Hello World

  1. 采用api方式编程
  2. 更多的使用方式参见:github.com/Netflix/Hys…
public class CommandHelloWorld extends HystrixCommand<String> {

    private final String name;

    public CommandHelloWorld(String name) {
        super(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"));
        this.name = name;
    }

    @Override
    protected String run() {
        return "Hello " + name + "!";
    }
}

// 使用方式,直接执行、加入队列、添加监听器
String s = new CommandHelloWorld("Bob").execute();
Future<String> s = new CommandHelloWorld("Bob").queue();
Observable<String> s = new CommandHelloWorld("Bob").observe();

5. Dashboard

  1. hystrix工程中的dashboard已经废弃了,现在迁移到:github.com/Netflix-Sku…
  2. hystrix的stream配置:github.com/Netflix/Hys…