RabbitMQ keeps stacking unacked messages although they are rejected or acknowledged

天大地大妈咪最大 提交于 2019-12-13 07:24:24

问题


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:


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!


来源:https://stackoverflow.com/questions/42123190/rabbitmq-keeps-stacking-unacked-messages-although-they-are-rejected-or-acknowled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!