Skip to content

Instantly share code, notes, and snippets.

@slemiere
Forked from pradeepgatram/amqp_replicator
Created January 18, 2010 14:53
Show Gist options
  • Save slemiere/280065 to your computer and use it in GitHub Desktop.
Save slemiere/280065 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