Switching to Ruby-style methods and setters

cat-town
Dan Buch 12 years ago
parent ef2c0337c6
commit 2e7de65c2d

@ -8,11 +8,11 @@ module Sylvilagus::Ch02::HelloWorld
module ClassMethods
def with_hello_world_conn(&block)
factory = ConnectionFactory.new
factory.setUri('amqp://guest:guest@localhost:5672')
conn = factory.newConnection
channel = conn.createChannel
channel.exchangeDeclare('hello-exchange', 'direct', true)
channel.queueDeclare('hello-queue', false, false, false, nil)
factory.uri = 'amqp://guest:guest@localhost:5672'
conn = factory.new_connection
channel = conn.create_channel
channel.exchange_declare('hello-exchange', 'direct', true)
channel.queue_declare('hello-queue', false, false, false, nil)
block.call(conn, channel)
ensure

@ -9,7 +9,7 @@ class Sylvilagus::Ch02::HelloWorldConsumer < DefaultConsumer
def main
with_hello_world_conn do |conn,channel|
channel.basicConsume('hello-queue', false, new(channel))
channel.basic_consume('hello-queue', false, new(channel))
loop do
sleep 3
puts "Still waiting..."
@ -19,10 +19,10 @@ class Sylvilagus::Ch02::HelloWorldConsumer < DefaultConsumer
end
def handleDelivery(consumer_tag, envelope, properties, body)
delivery_tag = envelope.getDeliveryTag
delivery_tag = envelope.get_delivery_tag
body_string = RubyString.bytes_to_string(body)
puts "Consumed #{body_string.inspect}"
getChannel.basicAck(delivery_tag, false)
get_channel.basic_ack(delivery_tag, false)
end
end

@ -7,7 +7,7 @@ class Sylvilagus::Ch02::HelloWorldProducer
def main
message = ARGV.first || 'snorg'
with_hello_world_conn do |conn,channel|
channel.basicPublish('hello-exchange', 'hola', nil, message.to_java_bytes)
channel.basic_publish('hello-exchange', 'hola', nil, message.to_java_bytes)
puts "Published #{message.inspect}"
end
end

Loading…
Cancel
Save