1. Go to this page and download the library: Download femike/yii2-amqp-rrobin 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/ */
namespace app\components;
use webtoucher\amqp\components\AmqpInterpreter;
class RabbitInterpreter extends AmqpInterpreter
{
/**
* Interprets AMQP message with routing key 'hello_world'.
*
* @param array $message
*/
public function readHelloWorld($message)
{
// todo: write message handler
$this->log(print_r($message, true));
}
}
namespace console\controllers;
use webtoucher\amqp\components\Amqp;
use Yii;
use yii\console\Controller;
class ExampleController extends Controller
{
public function actionIndex($message = 'Wasap Man')
{
Yii::$app->amqp->send('my-exchange', 'HelloWorld', $message, Amqp::TYPE_DIRECT, true);
}
}
$ php composer.phar
bash
$ php yii rabbit
bash
1st$ php yii rabbit HelloWorld direct true
bash
2nd$ php yii rabbit HelloWorld direct true
bash
$ php yii example
bash
$ php yii example "same text"
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.