Last active
August 29, 2015 14:16
-
-
Save timblair/64d531e3f3b13d29c302 to your computer and use it in GitHub Desktop.
Simple RabbitMQ message listener
This file contains 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
#!/usr/bin/env ruby | |
require "bunny" | |
abort "Usage: #{$0} BINDING_KEY [BINDING_KEY, ...]" if ARGV.empty? | |
conn = Bunny.new("amqp://development.vm:5672") | |
conn.start | |
channel = conn.create_channel | |
exchange = channel.exchange("event", no_declare: true) | |
queue = channel.queue("", exclusive: true, auto_delete: true) | |
ARGV.each { |key| queue.bind(exchange, :routing_key => key) } | |
begin | |
queue.subscribe(:block => true) do |delivery_info, properties, body| | |
puts "#{delivery_info.routing_key} [#{properties}]: #{body}" | |
end | |
rescue Interrupt => _ | |
channel.close | |
conn.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment