Starting implementation of RabbitMQ in Action Ch. 02 exercises in JRuby
This commit is contained in:
parent
4b81b14358
commit
43be53a224
@ -1,24 +1,34 @@
|
||||
require 'open-uri'
|
||||
|
||||
RMQ_URI_BASE = 'http://www.rabbitmq.com/releases/rabbitmq-java-client'
|
||||
RMQV = '2.8.7'
|
||||
|
||||
directory './tmp'
|
||||
|
||||
file './tmp/rabbitmq-java-client-bin-2.8.7.tar.gz' => ['./tmp'] do |f|
|
||||
open('http://www.rabbitmq.com/releases/rabbitmq-java-client/v2.8.7/rabbitmq-java-client-bin-2.8.7.tar.gz') do |f|
|
||||
file "./tmp/rabbitmq-java-client-bin-#{RMQV}.tar.gz" => ['./tmp'] do |f|
|
||||
puts "*** Downloading tarball"
|
||||
open("#{RMQ_URI_BASE}/v#{RMQV}/rabbitmq-java-client-bin-#{RMQV}.tar.gz") do |f|
|
||||
open('./tmp/rabbitmq-java-client-bin.tar.gz', 'w') do |out|
|
||||
out.write(f.read)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
file './tmp/rabbitmq-java-client-bin-2.8.7' => ['./tmp/rabbitmq-java-client-bin-2.8.7.tar.gz'] do
|
||||
file "./tmp/rabbitmq-java-client-bin-#{RMQV}/rabbitmq-client.jar" =>
|
||||
["./tmp/rabbitmq-java-client-bin-#{RMQV}.tar.gz"] do
|
||||
puts "*** Extracting tarball"
|
||||
Dir.chdir('./tmp') do
|
||||
`tar xzvf rabbitmq-java-client-bin.tar.gz`
|
||||
puts "*** Extracted, exit code = #{$?}"
|
||||
end
|
||||
end
|
||||
|
||||
file './lib/java/rabbitmq-client.jar' => ['./tmp/rabbitmq-java-client-bin-2.8.7'] do
|
||||
Dir['./tmp/rabbitmq-java-client-bin-2.8.7/*.jar'].each do |jar|
|
||||
FileUtils.mv(jar, './lib/java', :verbose => true)
|
||||
file './lib/java/rabbitmq-client.jar' =>
|
||||
["./tmp/rabbitmq-java-client-bin-#{RMQV}/rabbitmq-client.jar"] do
|
||||
puts "*** Copying jars"
|
||||
Dir["./tmp/rabbitmq-java-client-bin-#{RMQV}/*.jar"].each do |jar|
|
||||
puts "*** Copying #{jar} to ./lib/java"
|
||||
FileUtils.cp(jar, './lib/java', :verbose => true)
|
||||
end
|
||||
end
|
||||
|
||||
|
32
sylvilagus/jruby/lib/sylvilagus/ch02/hello_world_producer.rb
Normal file
32
sylvilagus/jruby/lib/sylvilagus/ch02/hello_world_producer.rb
Normal 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
|
9
sylvilagus/jruby/lib/sylvilagus/init.rb
Normal file
9
sylvilagus/jruby/lib/sylvilagus/init.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user