Skip to content

Instantly share code, notes, and snippets.

@tily
Created April 14, 2013 02:26
Show Gist options
  • Save tily/5381114 to your computer and use it in GitHub Desktop.
Save tily/5381114 to your computer and use it in GitHub Desktop.
AMQP Ruby サンプル
require 'rubygems'
require 'amqp'
BANNER = 'ruby amqp-test.rb [hostname]'
def main(args)
host = args.first
abort BANNER if host.nil?
EventMachine.run do
connection = AMQP.connect(:host => args.first)
puts "Connecting to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
channel = AMQP::Channel.new(connection)
queue = channel.queue("amqpgem.examples.hello_world", :auto_delete => true)
exchange = channel.default_exchange
queue.subscribe do |payload|
puts "Received a message: #{payload}. Disconnecting..."
connection.close {
EventMachine.stop { exit }
}
end
exchange.publish "Hello, world!", :routing_key => queue.name
end
end
main(ARGV.dup)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment