Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Yii2 Queue Laravel Package

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.

View on GitHub
Deep Wiki
Context7

AWS SQS Driver

The driver uses AWS SQS to store queue data.

You have to add aws/aws-sdk-php extension to your application in order to use it.

Configuration example for standard queues:

return [
    'bootstrap' => [
        'queue', // The component registers own console commands
    ],
    'components' => [
        'queue' => [
            'class' => \yii\queue\sqs\Queue::class,
            'url' => '<sqs url>',
            'key' => '<key>',
            'secret' => '<secret>',
            'region' => '<region>',
            'endpoint' => '<endpoint>', // https://docs.aws.amazon.com/general/latest/gr/sqs-service.html#sqs_region
        ],
    ],
];

Configuration example for FIFO queues:

return [
    'bootstrap' => [
        'queue', // The component registers own console commands
    ],
    'components' => [
        'queue' => [
            'class' => \yii\queue\sqs\Queue::class,
            'url' => '<sqs url>',
            'key' => '<key>',
            'secret' => '<secret>',
            'region' => '<region>',
            'messageGroupId' => '<Group ID>',
            'endpoint' => '<endpoint>', // https://docs.aws.amazon.com/general/latest/gr/sqs-service.html#sqs_region
        ],
    ],
];

The message group ID is required by SQS for FIFO queues. You can configure your own or use the "default" value.

The deduplication ID is generated automatically, so no matter if you have activated content-based deduplication in the SQS queue or not, this ID will be used.

Console

Console command is used to execute tasks.

yii queue/listen [timeout]

listen command launches a daemon which infinitely queries the queue. If there are new tasks they're immediately obtained and executed. timeout parameter is number of seconds to wait a job. It uses SQS "Long Polling" feature, that holds a connection between client and a queue.

Important: timeout parameter for SQS driver must be in range between 0 and 20 seconds.

This method is most efficient when command is properly daemonized via supervisor or systemd.

yii queue/run

run command obtains and executes tasks in a loop until queue is empty. Works well with cron.

run and listen commands have options:

  • --verbose, -v: print executing statuses into console.
  • --isolate: each task is executed in a separate child process.
  • --color: highlighting for verbose mode.
yii queue/clear

clear command clears a queue.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium