Skip to content

Instantly share code, notes, and snippets.

/ruby consumer
Created Jan 19, 2011

What would you like to do?
php publisher
// Create a connection
$cnn = new AMQPConnection();
// Declare a new exchange
$ex = new AMQPExchange($cnn);
$ex->declare('default');//, AMQP_EX_TYPE_DIRECT);
// Create a new queue
$q = new AMQPQueue($cnn);
// Bind it on the exchange to routing.key
$ex->bind('queue1', 'routing.key');
// Publish a message to the exchange with a routing key
$ex->publish('message', 'routing.key');
// Read from the queue
$msg = $q->consume();
$:.unshift File.dirname(__FILE__) + '/../../lib'
require 'mq'
require 'pp' do
# connect to the amqp server
connection = AMQP.connect(:host => 'localhost', :logging => false)
# open a channel on the AMQP connection
channel =
# declare a queue on the channel
queue =, 'queue1')
# create a fanout exchange
exchange =, :direct, 'direct1')
# bind the queue to the exchange
# subscribe to messages in the queue
queue.subscribe do |headers, msg|
pp [:got, headers, msg]
connection.close{ EM.stop_event_loop }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.