|
|
|
@ -8,21 +8,34 @@ class Sylvilagus::Ch02::HelloWorldConsumer < DefaultConsumer
|
|
|
|
|
include Sylvilagus::Ch02::HelloWorld::ClassMethods
|
|
|
|
|
|
|
|
|
|
def main
|
|
|
|
|
with_hello_world_conn do |conn,channel|
|
|
|
|
|
channel.basic_consume('hello-queue', false, new(channel))
|
|
|
|
|
with_hello_world_channel do |channel|
|
|
|
|
|
consumer = new(channel)
|
|
|
|
|
|
|
|
|
|
STDERR.puts 'Starting consume loop...'
|
|
|
|
|
channel.basic_consume('hello-queue', false, consumer)
|
|
|
|
|
|
|
|
|
|
loop do
|
|
|
|
|
sleep 3
|
|
|
|
|
puts "Still waiting..."
|
|
|
|
|
sleep 1
|
|
|
|
|
break if consumer.done?
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def done?
|
|
|
|
|
@done ||= false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def handleDelivery(consumer_tag, envelope, properties, body)
|
|
|
|
|
delivery_tag = envelope.get_delivery_tag
|
|
|
|
|
body_string = RubyString.bytes_to_string(body)
|
|
|
|
|
|
|
|
|
|
puts "Consumed #{body_string.inspect}"
|
|
|
|
|
get_channel.basic_ack(delivery_tag, false)
|
|
|
|
|
channel.basic_ack(envelope.delivery_tag, false)
|
|
|
|
|
|
|
|
|
|
if body_string == 'quit'
|
|
|
|
|
STDERR.puts 'Quitting...'
|
|
|
|
|
@done = true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|