Skip to content

Instantly share code, notes, and snippets.

@inokappa
Last active August 29, 2015 14:01
Show Gist options
  • Save inokappa/55616b179e567f19b36f to your computer and use it in GitHub Desktop.
Save inokappa/55616b179e567f19b36f to your computer and use it in GitHub Desktop.
RabbitMQ を Ruby から操作する(receive.rb)
#!/usr/bin/env ruby
# encoding: utf-8
#
require "bunny"
if ARGV[0] == ""
conn = Bunny.new(:hostname => "localhost")
else
conn = Bunny.new(:hostname => "#{ARGV[0]}")
end
conn.start
ch = conn.create_channel
q = ch.queue("hello")
puts " [*] Waiting for messages in #{q.name}. To exit press CTRL+C"
q.subscribe(:block => true) do |delivery_info, properties, body|
puts " [x] Received #{body}"
delivery_info.consumer.cancel
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment