AMQP
在线手册:中文  英文

The AMQPQueue class

(PECL amqp >= Unknown)

简介

Represents an AMQP queue.

类摘要

AMQPQueue {
/* 方法 */
public bool ack ( int $delivery_tag [, int $flags = AMQP_NOPARAM ] )
public bool bind ( string $exchange_name , string $routing_key )
public bool cancel ([ string $consumer_tag = "" ] )
public __construct ( AMQPChannel $amqp_channel )
public void consume ( callable $callback [, int $flags = AMQP_NOPARAM ] )
public int declare ( void )
publicbool delete ( void )
public mixed get ([ int $flags ] )
public mixed getArgument ( string $key )
public array getArguments ( void )
public int getFlags ( void )
public string getName ( void )
public void nack ( string $delivery_tag [, string $flags = AMQP_NOPARAM ] )
public bool purge ( void )
public void setArgument ( string $key , mixed $value )
public void setArguments ( array $arguments )
public void setFlags ( int $flags )
public void setName ( string $queue_name )
public bool unbind ( string $exchange_name , string $routing_key )
}

Table of Contents


AMQP
在线手册:中文  英文

用户评论:

ebuildy at gmail dot com (2012-07-14 11:24:28)

AMQPExchange constructor need a Channel not a Connection object.

bolo at nospam dot autistici dot org (2011-09-27 04:03:03)

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($exchangeAMQP_EX_TYPE_FANOUTAMQP_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

易百教程