hystrix文档翻译之插件
插件
可以通过实现插件来改变Hystrix的行为。可以通过HystrixPlugins来注册自定义插件,这些插件会被应用到HystrixCommand,HystrixObservableCommand和HystrixCollapser。
插件类型
- 事件通知
在HystrixCommand和HystrixObservableCommand执行过程中会触发一些时间,实现HystrixEventNotifier可以监听这些事件进行一些告警和数据收集。
- 发布metrics
通过实现HystrixMetricsPublisher可以获取所有实例的metrics信息,这样我们就可以获取和存储这些metrics信息,以便后续处理。默认的实现不会发布这些metrics信息。
- 配置策略
通过实现HystrixPropertiesStrategy可以改变配置的默认实现。系统默认使用Archaius.
- 并发策略
Hystrix实现ThreadLocal,Callable,Runnable,ThreadPoolExecutor和BlockingQueue来实现线程隔离和请求作用域。
Hystrix默认已经实现了这些功能,也提供了插件让用户通过实现HystrixConcurrencyStrategy可以实现自定义的组件:
getThreadPool和getBlockingQueue方法可以让你实现自定义的线程池和队列。
wrapCallable方法可以让你对Callable进行处理,
getRequestVarible方法实现一个请求作用域。
- HystrixCommandExecutionHook
通过实现HystrixCommandExecutionHook可以在HystrixCommand或HystrixObservableCommand执行期间的响应阶段进行回调。
HystrixCommandExecutionHookmethod |
when Hystrix calls the method |
|---|---|
onStart |
before the HystrixInvokable begins executing |
onEmit |
whenever the HystrixInvokable emits a value |
onError |
if the HystrixInvokable fails with an exception |
onSuccess |
if the HystrixInvokable completes successfully |
onThreadStart |
at the start of thread execution if the HystrixInvokable is a HystrixCommand executed using the THREADExecutionIsolationStrategy |
onThreadComplete |
at the completion of thread execution if the HystrixInvokable is a HystrixCommand executed using the THREAD ExecutionIsolationStrategy |
onExecutionStart |
when the user-defined execution method in the HystrixInvokable begins |
onExecutionEmit |
whenever the user-defined execution method in the HystrixInvokable emits a value |
onExecutionError |
when the user-defined execution method in the HystrixInvokable fails with an exception |
onExecutionSuccess |
when the user-defined execution method in the HystrixInvokable completes successfully |
onFallbackStart |
if the HystrixInvokable attempts to call the fallback method |
onFallbackEmit |
whenever the fallback method in the HystrixInvokableemits a value |
onFallbackError |
if the fallback method in the HystrixInvokable fails with an exception or does not exist when a call attempt is made |
onFallbackSuccess |
if the fallback method in the HystrixInvokable completes successfully |
onCacheHit |
if the response to the HystrixInvokable is found in the HystrixRequestCache |
怎么使用
当我们第一次使用HystrixCommand时,他就会初始化插件,所以我们不能在运行时来定义自定义组件。如果我们通过Archaius注册了组件,Hystrix会使用注册的组件,如果没有,会使用默认的组件。
也可以在调用HystrixCommand之前,通过下面的语句注册组件
HystrixPlugins.getInstance().registerEventNotifier(ACustomHystrixEventNotifierDefaultStrategy.getInstance());
接口还是虚拟类
我们通常通过继承虚拟类而不是接口来实现组件功能,有一下两个原因:
- 默认实现
通过虚拟类,只需要实现想要自定义的方法,并且可以重用默认的实现。每一个方法都是相互独立,并且不会互相影响。
- 架包维护
随着Hystrix的发展,这些插件可能会增加一些新的方法和功能,那么用户在更新时必须定制实现这些方法和功能。如果使用接口来实现插件,那么每次hystrix增加新的插件功能时,用户必须增加这些实现。在java8中可以在接口中定义默认方法,但是之前的并不行。所以通过实现虚拟类可以避免这样的情况。
hystrix文档翻译之插件的更多相关文章
- Android官方技术文档翻译——Gradle 插件用户指南(5)
昨晚把第五章未译完的几句话攻克了.只是第六章没怎么译,明后天又是周末,假设周一前第六章翻译完的话,周一再发第六章. 本文译自Android官方技术文档<Gradle Plugin User Gu ...
- Android官方技术文档翻译——Gradle 插件用户指南(4)
最近赶项目,白天基本没时间,只有晚上在家的时候才能看一看.昨天晚上只翻译完了第四章,今天就只发第四章吧. 本文译自Android官方技术文档<Gradle Plugin User Guide&g ...
- Android官方技术文档翻译——Gradle 插件用户指南(7)
本文译自Android官方技术文档<Gradle Plugin User Guide>,原文地址:http://tools.android.com/tech-docs/new-build- ...
- Android官方技术文档翻译——Gradle 插件用户指南(6)
没想到翻译这篇<Gradle 插件用户指南>拖了差不多一个月,还跨年了.不过还好,在2号时终于一口气把剩下的给翻译完了(其实那天剩下的也就不到一章). 今天先发一下第六章,明天再发第七章. ...
- hystrix文档翻译之配置
Hystrix使用Archaius作为配置的默认实现,下面介绍的是HystrixPropertiesStrategy的默认实现,你也可以通过插件方式重新实现. 每一个配置有四个级别: 全局默认 当下面 ...
- Android官方技术文档翻译——Gradle 插件用户指南(1-3)
不知道是什么网络问题,上午一直发不了博客,其它页面基本正常,就是在写博客这里,每次打开都是响应超时.刚才用了VPN,顺便试了一下,竟然能够编辑.想是CDN之类的问题吧. 这次翻译的是Gradle 插件 ...
- hystrix文档翻译之Dashboard
Dashboard Hystrix Dashboard可以让你实时监控hystrix的metrics信息. 当netflix开始使用dashboard后,运维效率得到了极大的提升,并且极大降低了大多数 ...
- hystrix文档翻译之metrics
metrics和监控 动机 HystrixCommands和HystrixObservableCommands执行过程中会产生相关运行情况的metrics.这些metrics对于监控系统表现有很大的 ...
- hystrix文档翻译之运维
hystrix不仅用作工程可靠性还可以用来运维. 这里将会分享一个拥有100+Hystrix命令,40+线程池,每天有100亿次线程请求,2000亿次信号量请求的系统是如何使用hystrix运维的.这 ...
随机推荐
- SpringSecurity权限管理系统实战—四、整合SpringSecurity(上)
目录 SpringSecurity权限管理系统实战-一.项目简介和开发环境准备 SpringSecurity权限管理系统实战-二.日志.接口文档等实现 SpringSecurity权限管理系统实战-三 ...
- Jmeter系列(50)- 详解 If 控制器
如果你想从头学习Jmeter,可以看看这个系列的文章哦 https://www.cnblogs.com/poloyy/category/1746599.html 简单介绍 可以通过条件来控制是否运行其 ...
- Jmeter 常用函数(12)- 详解 __machineName
如果你想查看更多 Jmeter 常用函数可以在这篇文章找找哦 https://www.cnblogs.com/poloyy/p/13291704.html 作用 返回机器(电脑)名称 语法格式 ${_ ...
- Gitlab安装使用
Gitlab安装使用 1. 为什么要使用gitlab Git的优点多多这里就不详细介绍了: Git是版本控制系统,Github是在线的基于Git的代码托管服务: Github有个小缺陷 (也不能算是缺 ...
- cinder 卷迁移进度的代码分析
一.cinder-api服务的入口函数 D:\code-program\cinder-ocata_cinder\cinder\api\contrib\admin_actions.py from cin ...
- Robot Framework(5)——自动化示例
上篇介绍了一些selenium2在robot framework中的一些关键字,这一篇主要来记录一下实际应用 一.安装并导入Selenium2Library 安装的工作一开始已经完成,可以用pip l ...
- 【从零开始撸一个App】PKCE
一个成功的App背后肯定有一堆后端服务提供支撑,认证授权服务(Authentication and Authorization Service,以下称AAS)就是其中之一,它是约束App.保障资源安全 ...
- 基于Nodejs的sequelize操纵数据库
## 使用基于ORM架构的sequelize操纵数据库 ### 1.技术背景 ```Sequelize是一个基于promise的关系型数据库ORM框架,*********************技术文 ...
- Kubernetes-14:一文详解Pod、Node调度规则(亲和性、污点、容忍、固定节点)
Kubernetes Pod调度说明 简介 Scheduler 是 Kubernetes 的调度器,主要任务是把定义的Pod分配到集群的节点上,听起来非常简单,但要考虑需要方面的问题: 公平:如何保证 ...
- Mac OSX上安装Nginx
1. 通过brew instal nginx安装 ==> Downloading https://homebrew.bintray.com/bottles/nginx-1.10.1.el_cap ...