File tree Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change 55 :license {:name " Eclipse Public License"
66 :url " http://www.eclipse.org/legal/epl-v10.html" }
77
8- :dependencies [[clj-http " 2.0.1 " ]
8+ :dependencies [[clj-http " 2.3.0 " ]
99 [com.netflix.hystrix/hystrix-clj " 1.4.23" ]
1010 [org.clojure/clojure " 1.8.0" ]
1111 [org.clojure/tools.logging " 0.3.1" ]
Original file line number Diff line number Diff line change 161161 " Deactivate clj-http-hystrix."
162162 []
163163 (hooke/remove-hook #'http/request ::wrap-hystrix ))
164+
165+ (defn wrap-hystrix
166+ " Middleware for adding hystrix to a clj-http client request.
167+
168+ Alternative to `add-hook`. Do not use both `wrap-hystrix` and `add-hook`.
169+
170+ ;; add wrap-hystrix to the middleware chain
171+ (clj-http.client/with-additional-middleware [wrap-hystrix]
172+ (clj-http.client/get ...))
173+
174+ ;; or if you want to provide your own defaults
175+ (clj-http.client/with-additional-middleware [(partial wrap-hystrix {:hystrix/timeout-ms 6000})]
176+ (clj-http.client/get ...))
177+ "
178+ ([client] (wrap-hystrix {} client))
179+ ([defaults client]
180+ (let [wrapper (hystrix-wrapper defaults )]
181+ (fn [req]
182+ (wrapper client req)))))
Original file line number Diff line number Diff line change 210210 (make-hystrix-call {:hystrix/fallback-fn (constantly " baz" )}) => " baz" )
211211 (remove-hook )
212212 (add-hook ))
213+
214+ (fact " wrap-hystrix enables clj-http-hystrix to be incorporated as a middleware"
215+ (remove-hook )
216+ ; verify hystrix is enabled by exceeding the default timeout (1000 ms)
217+ (http/with-additional-middleware [wrap-hystrix]
218+ (rest-driven
219+ [{:method :GET
220+ :url " /" }
221+ {:status 200
222+ :after 1500 }]
223+ (make-hystrix-call {})
224+ => (throws clojure.lang.ExceptionInfo " clj-http: status 503" )))
225+
226+ ; verify custom defaults are supported
227+ (http/with-additional-middleware
228+ [(partial wrap-hystrix {:hystrix/fallback-fn (constantly {:status 404 })})]
229+ (rest-driven
230+ [{:method :GET
231+ :url " /" }
232+ {:status 500 }]
233+ (make-hystrix-call {})
234+ => (throws clojure.lang.ExceptionInfo " clj-http: status 404" ))))
You can’t perform that action at this time.
0 commit comments