RabbitMQ keeps stacking unacked messages although they are rejected or acknowledged

416 views Asked by At

My Ruby code below processes RabbitMQ events. I'm using Bunny for Ruby and the sneakers gem. Although I think I'm acting on all possible events, the local channels are getting stacked with unacked messages. This happens every time the log says something like:

sneakers_1          | I, [2017-02-08T19:03:31.088857 #14]  INFO -- : Rejecting 172.21.0.21. Name invalid tld

This is my Ruby code:

require 'sneakers'

class EventProcessor
  include Sneakers::Worker
  from_queue :edge_requests


  def work(msg)
    msg = JSON.parse(msg)
    domain = msg[':path'].split('/').first
    domain = domain.downcase.sub(/^www\./, '')
    domain = Domain.find_or_initialize_by(name: domain) {|domain| domain.status = :active}
    unless domain.valid?
      Rails.logger.info "Rejecting #{domain.name}. #{domain.errors.full_messages.join(',')}"
      reject!
      return
    end
    domain.persisted? ? domain.touch : domain.save!
    ack!
  rescue
    Rails.logger.error $!
    reject!
  end
end

Something is wrong with my reject! probably? kind of stuck for hours. I tried to change all the reject! with ack! but nothing seems to help.

Maybe I'm using rescue the wrong way?

1

There are 1 answers

0
Lauri On

Slightly late answer but faced this issue and the solution is alway return either ack! or reject!.

So change this:

reject!
return

to

return reject!