amqp icon indicating copy to clipboard operation
amqp copied to clipboard

How to ensure that a single message is published?

Open TrevorBurnham opened this issue 13 years ago • 1 comments

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?

TrevorBurnham avatar Jul 28 '10 20:07 TrevorBurnham

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"})
}

botanicus avatar Jan 05 '11 17:01 botanicus