確定消息只投遞了一次
<?php
namespace app\queue\redis;
use Webman\RedisQueue\Consumer;
class MyMailSend implements Consumer
{
// 要消費(fèi)的隊(duì)列名
public $queue = 'test_send_mail';
// 連接名,對應(yīng) config/redis_queue.php 里的連接`
public $connection = 'default';
// 消費(fèi)
public function consume($data)
{
var_dump('consume => '.date('Y-m-d H:i:s'));
// 無需反序列化
var_export($data); // 輸出 ['to' => 'tom@gmail.com', 'content' => 'hello']
}
}
'redis_consumer' => [
'handler' => Webman\RedisQueue\Process\Consumer::class,
'count' => 1, // 可以設(shè)置多進(jìn)程
'constructor' => [
// 消費(fèi)者類目錄
'consumer_dir' => app_path() . '/queue/redis'
]
]
string(30) "consume => 2021-12-17 16:36:20"
array (
'to' => 'tom@gmail.com',
'content' => 'hello',
'time' => '2021-12-17 16:36:20',
)string(30) "consume => 2021-12-17 16:37:20"
array (
'to' => 'tom@gmail.com',
'content' => 'hello',
'time' => '2021-12-17 16:36:20',
)