Ruby tutorial 6: avoid using block: true
It makes reasoning about connection recovery pretty difficult. The option only exists to make tutorials shorter but sadly some users go straight into production with copy-pasted code :(
This commit is contained in:
parent
d04af19917
commit
802cf615bf
@ -19,14 +19,18 @@ class FibonacciServer
|
||||
connection.close
|
||||
end
|
||||
|
||||
def loop_forever
|
||||
# This loop only exists to keep the main thread
|
||||
# alive. Many real world apps won't need this.
|
||||
loop { sleep 5 }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :channel, :exchange, :queue, :connection
|
||||
|
||||
def subscribe_to_queue
|
||||
# block: true is only used to keep the main thread
|
||||
# alive. Please avoid using it in real world applications.
|
||||
queue.subscribe(block: true) do |_delivery_info, properties, payload|
|
||||
queue.subscribe do |_delivery_info, properties, payload|
|
||||
result = fibonacci(payload.to_i)
|
||||
|
||||
exchange.publish(
|
||||
@ -49,6 +53,7 @@ begin
|
||||
|
||||
puts ' [x] Awaiting RPC requests'
|
||||
server.start('rpc_queue')
|
||||
server.loop_forever
|
||||
rescue Interrupt => _
|
||||
server.stop
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user