I'm trying to implement a carmine worker in a constantly running process.
When launching the following app with lein run myclass.foo
, it just starts the worker and stops it right away.
(def my-worker
(car-mq/worker queue-server "my-queue"
{:handler (fn [{:keys [message attempt]}]
(println "Received" message)
{:status :success})
:auto-start false}))
(defn -main []
(car-mq/start my-worker))
My goal is something like that
Running it with lein foo
was the wrong approach. I edited the entire question to conform with the 'solution' I found.
The main problem was, that I was using lein run myclass.foo
to run it. lein trampoline run myclass.foo
launches the app's JVM and gets rid of leiningen's, with seems to be exactly what I need. When using trampoline
instead of run
, the app doesn't exit right away.
Step 2, to close the connection on ctrl-c is a simple shutdown hook
(.addShutdownHook (Runtime/getRuntime) (Thread. #(car-mq/stop my-worker)))