Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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