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執行期間的響應階段進行回調。
HystrixCommandExecutionHook method | when Hystrix calls the method |
---|---|
onStart |
before the HystrixInvokable begins executing |
onEmit |
whenever the HystrixInvokable |
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 THREAD ExecutionIsolationStrategy |
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 HystrixInvokable emits 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 |
怎麽使用
hystrix文檔翻譯之插件