             [apio.brokers.core :as brk])
   (:gen-class))
 
-(defn dispatch-one-task
+(defn- dispatch-task
   [pool task semaphore]
   (sem/acquire semaphore)
   (let [task-wrapper (fn []

  [path & args]
  (core/with-config path
    (let [queue   (q/queue (core/max-prefetch))
          thr     (thr/thread #(task-dispatcher queue))]

      ;; Add hook for keyboard interruption (sigint) and
      ;; properly close RabbitMQ connection.

                       (sem/release semaphore))]
    (thr/spawn pool task-wrapper)))

(defn- dispatcher
  [^Queue queue]
  (let [numworkers  (core/max-workers)
        pool        (thr/start-pool numworkers)
        semaphore   (sem/semaphore numworkers)]
    (loop []
      (let [task (q/rcv queue)]
        (do (dispatch-task pool task semaphore) (recur))))
    (thr/shutdown-pool pool)))

(defn- messages-dispatcher
  "Broker callback for receive messages."
  [^Queue queue]
  (let [dispatcher (fn [^String message & args]
