Reputation: 11687
I am using RabbitMq for communication, and I would like to consume just one message and unsubscribe. How to do it in ruby bunny? My subscribe block is pretty easy:
queue.subscribe(block: true) do |delivery_info, properties, payload|
puts "[consumer] #{q.name} received a message: #{payload}"
end
Upvotes: 1
Views: 1147
Reputation: 1879
Another way could be using #pop method of queue.
conn = Bunny.new
conn.start
ch = conn.create_channel
q = ch.queue("queue_name")
delivery_info, properties, payload = q.pop
You can find more details about it here
Upvotes: 0
Reputation: 11
You probably already figured it out by now, but for anyone else...
According to the documentation, you can just use basic_get. For example,
conn = Bunny.new
conn.start
ch = conn.create_channel
delivery_info, properties, message = ch.basic_get("your_queue_name", :ack => true)
ch.acknowledge(delivery_info.delivery_tag)
Upvotes: 1