File tree Expand file tree Collapse file tree 2 files changed +22
-28
lines changed Expand file tree Collapse file tree 2 files changed +22
-28
lines changed Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env ruby
2
- # encoding: utf-8
2
+ require 'bunny'
3
3
4
- require "bunny"
4
+ connection = Bunny . new ( automatically_recover : false )
5
+ connection . start
5
6
6
- conn = Bunny . new ( :automatically_recover => false )
7
- conn . start
7
+ channel = connection . create_channel
8
+ exchange = channel . topic ( 'topic_logs' )
9
+ severity = ARGV . shift || 'anonymous.info'
10
+ message = ARGV . empty? ? 'Hello World!' : ARGV . join ( ' ' )
8
11
9
- ch = conn . create_channel
10
- x = ch . topic ( "topic_logs" )
11
- severity = ARGV . shift || "anonymous.info"
12
- msg = ARGV . empty? ? "Hello World!" : ARGV . join ( " " )
12
+ exchange . publish ( message , routing_key : severity )
13
+ puts " [x] Sent #{ severity } :#{ message } "
13
14
14
- x . publish ( msg , :routing_key => severity )
15
- puts " [x] Sent #{ severity } :#{ msg } "
16
-
17
- conn . close
15
+ connection . close
Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env ruby
2
- # encoding: utf-8
2
+ require 'bunny'
3
3
4
- require "bunny"
4
+ abort "Usage: #{ $PROGRAM_NAME } [binding key]" if ARGV . empty?
5
5
6
- if ARGV . empty?
7
- abort "Usage: #{ $0} [binding key]"
8
- end
9
-
10
- conn = Bunny . new ( :automatically_recover => false )
11
- conn . start
6
+ connection = Bunny . new ( automatically_recover : false )
7
+ connection . start
12
8
13
- ch = conn . create_channel
14
- x = ch . topic ( " topic_logs" )
15
- q = ch . queue ( "" , : exclusive => true )
9
+ channel = connection . create_channel
10
+ exchange = channel . topic ( ' topic_logs' )
11
+ queue = channel . queue ( '' , exclusive : true )
16
12
17
13
ARGV . each do |severity |
18
- q . bind ( x , : routing_key => severity )
14
+ queue . bind ( exchange , routing_key : severity )
19
15
end
20
16
21
- puts " [*] Waiting for logs. To exit press CTRL+C"
17
+ puts ' [*] Waiting for logs. To exit press CTRL+C'
22
18
23
19
begin
24
- q . subscribe ( : block => true ) do |delivery_info , properties , body |
20
+ queue . subscribe ( block : true ) do |delivery_info , _properties , body |
25
21
puts " [x] #{ delivery_info . routing_key } :#{ body } "
26
22
end
27
23
rescue Interrupt => _
28
- ch . close
29
- conn . close
24
+ channel . close
25
+ connection . close
30
26
31
27
exit ( 0 )
32
28
end
You can’t perform that action at this time.
0 commit comments