Tutorial 1 code ported to Bunny
This commit is contained in:
parent
b1d09e3def
commit
e66cf5775e
20
ruby/receive.rb
Normal file
20
ruby/receive.rb
Normal 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
16
ruby/send.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user