我有一个使用RabbitMQ队列的ruby进程:
AMQP.start(:host => $AMQP_URL) do |connection|
@channel ||= AMQP::Channel.new(connection)
@queue ||= @channel.queue("results")
@queue.subscribe do |body|
puts "Received -> #{body}"
# Publish the same message again to the same queue
end
end
我知道这不切实际,但我很想知道我应该如何将相同的消息发布到同一个队列中,但是对于我来说直接通道并不合适,如果有的话甚至只是为了保持队列中的msg而不是删除它或只是再次重新发布msg它会很棒
有什么想法吗?
答案 0 :(得分:1)
这样做的正确方法就是拒绝带有否定确认的消息,它将自动重新排队:
@queue.subscribe do |metadata, payload|
# reject and requeue
channel.reject(metadata.delivery_tag, true)
end
无论如何,如果您想手动进行发布,前面示例中的“metadata”参数将为您提供所需的所有信息。