Search code examples
clojurejvmrabbitmq

RabbitMQ: Client does not receive messages sent before client boots


I am using RabbitMQ with Langohr (the clojure client). I can receive messages fine if the consumer is already running, but if I send messages before the client is booted, the client never receives those messages.

Is there a configuration option (or constellation of configuration options for both server and client) that ensures the client can receive messages generated before it was running?

How do I start trying to test or debug this?

I am using the default exchange. Here is the code I'm using to set up the client:

(ns sisyphus.rabbit
  (:require
   [cheshire.core :as json]
   [langohr.core :as lcore]
   [langohr.channel :as lchannel]
   [langohr.exchange :as lexchange]
   [langohr.queue :as lqueue]
   [langohr.consumers :as lconsumers]
   [langohr.basic :as lbasic]
   [sisyphus.log :as log]))

(defn connect!
  [config]
  (let [connection (lcore/connect {})
        channel (lchannel/open connection)
        _ (lbasic/qos channel 1)
        queue-name (get config :queue "sisyphus")
        exchange (get config :exchange "")
        queue (lqueue/declare channel "sisyphus" {:exclusive false :durable true})
        routing-key (get config :routing-key "sisyphus")]
    (if-not (= exchange "")
      (lqueue/bind channel queue-name exchange {:routing-key routing-key}))
    {:queue queue
     :queue-name queue-name
     :exchange exchange
     :routing-key routing-key
     :connection connection
     :channel channel
     :config config})

Then to publish:

(defn publish!
  [rabbit message]
  (lbasic/publish
   (:channel rabbit)
   (:exchange rabbit)
   (:routing-key rabbit)
   (json/generate-string message)
   {:content-type "text/plain"
    :peristent true}))

Thanks!


Solution

  • It turns out you need to set :auto-delete false to get a durable queue to behave well. The more you know!