Skip to content

Instantly share code, notes, and snippets.

@carllerche
Created April 30, 2009 03:01
Show Gist options
  • Select an option

  • Save carllerche/104226 to your computer and use it in GitHub Desktop.

Select an option

Save carllerche/104226 to your computer and use it in GitHub Desktop.
require "rubygems"
require "mq"
require "shared"
EM.run do
@connection = AMQP.connect(:host => "localhost", :user => "carllerche", :pass => "enter", :vhost => "/testing")
@channel = MQ.new(@connection)
@xchange = @channel.fanout('my_exchange', :durable => true)
EM.add_timer(1) do
@xchange.publish(Marshal.dump(Awesome.new("Hello")))
EM.add_timer(1) { EM.stop_event_loop }
end
end
class Awesome
def initialize(message)
@message = message
end
attr_accessor :message
end
require "rubygems"
require "mq"
require "shared"
EM.run do
trap("INT") { EM.stop }
trap("TERM") { EM.stop }
@connection = AMQP.connect(:host => "localhost", :user => "carllerche", :pass => "enter", :vhost => "/testing")
@channel = MQ.new(@connection)
@xchange = @channel.fanout('my_exchange', :durable => false)
queue = MQ::Queue.new(@channel, 'my_queue', :durable => false)
queue.bind(@xchange)
queue.subscribe do |header, msg|
puts "GOT: #{Marshal.load(msg).message}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment