Skip to content

Instantly share code, notes, and snippets.

@ck
Created October 28, 2013 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ck/7203964 to your computer and use it in GitHub Desktop.
Save ck/7203964 to your computer and use it in GitHub Desktop.
Reuse connection in worker
(defrecord QueueWorker [queue worker-fn]
daemon/Daemon
(start [_]
(reset! done false)
(msg/with-connection {} ; use single connection for receive
(loop []
(when-not @done
;; make sure we re-use the same HornetQ connection
(info "Worker Connection" (:connection ((get-thread-bindings) #'immutant.messaging.core/*options*)))
(when-let [msg (msg/receive queue :timeout 5000)]
(worker-fn msg))
(recur)))))
(stop [_]
(reset! done true)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment