Skip to content

Instantly share code, notes, and snippets.

@sonots
Created November 26, 2012 06:37
Show Gist options
  • Save sonots/4146873 to your computer and use it in GitHub Desktop.
Save sonots/4146873 to your computer and use it in GitHub Desktop.
Bunny and AMQP gem
require "rubygems"
require "amqp"
EventMachine.run do
AMQP.connect(host: 'localhost', user: 'guest') do |connection|
puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
channel = AMQP::Channel.new(connection)
channel.queue("test1", :auto_delete => true).subscribe do |payload|
puts "Received a message: #{payload}. Disconnecting..."
connection.close { EventMachine.stop }
end
channel.direct("").publish "Hello, world!", :routing_key => "test1"
end
end
require 'rubygems'
require 'bunny'
b = Bunny.new(host: 'localhost', user: 'guest')
b.start
e = b.exchange("", :auto_delete => true)
e.publish("hello, everybody!", :key => 'test1')
require 'rubygems'
require 'bunny'
b = Bunny.new(host: 'localhost', user: 'guest')
b.start
q = b.queue("test1")
print "Message count: #{q.message_count}\n"
msg = q.pop[:payload]
puts "This is the message: #{msg}\n\n"
b.stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment