我的问题类似于之前提出的问题,但是它没有找到答案,我有一个消费者,我想处理一个称为 Web 服务的操作,但是,如果这个 Web 服务由于某种原因没有响应,我想要消费者不处理 RabbitMQ 的消息,但我将其设置为稍后处理,我的消费者如下:
require File.expand_path('../config/environment.rb', __FILE__)
conn=Rabbit.connect
conn.start
ch = conn.create_channel
x = ch.exchange("d_notification_ex", :type=> "x-delayed-message", :arguments=> { "x-delayed-type" => "direct"})
q = ch.queue("d_notification_q", :durable =>true)
q.bind(x)
p 'Wait ....'
q.subscribe(:manual_ack => true, :block => true) do |delivery_info, properties, body|
datos=JSON.parse(body)
if datos['status']=='request'
#I call a web service and process the json
result=Notification.send_payment_notification(datos.to_json)
else
#I call a web service and process the body
result=Notification.send_payment_notification(body)
end
#if the call to the web service, the web server is off the result will be equal to nil
#therefore, he did not notify RabbitMQ, but he puts the message in UNACKED status
# and does not process it later, when I want him to keep it in the queue and evaluate it afterwards.
unless result.nil?
ch.ack(delivery_info.delivery_tag)
end
end
RabbitMQ 的图像,
语句中有某种方式:c hack(delivery_info.delivery_tag),这样可以代替删除队列的元素,以后再处理,有什么想法吗?谢谢