Yii 1.1: amqp

Wrapper class over AMQP PHP library, gateway pattern implementation
21 followers

CAMQP Extension

DoubleGIS company presents Yii extensions for MQ-Servers like RabbitMQ, ApacheMQ or other servers which support AMQP protocol.

The 'CAMQP' is a Yii Framework Plugin that provides a Gateway for MQ-Server interface. Contains all methods to add/edit/delete/read messages/queues/exchanges on the broker.

Allow to work in 'Fake' mode to avoid direct connection to the broker.

Changelog:

  • 1.1 Flags bitmask added, some bugs fixed
  • 1.0 Initial release

Requirements

  • Yii 1.1.*
  • AMQP PECL extension (http://pecl.php.net/package/amqp)

Installation

  • Unpack all files under your project 'component' folder
  • Include your new extenion into your project main.php configuration file:
'components' => array(
                'amqp' => array(
                    'class' => 'application.components.AMQP.CAMQP',
                    'host'  => '127.0.0.1'
                )
            )
  • Enjoy!

Usage

To write a message into the MQ-Exchange:

Yii::app()->amqp->exchange('topic')->publish('some message','some.route');

To read a message from MQ-Queue:

Yii::app()->amqp->queue('some_listener')->get();

To Create an Exchange from the Script:

$ex = Yii::app()->amqp->declareExchange('my_new_exchange');
...
// now we can use created exchange
$ex->publish('message1', 'some.route');
$ex->publish('message2', 'some.route');
$ex->publish('message3', 'some.route');
...
$ex->publish('messageN', 'some.route');

To Create a Queue from the Script:

$queue = Yii::app()->amqp->declareQueue('my_new_queue');
...
// now we can use created queue
while ($message = $queue->get()) {
    // reading all messages
    ...
}

Bind a Queue to an Exchange:

$queue = Yii::app()->amqp->queue('my_new_queue');
$queue->bind('my_new_exchange');
...
$ex = Yii::app()->amqp->queue('my_new_exchange');
$ex->publish('Hello World!', 'routie');
...
echo $queue->get(); // Hello World!
/* OR */
$queue = Yii::app()->amqp->bindQueueToExchange('my_new_queue', 'my_new_exchange');
...
echo $queue->get(); // Hello World!

Total 4 comments

#15677 report it
saurabh_patil at 2013/12/06 02:47am
AMQPQueue.php class not found error.

I am getting above error about class not found or fail to open AMQPQueue.php file Please suggest where do i need to include AMQPQueue.php file

#15508 report it
sikoshi at 2013/11/16 12:26pm
Support

Declaration Of Camqpqueue: :consume() should be compatible with AMQPQueue::consume($callback, $flags = NULL, $consumer_tag = NULL)

how can i fix this issue?

#11036 report it
Kavi at 2012/12/11 08:04am
The extension is not working

I've tried to use it my project, however it does not working properly:

AMQPQueue::declare() expects exactly 0 parameters, 2 given

/var/www/t.depo.fm/protected/components/AMQP/CAMQP.php(129)

117 $ex = new CAMQPExchange($this->getChannel()); 118 return $ex->declare($name, $type, $flags); 119 } 120 121 /** 122 * @brief Declares a new Queue on the broker 123 * @param $name 124 * @param $flags 125 */ 126 public function declareQueue($name, $flags = NULL) 127 { 128 $queue = new CAMQPQueue($this->getChannel()); 129 return $queue->declare($name, $flags); 130 }

#2951 report it
Leric at 2011/03/01 05:06am
It depends on the amqp pecl extension

It seems to depend on the amqp pecl extension , try this: pecl install amqp It's not available under windows yet

Leave a comment

Please to leave your comment.

Create extension
Downloads