Search code examples
ruby-on-railsrubyrabbitmqbunny

Hutch & RabbitMQ: set timeout on re-queued messages


When my Hutch consumer loses connection to a database I would like to requeue all the messages I got and try to handle (and save to the DB) them later.

I found I can use requeue! method like this in my consumer:

def process(message)
    handle_message(message)
  rescue ActiveRecord::ConnectionNotEstablished => error
    Rails.logger.warn("Connection to database is broken: #{error}")
    requeue!
  ensure
    ::ActiveRecord::Base.clear_active_connections!
  end
end

But then I will get that message instantly back from Rabbit, and so, my consumer stuck in trying to process this message when it's obviously can't be saved to the DB.

Is it possible to put a timeout on either Hutch or RabbitMQ site in this situation?


Solution

  • As it was answered here https://github.com/gocardless/hutch/issues/161

    Not without using Scheduled delivery exchange, or abusing TTL and dead lettering.