         consumer (atom {:handlers  {}
                         :protocol protocol
                         :zloop zloop
-                        :consumer (agent 0)
                         :socket nil})
         initialize #(let [poller (zmq/poller context 1)
                           socket (q/create-connected-socket


(defprotocol Protocol
  (send! [this socket messages]))


(defrecord MessageProtocol [method]
  Protocol

                      (.addPoller (@consumer :zloop)
                                  (.getItem poller 0)
                                  (q/zloop-handler (fn [] ((handle-incoming consumer)) (int 0)))
                                  {})
                      (send! protocol socket [q/MSG-READY]))]
    (log/info "[consumer] started consumer for" method)
    (swap! consumer assoc
           :handlers {q/MSG-REQ (handle-request consumer handler)}
           :initialize initialize)
    ((@consumer :initialize))
    ; mysterious hack required to start the zloop
    (.addTimer zloop 1000 0 (q/zloop-handler #(do (Thread/sleep 1) 0)) {})

    (.start (Thread. #(.start zloop)))
    consumer))

(defn start
