PHP code example of cperdana / yii2-rabbitmq
1. Go to this page and download the library: Download cperdana/yii2-rabbitmq library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cperdana / yii2-rabbitmq example snippets
use PhpAmqpLib\Message\AMQPMessage;
use cperdana\rabbitmq\RabbitPhpAmqpLib;
class MsgqueController extends \yii\console\Controller
{
private function execute($message){
echo $message->body;
$rabbit = \Yii::$app->rabbit;
$rabbit->sendAck($message);
}
public function actionSend($themsg){
$rabbit = \Yii::$app->rabbit;
$rabbit->send($themsg);
}
public function actionRead(){
$callback = function($message){
$this->execute($message);
};
$rabbit = \Yii::$app->rabbit;
$rabbit->read($callback);
}
}
php yii msgque/read