Created
February 9, 2012 20:04
-
-
Save thom-nic/1782569 to your computer and use it in GitHub Desktop.
AMQP Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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