Skip to content

Instantly share code, notes, and snippets.

/ruby consumer
Created Jan 19, 2011

Embed
What would you like to do?
php publisher
<?php
// Create a connection
$cnn = new AMQPConnection();
$cnn->connect();
// Declare a new exchange
$ex = new AMQPExchange($cnn);
$ex->declare('default');//, AMQP_EX_TYPE_DIRECT);
// Create a new queue
$q = new AMQPQueue($cnn);
$q->declare('queue1');
// 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'
EM.run do
# connect to the amqp server
connection = AMQP.connect(:host => 'localhost', :logging => false)
# open a channel on the AMQP connection
channel = MQ.new(connection)
# declare a queue on the channel
queue = MQ::Queue.new(channel, 'queue1')
# create a fanout exchange
exchange = MQ::Exchange.new(channel, :direct, 'direct1')
# bind the queue to the exchange
queue.bind(exchange)
# subscribe to messages in the queue
queue.subscribe do |headers, msg|
pp [:got, headers, msg]
connection.close{ EM.stop_event_loop }
end
end
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.