webman-redis-queue

0

队列配置如下:


'redis_consumer'  => [
'handler' => Webman\RedisQueue\Process\Consumer::class,
'count' => 8, // 可以设置多进程
'constructor' => [
// 消费者类目录
'consumer_dir' => app_path() . '/queue/redis'
]
]

consumer_dir下,有2个类
Email,消费队列send_mail
Sms,消费队列send_sms


这8个进程,和,这2个消费类之间,有什么联系吗?
这8个进程中,有几个是消费的send_mail队列?
这8个进程中,有几个是消费的send_sms队列?


后来,查看了vendor/webman/redis-queue/src/Process/Consumer.php


/**
* onWorkerStart.
*/
public function onWorkerStart()
{
$dir_iterator = new \RecursiveDirectoryIterator($this->_consumerDir);
$iterator = new \RecursiveIteratorIterator($dir_iterator);
foreach ($iterator as $file) {
if (is_dir($file)) {
continue;
}
$fileinfo = new \SplFileInfo($file);
$ext = $fileinfo->getExtension();
if ($ext === 'php') {
$class = str_replace('/', "\\", substr(substr($file, strlen(base_path())), 0, -4));
if (is_a($class, 'Webman\RedisQueue\Consumer', true)) {
$consumer = Container::get($class);
echo $class. PHP_EOL;

$connection_name = $consumer->connection ?? 'default';
$queue = $consumer->queue;
$connection = Client::connection($connection_name);
$connection->subscribe($queue, [$consumer, 'consume']);
}
}
}

}

可以理解为
这8个进程,每个进程
其实,同时subscribe了 send_mailsend_sms 两个队列吗?

已邀请:

latin - 挨踢男

赞同来自:

看起来是每个进程都同时消费send_mail 和 send_sms 两个队列

要回复问题请先登录注册