Tutorial 1 code ported to Bunny

This commit is contained in:
Michael Klishin 2013-07-17 18:21:48 +04:00
parent b1d09e3def
commit e66cf5775e
2 changed files with 36 additions and 0 deletions

20
ruby/receive.rb Normal file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env ruby
# encoding: utf-8
require "bunny"
conn = Bunny.new
conn.start
ch = conn.create_channel
q = ch.queue("hello")
puts "Will wait from messages in #{q.name}"
q.subscribe(:block => true) do |delivery_info, properties, body|
puts " [x] Received #{body}"
# cancel the consumer to exit
delivery_info.consumer.cancel
end
conn.close

16
ruby/send.rb Normal file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env ruby
# encoding: utf-8
require "bunny"
conn = Bunny.new
conn.start
ch = conn.create_channel
q = ch.queue("hello")
ch.default_exchange.publish("Hello World!", :routing_key => q.name)
puts " [x] Sent 'Hello World!'"
sleep 0.5
conn.close