Skip to content

Instantly share code, notes, and snippets.

@aceakash
Created October 3, 2015 19:29
Show Gist options
  • Save aceakash/6f556e326eeb6573b535 to your computer and use it in GitHub Desktop.
Save aceakash/6f556e326eeb6573b535 to your computer and use it in GitHub Desktop.
RabbitMQ simple send-receive in Ruby
require 'bunny'
conn = Bunny.new
conn.start
ch = conn.create_channel
q = ch.queue('hello')
begin
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}"
p delivery_info
end
rescue Interrupt => _
conn.close
exit(0)
end
require 'bunny'
conn = Bunny.new
conn.start
ch = conn.create_channel
q = ch.queue('hello')
ch.default_exchange.publish('Hello world', :routing_key => q.name)
puts " [x] Sent 'Hello world'"
@aceakash
Copy link
Author

aceakash commented Oct 3, 2015

Needs a local instance of RabbitMQ server running

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment