Created
January 19, 2011 17:32
-
-
Save anonymous/786508 to your computer and use it in GitHub Desktop.
php publisher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$:.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