note 105946 deleted from class.amqpqueue by danbrown
| From: | danbrown@php.net | Date: | Tue, 27 Sep 2011 14:22:11 +0000 |
| Subject: | note 105946 deleted from class.amqpqueue by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-183485@lists.php.net to get a copy of this message | ||
Note Submitter: bolo at nospam dot autistici dot org
----
Functions to send message to Rabbit server.
<?php
//First initialize the connection to the Rabbit server
function amqp_connection() {
$connection = new AMQPConnection();
$connection->setLogin('guest');
$connection->setPassword('guest');
$connection->connect();
if (!$connection->isConnected()) {
echo "Cannot connect to the broker";
}
return $connection;
}
//Next perform message delivery, the FANOUT type is for loadbalacing mode
//It perform the delivery of $text message to every Rabbit servers running in your system.
//Refer to the php manual (http://www.php.net/manual/en/amqp.constants.php) for others type.
function sender($text, $rk, $exchange){
$connection=amqp_connection();
$ex = new AMQPExchange($connection);
$ex->declare($exchange, AMQP_EX_TYPE_FANOUT, AMQP_DURABLE);
$msg=$ex->publish($text, $rk);
if (!$msg){echo "error";}echo 'Sended '.$msg.'<br>';
if (!$connection->disconnect()) {
throw new Exception('Could not disconnect');
} else {
echo "disconnected";
}
}
?>