AMQPExchange constructor need a Channel not a Connection object.
La clase AMQPQueue
(No hay información de versión disponible, podría estar únicamente en SVN)
Introducción
Representa una cola AMQP.
Sinopsis de la Clase
AMQPQueue
{
/* Métodos */
}Tabla de contenidos
- AMQPQueue::ack — Reconoce la recepción de un mensaje
- AMQPQueue::bind — Enlaza la cola dada a un enrutamiento clave en un intercambio
- AMQPQueue::cancel — Cancela una cola enlaza
- AMQPQueue::__construct — Crea una instancia de un objeto AMQPQueue
- AMQPQueue::consume — Consume mensajes de una cola
- AMQPQueue::declare — Declarar una nueva cola
- AMQPQueue::delete — Borra una cola y su contenido
- AMQPQueue::get — Recupera el mensaje siguiente de la cola
- AMQPQueue::getArgument — Obtiene el argumento asociado con la clave proporcionada
- AMQPQueue::getArguments — Get all arguments set on the given queue
- AMQPQueue::getFlags — Get the flag bitmask
- AMQPQueue::getName — Obtener el nombre configurado
- AMQPQueue::nack — Mark a message as explicitly not acknowledged.
- AMQPQueue::purge — Purga los contenidos de una cola
- AMQPQueue::setArgument — Establecer el valor de la clave dada
- AMQPQueue::setArguments — Establecer todos los argumentos en la cola
- AMQPQueue::setFlags — Set the queue flags
- AMQPQueue::setName — Establecer el nombre de cola
- AMQPQueue::unbind — Desata la cola de una clave de enrutamiento
ebuildy at gmail dot com ¶
10 months ago
bolo at nospam dot autistici dot org ¶
1 year ago
Function that perform a php publisher daemon. [And function to interface with Rabbit server.]
<?php
//First initialise the connection to 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;
}
//This is the daemon, it should be more performant because the sleep(1) run the publisher every 1 second. Rabbit is more faster.
function receiver($exchange, $rk, $queuename) {
$connection=amqp_connection();
$queue = new AMQPQueue($connection);
$queue->declare($queuename);
$queue->bind($exchange, $rk);
while(true){
$msg=$queue->get();
if ($msg['count']>-1){
echo "\n--------\n";
print_r($msg['msg']);
echo "\n--------\n";
}
sleep(1);
}
if (!$connection->disconnect()) {
throw new Exception('Could not disconnect');
}
}
//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";
}
}
?>
P.S. run the daemon with ~$ php /pathto/php.ini functioncaller.php
