Created
July 18, 2014 20:59
-
-
Save augustl/3e9ecb8fc813b72ec402 to your computer and use it in GitHub Desktop.
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
(defrecord ZmqRpc [zmq-rpc-url] | |
component/Lifecycle | |
(start [component] | |
(let [ctx (ZMQ/context 1) | |
worker-url "inproc://myapp-api-responders" | |
router-socket (.socket ctx ZMQ/ROUTER) | |
dealer-socket (.socket ctx ZMQ/DEALER)] | |
(.bind router-socket zmq-rpc-url) | |
(.bind dealer-socket worker-url) | |
(dotimes [n 4] | |
(doto (Thread. (zmq-rpc/create-rep-handler (:db component) ctx worker-url)) | |
(.setName (str "myapp-api-zmq-req-" n)) | |
(.start))) | |
(doto (Thread. #(.run (ZMQQueue. ctx router-socket dealer-socket))) | |
(.start)) | |
component)) | |
(stop [component] | |
(doseq [thr (:zmq-rpc-worker-threads component)] | |
(.interrupt thr)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment