Skip to content

Instantly share code, notes, and snippets.

@johndemic
Created March 7, 2012 22:49
Show Gist options
  • Save johndemic/1996848 to your computer and use it in GitHub Desktop.
Save johndemic/1996848 to your computer and use it in GitHub Desktop.
A script to publish messages to an AMQP exchange
<?php
// Establish a connection to the locally running RabbitMQ instance
$cnn = new AMQPConnection();
$cnn->connect();
// Create a channel
$ch = new AMQPChannel($cnn);
// Declare the exchange specified by the first argument to the script
$ex = new AMQPExchange($ch);
$ex->setName($argv[1]);
$ex->setType(AMQP_EX_TYPE_TOPIC);
$ex->setFlags(AMQP_DURABLE);
$ex->declare();
// Publish a message to the exchange with the given routing key
$msg = $ex->publish($argv[3], $argv[2], AMQP_NOPARAM,
array("Content-type" => "text/plain"));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment