Created
January 13, 2010 13:50
-
-
Save pradeepgatram/276195 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
# 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