Skip to content

Instantly share code, notes, and snippets.

@thom-nic
Created February 9, 2012 20:04
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 thom-nic/1782569 to your computer and use it in GitHub Desktop.
Save thom-nic/1782569 to your computer and use it in GitHub Desktop.
AMQP Example
require 'amqp'
AMQP.start 'amqp://localhost' do
puts 'Connected.'
AMQP::Channel.new do |channel, open_ok|
channel.queue "schwartz.test2", :durable => false do |queue, ok|
queue.subscribe do |headers, msg|
puts "Got message: #{msg}"
end
EM.add_periodic_timer 5 do
3.times do |i|
AMQP.channel.default_exchange.publish(
"A new message #{i} from #{Time.now.strftime('%H:%M:%S %m/%b/%Y')}",
:routing_key => queue.name )
end
puts "Sent messages..."
end
puts 'plz wait...'
end
end
puts "running..."
['HUP','INT','TERM'].each do |sig|
Signal.trap sig do
puts "Terminating..."
AMQP.connection.close { EM.stop { exit } }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment