AMQPExchange constructor need a Channel not a Connection object.
The AMQPQueue class
(No version information available, might only be in SVN)
Introduction
Represents an AMQP queue.
Class synopsis
AMQPQueue
{
/* Methods */
}Table of Contents
- AMQPQueue::ack — Acknowledge the receipt of a message
- AMQPQueue::bind — Bind the given queue to a routing key on an exchange.
- AMQPQueue::cancel — Cancel a queue binding.
- AMQPQueue::__construct — Create an instance of an AMQPQueue object
- AMQPQueue::consume — Consume messages from a queue
- AMQPQueue::declare — Declare a new queue
- AMQPQueue::delete — Delete a queue and its contents.
- AMQPQueue::get — Retrieve the next message from the queue.
- AMQPQueue::getArgument — Get the argument associated with the given key
- AMQPQueue::getArguments — Get all arguments set on the given queue
- AMQPQueue::getFlags — Get the flag bitmask
- AMQPQueue::getName — Get the configured name
- AMQPQueue::nack — Mark a message as explicitly not acknowledged.
- AMQPQueue::purge — Purge the contents of a queue
- AMQPQueue::setArgument — Set the value for the given key
- AMQPQueue::setArguments — Set all arguments on the queue
- AMQPQueue::setFlags — Set the queue flags
- AMQPQueue::setName — Set the queue name
- AMQPQueue::unbind — Unbind the queue from a routing key.
ebuildy at gmail dot com ¶
9 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
