Created
March 5, 2017 21:11
-
-
Save olegakbarov/137ebff5a16851f6318d712d06f56244 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(ns my.app | |
(:require | |
[aleph.http :refer :all] | |
[compojure.core :refer [defroutes GET]] | |
[compojure.handler :as handler] | |
[lamina.core :refer :all] | |
[com.netflix.hystrix.core :as hystrix] | |
[clj-http.client :as client])) | |
(defn get-pants [] | |
(client/get "http://pants-service")) | |
(hystrix/defcommand find-pants | |
{:hystrix/fallback-fn (constantly {})} | |
[] | |
(let [response (get-pants)] | |
(if (= 200 (:status response)) | |
(:body response) | |
{}))) | |
(defn- find-pants-observable [] (hystrix/observe #'find-pants)) | |
(defn- pants-request-handler [channel request] | |
(-> (find-pants-observable) | |
(.subscribe | |
#(enqueue channel {:status 200 :body %}) | |
#(println "ERROR " %)))) | |
(defroutes routes | |
(GET "/pants" [] (wrap-aleph-handler pants-request-handler))) | |
(defn make-app [] | |
(handler/api routes)) |
This file contains hidden or 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
(ns my.integration.t-app | |
(:require | |
[midje.sweet :refer :all] | |
[aleph.http :refer :all] | |
[lamina.core :refer :all] | |
[clj-http.client :as client] | |
[my.app :refer :all])) | |
(defn do-get ([uri] (do-get uri {})) | |
([uri params] | |
(let [app (wrap-ring-handler (make-app))] | |
(app ch {:uri uri :params params :request-method :get}) | |
(:body @(read-channel ch))))) | |
(fact "pants are not trousers" | |
(do-get "/pants") => "are not trousers" | |
(provided | |
(client/get anything) => "are not trousers")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment