Skip to content

Commit 175d37c

Browse files
author
Caique Hitoshi Mitsuoka
committed
Update ruby tutorial three
1 parent 6c2539d commit 175d37c

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

ruby/emit_log.rb

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
#!/usr/bin/env ruby
2-
# encoding: utf-8
32

4-
require "bunny"
3+
require 'bunny'
54

6-
conn = Bunny.new(:automatically_recover => false)
7-
conn.start
5+
connection = Bunny.new
6+
connection.start
87

9-
ch = conn.create_channel
10-
x = ch.fanout("logs")
8+
channel = connection.create_channel
9+
exchange = channel.fanout('logs')
1110

12-
msg = ARGV.empty? ? "Hello World!" : ARGV.join(" ")
11+
message = ARGV.empty? ? 'Hello World!' : ARGV.join(' ')
1312

14-
x.publish(msg)
15-
puts " [x] Sent #{msg}"
13+
exchange.publish(message)
14+
puts " [x] Sent #{message}"
1615

17-
conn.close
16+
connection.close

ruby/receive_logs.rb

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
#!/usr/bin/env ruby
2-
# encoding: utf-8
32

4-
require "bunny"
3+
require 'bunny'
54

6-
conn = Bunny.new(:automatically_recover => false)
7-
conn.start
5+
connection = Bunny.new
6+
connection.start
87

9-
ch = conn.create_channel
10-
x = ch.fanout("logs")
11-
q = ch.queue("", :exclusive => true)
8+
channel = connection.create_channel
9+
exchange = channel.fanout('logs')
10+
queue = channel.queue('', exclusive: true)
1211

13-
q.bind(x)
12+
queue.bind(exchange)
1413

15-
puts " [*] Waiting for logs. To exit press CTRL+C"
14+
puts ' [*] Waiting for logs. To exit press CTRL+C'
1615

1716
begin
18-
q.subscribe(:block => true) do |delivery_info, properties, body|
17+
queue.subscribe(block: true) do |_delivery_info, _properties, body|
1918
puts " [x] #{body}"
2019
end
2120
rescue Interrupt => _
22-
ch.close
23-
conn.close
24-
25-
exit(0)
21+
channel.close
22+
connection.close
2623
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy