We're using langohr to interact with RabbitMQ. We've tried two different approaches to let RabbitMQ resend messages that has not yet been properly handled by our service. One way that works is to send a
requeue set to the
true but this will resend the message immediately until the service responds with a
basic.ack. This is a bit problematic if the service for example tries to persist the message to a datastore that is currently down (and is down for a while). It would be better for us to just fetch the undelivered messages say every 20 seconds or so (i.e. we neither do a
basic.nack if the datastore is down, we just let the messages be retained in the queue). We've tried to implement this using an
ExecutorService whose gist is implemented like this:
(let [chan (lch/open conn)] ; We create a new channel since channels in Langohr are not thread-safe (log/info "Triggering \"recover\" for channel" chan) (try (lb/recover chan) (catch Exception e (log/error "Failed to call recover" e)) (finally (lch/close chan))))
Unfortunately this doesn't seem to work (the messages are not redelivered and just remains in the queue). If we restart the service the queued messages are consumed correctly. However we have other services that are implemented using spring-rabbitmq (in Java) and they seem to be taking care of this out of the box. I've tried looking in the source code to figure out how they do it but I haven't managed to do so yet.
How do you instruct RabbitMQ to (re-)deliver messages in the queue periodically (preferably using Langohr)?