Created
October 3, 2015 19:29
-
-
Save aceakash/6f556e326eeb6573b535 to your computer and use it in GitHub Desktop.
RabbitMQ simple send-receive in Ruby
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 '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 | |
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 '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'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Needs a local instance of RabbitMQ server running