Skip to content

Instantly share code, notes, and snippets.

@reqshark
Created June 10, 2012 17:26
Show Gist options
  • Select an option

  • Save reqshark/2906694 to your computer and use it in GitHub Desktop.

Select an option

Save reqshark/2906694 to your computer and use it in GitHub Desktop.
RabbitMQ-producer
if defined?(Bundler); Bundler.setup; else; require "rubygems"; end
require "amqp"
EventMachine.run do
AMQP.connect(:host => "localhost", :username => "guest", :password => "guest") do |connection|
puts "Connected. Hit Control + C to stop me."
channel = AMQP::Channel.new(connection)
channel.direct("hello-exchange", :durable => true, :auto_delete => false).
publish(ARGV[0], :routing_key => "hola")
# stop on Control + c or after 1 second
stop = Proc.new { connection.close { EventMachine.stop } }
Signal.trap("INT", &stop)
EventMachine.add_timer(1, &stop)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment