PHP code example of xiaochengfu / yii2-cmq

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

    

xiaochengfu / yii2-cmq example snippets



return [
    'cmq'=>[
       'secretId'=>'您的腾讯id',
       'secretKey'=>'您的key',
       'endpoint'=>'http://cmq-queue-bj.api.qcloud.com',//地区域名
       'queueName'=>'queue-v1',//队列名称
       'processName'=>'cmq-master',//进程名称
       'callback'=>'common\\components\\cmq\\Consumer'//消费业务回调处理名字空间
    ]
];


/**
 * Name: cmq回调处理类
 * Author: hp <[email protected]>
 * Date: 2017-11-22 18:17
 * Description: adf.php.
 */
namespace common\components\cmq;

use yii\base\Exception;

class Consumer
{

    /**
     * Description:  异步回调执行体
     * Author: hp <[email protected]>
     * Updater:
     * @return int
     */
    public function execute($msg)
    {
        try{
              $data = unserialize($msg['msgBody']);
              var_dump($msg);
        }catch (Exception $e){
            var_dump($e->getMessage());
        }

    }
}