rabbitmq-tutorials/ruby-amqp/new_task.rb
2013-07-17 21:54:17 +04:00

20 lines
475 B
Ruby
Executable File

#!/usr/bin/env ruby
# encoding: utf-8
require "amqp"
AMQP.start(:host => "localhost") do |connection|
channel = AMQP::Channel.new(connection)
queue = channel.queue("task_queue", :durable => true)
message = ARGV.empty? ? "Hello World!" : ARGV.join(" ")
channel.default_exchange.publish(message, :routing_key => queue.name, :persistent => true)
puts " [x] Sent #{message}"
EM.add_timer(0.5) do
connection.close do
EM.stop { exit }
end
end
end