1. Go to this page and download the library: Download alan/yii2-mq-task 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 console\controllers;
use Yii;
use yii\console\Controller;
use yii2\mq_task\basic\MQEngine;
class MqController extends Controller
{
/**
* @return MQEngine
* @throws \yii\base\InvalidConfigException
*/
public function getMQ(){
return Yii::$app->get("messageQueue");
}
/**
* 启动MQ
*/
public function actionStart()
{
$this->getMQ()->start();
}
/**
* 停止MQ
*/
public function actionStop()
{
$this->getMQ()->stop();
}
/**
* MQ状态查询
*/
public function actionStatus()
{
$this->getMQ()->status();
}
/**
* 服务热重启
*/
public function actionReload()
{
$this->getMQ()->reload();
}
/**
* 重启服务
*/
public function actionRestart()
{
$this->getMQ()->restart();
}
}
php yii mq/start
php yii mq/stop
php yii mq/reload
php yii mq/restart
php yii mq/status
namespace console\mqTask;
use yii2\mq_task\basic\Task;
class InvoiceRedisEvent extends Task {
/**
* @param array $data
* @return bool
*/
public function consume(array $data): bool {
// TODO: Implement consume() method.
print_r($data);//在这里处理任务
return true;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.