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
- Launch the foo listener
- foo listener runs in foreground and prints everything that gets posted to the queue
- Ctrl-c / quit will close the listener
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 usingtrampoline
instead ofrun
, the app doesn't exit right away.Step 2, to close the connection on ctrl-c is a simple shutdown hook