Update ruby tutorial one
This commit is contained in:
parent
a2da52fbdb
commit
7a4de0393f
@ -1,21 +1,19 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
# encoding: utf-8
|
require 'bunny'
|
||||||
|
|
||||||
require "bunny"
|
connection = Bunny.new(automatically_recover: false)
|
||||||
|
connection.start
|
||||||
|
|
||||||
conn = Bunny.new(:automatically_recover => false)
|
channel = connection.create_channel
|
||||||
conn.start
|
queue = channel.queue('hello')
|
||||||
|
|
||||||
ch = conn.create_channel
|
|
||||||
q = ch.queue("hello")
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
puts " [*] Waiting for messages. To exit press CTRL+C"
|
puts ' [*] Waiting for messages. To exit press CTRL+C'
|
||||||
q.subscribe(:block => true) do |delivery_info, properties, body|
|
queue.subscribe(block: true) do |_delivery_info, _properties, body|
|
||||||
puts " [x] Received #{body}"
|
puts " [x] Received #{body}"
|
||||||
end
|
end
|
||||||
rescue Interrupt => _
|
rescue Interrupt => _
|
||||||
conn.close
|
connection.close
|
||||||
|
|
||||||
exit(0)
|
exit(0)
|
||||||
end
|
end
|
||||||
|
16
ruby/send.rb
16
ruby/send.rb
@ -1,15 +1,13 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
# encoding: utf-8
|
require 'bunny'
|
||||||
|
|
||||||
require "bunny"
|
connection = Bunny.new(automatically_recover: false)
|
||||||
|
connection.start
|
||||||
|
|
||||||
conn = Bunny.new(:automatically_recover => false)
|
channel = connection.create_channel
|
||||||
conn.start
|
queue = channel.queue('hello')
|
||||||
|
|
||||||
ch = conn.create_channel
|
channel.default_exchange.publish('Hello World!', routing_key: queue.name)
|
||||||
q = ch.queue("hello")
|
|
||||||
|
|
||||||
ch.default_exchange.publish("Hello World!", :routing_key => q.name)
|
|
||||||
puts " [x] Sent 'Hello World!'"
|
puts " [x] Sent 'Hello World!'"
|
||||||
|
|
||||||
conn.close
|
connection.close
|
||||||
|
@ -1,25 +1,23 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
# encoding: utf-8
|
require 'bunny'
|
||||||
|
|
||||||
require "bunny"
|
connection = Bunny.new(automatically_recover: false)
|
||||||
|
connection.start
|
||||||
|
|
||||||
conn = Bunny.new(:automatically_recover => false)
|
channel = connection.create_channel
|
||||||
conn.start
|
queue = channel.queue('task_queue', durable: true)
|
||||||
|
|
||||||
ch = conn.create_channel
|
channel.prefetch(1)
|
||||||
q = ch.queue("task_queue", :durable => true)
|
puts ' [*] Waiting for messages. To exit press CTRL+C'
|
||||||
|
|
||||||
ch.prefetch(1)
|
|
||||||
puts " [*] Waiting for messages. To exit press CTRL+C"
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
q.subscribe(:manual_ack => true, :block => true) do |delivery_info, properties, body|
|
queue.subscribe(manual_ack: true, block: true) do |delivery_info, _properties, body|
|
||||||
puts " [x] Received '#{body}'"
|
puts " [x] Received '#{body}'"
|
||||||
# imitate some work
|
# imitate some work
|
||||||
sleep body.count(".").to_i
|
sleep body.count('.').to_i
|
||||||
puts " [x] Done"
|
puts ' [x] Done'
|
||||||
ch.ack(delivery_info.delivery_tag)
|
channel.ack(delivery_info.delivery_tag)
|
||||||
end
|
end
|
||||||
rescue Interrupt => _
|
rescue Interrupt => _
|
||||||
conn.close
|
connection.close
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user