Last active
August 29, 2015 14:01
-
-
Save skrat/e5057bd879ac844eb5b1 to your computer and use it in GitHub Desktop.
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 'eventmachine' | |
require 'amqp' | |
EventMachine.run { | |
conn = AMQP.connect(:host => '127.0.0.1') | |
puts "Connecting to RabbitMQ. Running #{AMQP::VERSION} version of the gem..." | |
ch = AMQP::Channel.new(conn) | |
q = ch.queue("amqpgem.examples.hello_world", :auto_delete => true) | |
x = ch.default_exchange | |
q.subscribe do |metadata, payload| | |
puts "Received a message: #{payload}. Disconnecting..." | |
conn.close { | |
EventMachine.stop { exit } | |
} | |
end | |
conn.on_error do |conn, connection_close| | |
puts "Handling a connection-level exception." | |
puts | |
puts "AMQP class id : #{connection_close.class_id}" | |
puts "AMQP method id: #{connection_close.method_id}" | |
puts "Status code : #{connection_close.reply_code}" | |
puts "Error message : #{connection_close.reply_text}" | |
EventMachine.stop { exit } | |
end | |
payload = "Dusan is a handwaving troll!" * 1e5 | |
puts "Publishing message with payload #{payload.bytesize} bytes" | |
x.publish payload, :routing_key => q.name | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment