Skip to content

Instantly share code, notes, and snippets.

@skrat
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skrat/e5057bd879ac844eb5b1 to your computer and use it in GitHub Desktop.
Save skrat/e5057bd879ac844eb5b1 to your computer and use it in GitHub Desktop.
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