Skip to content

Instantly share code, notes, and snippets.

@pradeepgatram
Created January 13, 2010 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pradeepgatram/276195 to your computer and use it in GitHub Desktop.
Save pradeepgatram/276195 to your computer and use it in GitHub Desktop.
# written by Pradeep Gatram, www.masplantiz.com
# no restrictions whatsoever on usage.
require 'rubygems'
require 'mq'
EM.run do
def replicate source, destination, topic
source_q = MQ::Queue.new(source, "replicator for #{topic}")
source_q.bind(MQ::Exchange.new(source, :topic, topic))
destination_ex = MQ::Exchange.new(destination, :topic, topic)
source_q.subscribe do |headers, msg|
destination_ex.publish(msg)
end
end
local, remote = %w{one two}, %w{three}
localhost, remotehost = 'localhost', '192.168.0.26'
local_channel = MQ.new(AMQP.connect(:host => localhost, :logging => false))
remote_channel = MQ.new(AMQP.connect(:host => remotehost, :logging => false))
local.each { |topic| replicate local_channel, remote_channel, topic }
remote.each { |topic| replicate remote_channel, local_channel, topic }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment