Skip to content

Instantly share code, notes, and snippets.

@wilken
Created June 21, 2011 12:12
Show Gist options
  • Save wilken/1037726 to your computer and use it in GitHub Desktop.
Save wilken/1037726 to your computer and use it in GitHub Desktop.
Rabbitmq
#!/usr/bin/env ruby
# encoding: utf-8
require "bundler"
Bundler.setup
require "amqp"
EventMachine.run do
connection1 = AMQP.connect(:host => '127.0.0.1')
puts "Connected to AMQP broker. Running #{AMQP::VERSION} version of the gem..."
channel1 = AMQP::Channel.new(connection1)
channel2 = AMQP::Channel.new(connection1)
channel3 = AMQP::Channel.new(connection1)
exchange = channel3.fanout('fanout')
queue1 = channel1.queue("n")
queue1.bind(exchange)
queue1.subscribe do |payload|
puts "#{payload} 1"
end
queue2 = channel2.queue("n")
queue2.bind(exchange)
queue2.subscribe do |payload|
puts "#{payload} 2"
end
20.times do |i|
exchange.publish "#{i}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment