amqp
amqp copied to clipboard
How to ensure that a single message is published?
Try running the following Ruby file:
require 'rubygems'
require 'mq'
EM.run {
amq = MQ.new
queue = amq.queue("whatev")
queue.publish({"foo" => "bar"})
break
}
The message is never published. If you remove the break
, then it is. What should I be doing here to ensure that the message is sent, and then leave the EventMachine loop when it is?
Try:
EM.run {
amq = MQ.new
queue = amq.queue("whatev")
amq.callback {
puts "Callback fired!"
break # It'll cause LocalJumpError, but otherwise it does what you want.
}
queue.publish({"foo" => "bar"})
}