我看到旧的gem版本在2015年左右支持在Sneakers.configure
参数中定义这类东西,但现在已经不是这样了。所以我试图找到替代方案,但运动鞋wiki没有任何细节,我也找不到任何方法来完成它通过寻找运动鞋的源代码。
我需要我的工作人员能够“知道”尝试发送消息失败的次数,以便选择是重新排队还是拒绝该消息
配置
Sneakers.configure(
heartbeat: 60,
amqp: "amqp://#{ENV['RABBITMQ_USER']}:#{ENV['RABBITMQ_PASS']}@#{ENV['RABBITMQ_HOST']}",
daemonize: ENV['RACK_ENV'] == 'production',
pid_path: './sneakers.pid',
vhost: '/',
exchange: 'sneakers',
exchange_type: :direct,
timeout_job_after: 2.minutes,
workers: 1,
properties: {
connection_name: 'worker'
}
)
Sneakers.logger.level = Logger::DEBUG
workers = Sneakers::Runner.new([Workers::BB])
workers.run
工人
module Workers
##
class BB
include Sneakers::Worker
from_queue :backbone
def work(msg)
failed_atempts = 0 ## ! need to find out the failed attempt count
## ... handle message ...
ack!
rescue StandardError => e
log :fatal, e.message
log :fatal, e.backtrace
requeue! if failed_attempts <= 5
reject! if failed_attempts > 5
end
end
end
1条答案
按热度按时间gwbalxhn1#
目前,这是我找到的唯一方法,我使用
work_with_params
代替work
,然后使用publish
手动重新排队消息,并手动配置自定义报头