35 lines
721 B
PHP
35 lines
721 B
PHP
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use Hyperf\AsyncQueue\Driver\DriverFactory;
|
|
use Hyperf\AsyncQueue\Driver\DriverInterface;
|
|
|
|
/**
|
|
* 消息投递
|
|
*/
|
|
class QueueService
|
|
{
|
|
/**
|
|
* @var DriverInterface
|
|
*/
|
|
protected DriverInterface $driver;
|
|
|
|
public function __construct(DriverFactory $driverFactory)
|
|
{
|
|
$this->driver = $driverFactory->get('default');
|
|
}
|
|
|
|
/**
|
|
* 生产消息.
|
|
* @param array $params 数据
|
|
* @param int $delay 延时时间 单位秒
|
|
* @param string $queue_name
|
|
* @return bool
|
|
*/
|
|
public function push(string $queue_name, array $params, int $delay = 0): bool
|
|
{
|
|
return $this->driver->push(new $queue_name($params), $delay);
|
|
}
|
|
}
|