Created
December 19, 2011 22:36
-
-
Save joshrotenberg/1499232 to your computer and use it in GitHub Desktop.
style of client/worker request
This file contains 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
;; i have this working on the client/send side using a multimethod | |
;; currently, sending looks like this | |
(let [reply (mdc/send! reverse-client "reverse3" "bleh")] | |
;; or like this | |
(let [reply (mdc/send! reverse-client "reverse3" '("bleh" "foo" "bar"))] | |
;; or | |
(let [reply (mdc/send! reverse-client "reverse3" ["bleh" "foo" "bar"])] | |
;; here is how my worker macro works | |
;; this case would assume the first send call above | |
(future (mdw/as-worker "reverse3" "tcp://localhost:5555" | |
(apply str (reverse request)))) | |
;; and this either of the other two | |
(future (mdw/as-worker "reverse3" "tcp://localhost:5555" | |
(map #(apply str (reverse %) request)))) | |
;; its totally up to the application, there is no reason it couldn't send a single value and expect a | |
;; sequence in return or vice versa. its really a question of how much iffing i want to do to see | |
;; if the incoming request is a list or a scalar. | |
(defmacro as-worker | |
[service endpoint & body] | |
`(let [worker# (mdwrkapi. ~endpoint ~service false) | |
reply# (ZMsg.)] | |
(while (not (.isInterrupted (Thread/currentThread))) | |
(let [requezt# (.receive worker# reply#) | |
~'request (map #(.toString %) (.toArray requezt#)) | |
repli# (do ~@body)] | |
(if (seq? repli#) | |
(doall (map #(.add reply# (ZFrame. %)) repli#)) | |
(.add reply# (ZFrame. repli#))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment