To create a new queue worker in Laravel using Artisan, follow the steps below:
Open your terminal and navigate to your Laravel project's root directory.
Run the following command to create a new queue worker using Artisan:
php artisan queue:work
By default, the worker will use the redis
queue connection. If you want to use a different queue connection, you can specify it like this:
php artisan queue:work --queue=connection_name
Replace connection_name
with the name of your queue connection as defined in your config/queue.php
file.
--tries
flag followed by the number of tries you want the worker to attempt:php artisan queue:work --tries=3
This example sets the maximum number of tries to 3 before giving up on a job.
php artisan queue:work --queue=queue_name,another_queue_name
Replace queue_name
and another_queue_name
with the names of the queues you want the worker to listen to.
php artisan queue:work connection_name --queue=queue_name
Replace connection_name
and queue_name
with your desired connection and queue names.
--daemon
option:php artisan queue:work --daemon
This will start the worker as a background process.
That's it! You have now created a new queue worker using Artisan in Laravel. The worker will listen for jobs in the specified queue(s) and process them accordingly.