RabbitMQ会不断堆积未确认的消息,尽管它们会被拒绝或确认 [英] RabbitMQ keeps stacking unacked messages although they are rejected or acknowledged
问题描述
下面的我的Ruby代码处理RabbitMQ事件.我正在将Bunny for Ruby和运动鞋gem 使用.尽管我认为我正在处理所有可能发生的事件,但是本地渠道中堆积着许多未经确认的消息.每当日志显示以下内容时就会发生这种情况:
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
这是我的Ruby代码:
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
我的reject!
可能有问题吗?停留了几个小时.我试图用ack!
更改所有reject!
,但似乎无济于事.
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.
也许我使用错误的方式rescue
?
Maybe I'm using rescue
the wrong way?
推荐答案
答案稍晚,但遇到此问题,解决方案是始终返回ack!
或reject!
.
Slightly late answer but faced this issue and the solution is alway return either ack!
or reject!
.
所以改变这个:
reject!
return
到
return reject!
这篇关于RabbitMQ会不断堆积未确认的消息,尽管它们会被拒绝或确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!