我有一个有 1 名工人的队列。暗示。看起来像这样:
def work
connection = get_connection
connection.start
channel = connection.create_channel
queue = channel.queue("crawl", :durable => true)
multi_log " [*] Worker waiting for messages in #{queue.name}. To exit press CTRL+C"
begin
queue.subscribe(:ack => true, :block => true) do |delivery_info, properties, message|
multi_log " [x] Worker received #{message}"
process_work message
channel.ack(delivery_info.delivery_tag)
multi_log " [x] Worker job done for #{message}"
end
rescue => e
log.error e.message
log.error e.backtrace.join("\n")
connection.close
end
end
只要作业执行,消费者就会阻塞。据我了解,该消费者一次处理一项工作。但让我感到困惑的是,在 RabbitMQ 管理 UI 中,我有时会看到该队列有 2 或 3 个 Unacked。但这怎么可能?