1. Go to this page and download the library: Download bang/queue 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/ */
bang / queue example snippets
declare (strict_types=1);
namespace app\queue\test;
use bang\queue\Consumer;
class Consume implements Consumer
{
/**
* 队列名称
* @var string
*/
public static string $queue = 'queue1';
/**
* 使用的链接
* @var string
*/
public static string $connection = 'default';
/**
* 消费逻辑
* @param $data
* @return void
* @throws \Throwable
*/
public function consume($data)
{
throw new \Error('抛出异常就会重新执行队列,直到重试次数');
}
/**
* 失败回调逻辑
* @param $data
* @return void
* @throws \Throwable
*/
public function onConsumeFailure(\Throwable $e, $package)
{
//这里是每一次执行失败时会调用,你可以写任何的邮件、短信等等通知
//$package 包含了 attempts 已经重试的次数。data,生产者发布的数据。error,是错误信息。
}
}