         relpath (:relpath (:entry body))
         delivery-tag (:delivery-tag metadata)
         fp (string/join File/separator [directory relpath])
+        nack-this-message #(lb/nack ch delivery-tag false false)
         ;; converted (tika/parse fp)
         ]
         ;;
-    (future
-      (try
-        (let [converted (convert fp)]
-          ;; (println "before ack" (Thread/currentThread) (:delivery-tag metadata))
+    (register-future
+     (future
+       (try
+         (let [converted (convert fp)]
+           ;; (println "before ack" (Thread/currentThread) (:delivery-tag metadata))
 
-          (lb/publish ch
-                      exchange
-                      (routing-key-string-with-command routing-key "import_file")
-                      (json/write-str (assoc body "tika-content" converted)))
-          (lb/ack ch delivery-tag)
-          (println "done" fp " ****" ))
-        (catch Throwable err
+           (lb/publish ch
+                       exchange
+                       (routing-key-string-with-command routing-key "import_file")
+                       (json/write-str (assoc body "tika-content" converted)))
+           (lb/ack ch delivery-tag))
+         (catch Exception err
+           (println "got exception while handling" fp err)
+           (trace/print-stack-trace err)
+           (lb/nack ch delivery-tag false false))))
+     {:cleanup-on-error nack-this-message
+      :fp fp})
 
-          (println "got exception while handling" fp err)
-          (trace/print-stack-trace err)
-          (lb/nack ch delivery-tag false false))))
 
-    (println "scheduled" fp " ****" )))
+    ;; (println "scheduled" fp " ****" )
+    ))
 
     ;; (println "dir" fp " ****" (:content-type converted))))
 

  (:require [clojure.stacktrace :as trace])
  (:require [tika])
  (:import java.io.File)
  (:gen-class))


(defn map-from-routing-key-string

  (alter-var-root #'*read-eval* (constantly false))



  (let [[options args banner]
        (cli/cli args
                 ["--ampqp-url" "amqp url to connect to"]
