Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Whenever you make an http request, add one or more of the hystrix-clj options to
:hystrix/breaker-request-volume 20
:hystrix/breaker-error-percent 50
:hystrix/breaker-sleep-window-ms 5000
:hystrix/bad-request-pred client-error?}}
:hystrix/bad-request-pred client-error?}}
```
Any values not supplied will be set to their default values as above. Requests with no Hystrix-related keys won't use Hystrix.

Expand Down
20 changes: 12 additions & 8 deletions src/clj_http_hystrix/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
:hystrix/threads
:hystrix/queue-size
:hystrix/timeout-ms
:hystrix/breaker-request-volume
:hystrix/breaker-error-percent
:hystrix/breaker-sleep-window-ms
:hystrix/bad-request-pred})

(defn default-fallback [req resp]
Expand Down Expand Up @@ -63,10 +66,10 @@
(.withCoreSize threads)
(.withMaxQueueSize (:hystrix/queue-size config 5))
(.withQueueSizeRejectionThreshold (:hystrix/queue-size config 5)))]
(-> (HystrixCommand$Setter/withGroupKey (group-key group))
(.andCommandKey (command-key (:hystrix/command-key config :default)))
(.andCommandPropertiesDefaults command-configurator)
(.andThreadPoolPropertiesDefaults thread-pool-configurator))))
(doto (HystrixCommand$Setter/withGroupKey (group-key group))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed this to be consistent with rest of fn

(.andCommandKey (command-key (:hystrix/command-key config :default)))
(.andCommandPropertiesDefaults command-configurator)
(.andThreadPoolPropertiesDefaults thread-pool-configurator))))

(defn ^:private log-error [command-name ^HystrixCommand context]
(let [message (format "Failed to complete %s %s" command-name (.getExecutionEvents context))]
Expand Down Expand Up @@ -101,7 +104,7 @@
:message "Bad request pred"
:stack-trace (stack-trace)})))
resp))
wrap-exception-reponse (fn [resp] ((http/wrap-exceptions (constantly resp)) (assoc req :throw-exceptions true)))
wrap-exception-response (fn [resp] ((http/wrap-exceptions (constantly resp)) (assoc req :throw-exceptions true)))
^HystrixCommand$Setter configurator (configurator req)
logging-context (or (MDC/getCopyOfContextMap) {})
command (proxy [HystrixCommand] [configurator]
Expand All @@ -117,12 +120,13 @@
(assoc :throw-exceptions false)
f
wrap-bad-request
wrap-exception-reponse)))]
wrap-exception-response)))]
(handle-exception #(.execute command) req))
(f req)))

(defn add-hook []
(defn add-hook
"Activate clj-http-hystrix to wrap all clj-http client requests as
hystrix commands."
(when (not (some-> (meta http/request) :robert.hooke/hooks deref (contains? #'wrap-hystrix)))
[]
(when-not (some-> (meta http/request) :robert.hooke/hooks deref (contains? #'wrap-hystrix))
(hooke/add-hook #'http/request #'wrap-hystrix)))