Created
November 26, 2012 06:37
-
-
Save sonots/4146873 to your computer and use it in GitHub Desktop.
Bunny and AMQP gem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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