Skip to content

Instantly share code, notes, and snippets.

@mattdenner
Created March 27, 2010 10:53
Show Gist options
  • Save mattdenner/345930 to your computer and use it in GitHub Desktop.
Save mattdenner/345930 to your computer and use it in GitHub Desktop.
#!/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