Skip to content

Instantly share code, notes, and snippets.

@daveray
Last active December 24, 2015 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daveray/6802219 to your computer and use it in GitHub Desktop.
Save daveray/6802219 to your computer and use it in GitHub Desktop.
hystrix clj bindings
; 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