PHP code example of xutl / yii2-mq

1. Go to this page and download the library: Download xutl/yii2-mq 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/ */

    

xutl / yii2-mq example snippets


//使用Redis
'queue' => [
    'class' => 'xutl\mq\redis\Client',
                'redis' => [
                    'scheme' => 'tcp',
                    'host' => '127.0.0.1',
                    'port' => 6379,
                    //'password' => '1984111a',
                    'db' => 0
                ],
],

//使用AWS SQS
'queue' => [
    'class' => 'xutl\mq\awsqs\Client',
                'sqs' => [
                    //etc
                ],
],
//使用阿里MNS
'queue' => [
   'class' => 'xutl\mq\alimns\Client',
               'endPoint' => '',
               'accessId'=>'',
               'accessKey'=>'',
],        


//入队
/** @var \xutl\mq\Queue $queue */
$queue = Yii::$app->queue->getQueueRef('mailer');
for ($i = 0; $i < 500; $i++) {
    $queue->sendMessage([
        'aaa'=>'bbb',
    ]);
}

//出队
/** @var \xutl\mq\Queue $queue */
$queue = Yii::$app->queue->getQueueRef('mailer');
/** @var \xutl\mq\Message $message */
while (($message = $queue->receiveMessage()) !== false) {
    $body = $message->getBody();
    var_dump($body);
    $message->delete();
}