Last active
December 24, 2015 13:09
-
-
Save daveray/6802219 to your computer and use it in GitHub Desktop.
hystrix clj bindings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; https://github.com/Netflix/Hystrix | |
; Hystrix is a latency and fault tolerance library designed to | |
; isolate points of access to remote systems, services and 3rd party | |
; libraries, stop cascading failure and enable resilience in complex | |
; distributed systems where failure is inevitable. | |
; Define a vanilla function | |
(defn search | |
"Fault INtolerant search" | |
[term] | |
... execute service request and return vector of results ...) | |
; Turn it into a HystrixCommand | |
(defcommand search | |
"Fault tolerant search" | |
[term] | |
... execute service request and return vector of results ...) | |
; Same as above, but add fallback and caching | |
(defcommand search | |
"Fault tolerant search" | |
{:hystrix/cache-key-fn identity | |
:hystrix/fallback-fn (constantly []))} | |
[term] | |
... execute service request and return vector of results ...) | |
; Call it like a normal function | |
(search "The Big Lebowski") | |
;=> [... vector of results ...] | |
; Execute the search command and get a future | |
(queue #'search "Fargo") | |
;=> a deref-able future | |
; Execute the search command and get an rx.Observable<T> | |
(observe #'search "The Hudsucker Proxy") | |
;=> rx.Observable<T> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment