Skip to content

Instantly share code, notes, and snippets.

@dagda1
Created November 22, 2011 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dagda1/1387178 to your computer and use it in GitHub Desktop.
Save dagda1/1387178 to your computer and use it in GitHub Desktop.
publisher.rb
def publish(urlSearch, routing_key)
EM.run do
corr_id = rand(10_000_000).to_s
requests ||= Hash.new
connection = AMQP.connect(:host => "localhost")
callback_queue = AMQP::Channel.new(connection).queue("", :exclusive => true)
callback_queue.subscribe do |header, body|
reply = MultiJson.decode(body)
if reply[:is_last.to_s]
connection.close do
EM.stop{exit}
end
end
end
callback_queue.append_callback(:declare) do
AMQP::Exchange.default.publish(MultiJson.encode(urlSearch), :routing_key => routing_key, :reply_to => callback_queue.name, :correlation_id => corr_id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment