Starting implementation of RabbitMQ in Action Ch. 02 exercises in JRuby

This commit is contained in:
Dan Buch
2012-11-16 20:25:44 -05:00
parent 4b81b14358
commit 43be53a224
3 changed files with 57 additions and 6 deletions

View File

@@ -0,0 +1,32 @@
require 'sylvilagus/init'
require 'rabbitmq-client.jar'
import com.rabbitmq.client.ConnectionFactory
module Sylvilagus
module Ch02
class HelloWorldProducer
class << self
def main
message = ARGV.first || 'snorg'
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)
channel.basicPublish('hello-exchange', 'hola', nil, message.to_java_bytes)
puts "Published #{message.inspect}"
ensure
conn.close
end
end
end
end
end
if $0 == __FILE__
Sylvilagus::Ch02::HelloWorldProducer.main
end

View File

@@ -0,0 +1,9 @@
require 'java'
SYLVILAGUS_JAVA_LIBS = File.expand_path('../../java/', __FILE__)
$CLASSPATH << SYLVILAGUS_JAVA_LIBS
Dir["#{SYLVILAGUS_JAVA_LIBS}/*.jar"].each do |jar|
$CLASSPATH << jar
end