I'm working on a program that needs to make multiple calls to various microservices, possibly do some processing on those results, and then return a combination of those processes.
A very basic example might look like:
(def urls ["http://localhost:8080" "http://localhost:8080"]) (defn handle-http-request [url] (let [request (http-kit/get url)] (do-some-processing (:body @request)))) (defn home-page [request] (let [response (pmap handle-http-request urls)] (ring-resp/response {:buildings (first response) :characters (second response)})))
In this case i'm using pmap
to handle running all my requests in parallel, and then return them as JSON that the UI making the request can handle. In the real environment there will be more URLs each fetching different data.
My question is whether this is an appropriate way to handle this problem? I've looked some core.async, and see it as a possible way to handle this but worry it might be overkill? My second concern is handling errors, it would appear that core.async might be able to more elegantly handle issues where a remote has timed out. Am I right in this assumption, or is using pmap
okay in this situation?
没有评论:
发表评论