Created
March 27, 2010 10:53
-
-
Save mattdenner/345930 to your computer and use it in GitHub Desktop.
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 'rubygems' | |
require 'amqp' | |
require 'mq' | |
require 'uuid' | |
exchange_type = ARGV.first or raise "Usage: publisher <exchange type>" | |
[ :direct, :fanout, :topic ].include?(exchange_type.to_sym) or raise "You can only use direct, fanout or topic" | |
KEYS = [ 'even', 'odd' ] | |
puts "Starting the #{ exchange_type } publisher ..." | |
AMQP.start(:host => 'localhost') do | |
amq = MQ.new | |
puts "Connecting ..." | |
exchange = amq.method(exchange_type.to_sym).call('exchange') # Can't use send() here! | |
marker = UUID.new.generate | |
puts "Sending marker #{ marker } ..." | |
exchange.publish(marker) | |
puts "Sending messages to #{ exchange.name } ..." | |
(1..100).each { |i| exchange.publish(i, :routing_key => KEYS[ i % 2 ]) } | |
puts "Shutting down ..." | |
AMQP.stop { EM.stop } | |
puts "Done" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment