yiisoft/yii2-queue
Yii2 Queue runs tasks asynchronously via pluggable queue backends: DB, Redis, RabbitMQ/AMQP, Beanstalk, ActiveMQ, and Gearman. Define jobs as classes implementing JobInterface and push them to the queue for background processing.
config/console.php and extending yii\base\Application with the queue component). Example:
'components' => [
'queue' => [
'class' => 'yii\queue\Queue',
'as log' => 'yii\queue\log\QueueLog', // Log failed jobs
'as retry' => [
'class' => 'yii\queue\retry\QueueRetry',
'retryCount' => 3,
],
'as mutator' => 'yii\queue\db\QueueMutator', // DB backend
'db' => 'db', // Yii2 DB component
],
],
Queue, Job) in a facade or adapter layer to avoid tight coupling. Example:
// Pseudocode for non-Yii2 integration
$queue = new \yii\queue\Queue([
'as mutator' => new \yii\queue\redis\QueueMutator(['redis' => $redisClient]),
]);
namespace app\jobs;
use yii\queue\JobInterface;
class SendWelcomeEmail implements JobInterface {
public $userId;
public $email;
public function execute($queue) {
// Logic to send email via Yii2's mail component
}
}
Yii::$app->queue->push(new SendWelcomeEmail(['userId' => 1, 'email' => 'user@example.com']));
QueueLog).yii queue/run --queue=default --concurrency=10
class QueueFacade {
private $queue;
public function __construct() {
$this->queue = new \yii\queue\Queue(['as mutator' => new \yii\queue\redis\QueueMutator(['redis' => new \Redis()])]);
}
public function push(JobInterface $job) { /* ... */ }
}
redis/redis-php package.php-amqplib.aws/aws-sdk-php.pda/pheanstalk.How can I help you explore Laravel packages today?