Skip to content

Instantly share code, notes, and snippets.

@tmm1
Created July 25, 2008 08:25
Show Gist options
  • Save tmm1/2412 to your computer and use it in GitHub Desktop.
Save tmm1/2412 to your computer and use it in GitHub Desktop.
$:.unshift File.dirname(__FILE__) + '/../lib'
require 'mq'
EM.run do
# open a channel on the AMQP connection
channel = MQ.new
# declare a queue on the channel
queue = MQ::Queue.new(channel, 'queue name')
# use the default fanout exchange
exchange = MQ::Exchange.new(channel, :fanout, 'all queues')
# bind the queue to the exchange
queue.bind(exchange)
# publish a message to the exchange
exchange.publish('hello world')
# subscribe to messages from the queue
queue.subscribe do |headers, msg|
p [:got, headers, msg]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment