Skip to content

Commit e66cf57

Browse files
author
Michael Klishin
committed
Tutorial 1 code ported to Bunny
1 parent b1d09e3 commit e66cf57

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

ruby/receive.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env ruby
2+
# encoding: utf-8
3+
4+
require "bunny"
5+
6+
conn = Bunny.new
7+
conn.start
8+
9+
ch = conn.create_channel
10+
q = ch.queue("hello")
11+
12+
puts "Will wait from messages in #{q.name}"
13+
q.subscribe(:block => true) do |delivery_info, properties, body|
14+
puts " [x] Received #{body}"
15+
16+
# cancel the consumer to exit
17+
delivery_info.consumer.cancel
18+
end
19+
20+
conn.close

ruby/send.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env ruby
2+
# encoding: utf-8
3+
4+
require "bunny"
5+
6+
conn = Bunny.new
7+
conn.start
8+
9+
ch = conn.create_channel
10+
q = ch.queue("hello")
11+
12+
ch.default_exchange.publish("Hello World!", :routing_key => q.name)
13+
puts " [x] Sent 'Hello World!'"
14+
15+
sleep 0.5
16+
conn.close

0 commit comments

Comments
 (0)