Skip to content

Instantly share code, notes, and snippets.

@arunthampi
Created November 21, 2008 06:51
Show Gist options
  • Save arunthampi/27376 to your computer and use it in GitHub Desktop.
Save arunthampi/27376 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'amqp'
require 'mq'
require 'evented_net'
def log *args
p args
end
# If running on Linux, use EventMachine.epoll, on Mac OS X, use EventMachine.kqueue
# Most of the code stolen from the example in http://www.github.com/tmm1/amqp
EM.run {
EventMachine.kqueue
def process_http_req(code, body)
log 'Fetched page', code
end
all_partners = MQ.new.fanout('hotel-partners')
# Periodically send the time to the fanout queue 'hotel-partners'
EM.add_periodic_timer(1) {
puts
log :publishing, time = Time.now
all_partners.publish(Marshal.dump(time))
}
amq = MQ.new
amq1 = MQ.new
amq.queue('hotel-partners-xyz.com').bind(amq.fanout('hotel-partners')).subscribe { |time|
log 'going to fetch web page 1', Marshal.load(time)
EventedNet::HTTP.get(URI.parse('http://www.bbc.co.uk'), :callback => method(:process_http_req))
}
amq1.queue('hotel-partners-xyz.com').bind(amq.fanout('hotel-partners')).subscribe { |time|
log 'going to fetch web page 2', Marshal.load(time)
EventedNet::HTTP.get(URI.parse('http://www.bbc.co.uk'), :callback => method(:process_http_req))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment