fbpx

SQS Queue in Laravel Not Working

I recently switched a client site to use AWS SQS as the queue provider instead of a database to speed things up a bit. After creating a standard Queue in SQS, adding the AWS SQS credentials to the config/queue.php file per Laravel’s documentation, and updating the QUEUE_DRIVER in the .env file, I could see that the jobs were being sent to the SQS queue but they were not being processed by the application.

I finally figured out the solution. It involves 2 simple steps: modify the supervisor configuration file and then update and restart supervisor.

Step 1: Update Supervisor Configuration File

The application was using Supervisor to automate the processing of the queue. The supervisor configuration files are typically located in /etc/supervisor/conf.d. The default configuration file within this directory tends to be called laravel-worker.conf. The laravel-worker.conf file contained the following line:

command=php /var/www/html/artisan queue:work database --sleep=3 --tries=3

In this file, I had to change the queue:work database portion of the command line to reflect the new SQS queue connection. See the updated line below:

command=php /var/www/html/artisan queue:work sqs --sleep=3 --tries=3

You could use these directions to switch to any queue connection. The key is to update the `queue:work sqs` portion of the command directive in your configuration file to use the new queue connection.

Step 2: Update and Restart Supervisor

After I updated that supervisor configuration file, I had to run the following commands to update Supervisor and restart the queue processing:

sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl restart all

This worked like a charm for me, but if you need some additional information on configuring Supervisor, make sure you have completed the following steps:

  • create your standard queue in SQS
  • update your config/queue.php file to use your SQS credentials (add more environment variables to your .env file and reference them in the config/queue.php file)
  • update your QUEUE_DRIVER in your .env, so it’s set to QUEUE_DRIVER=SQS
  • update your supervisor configuration file (typically /etc/supervisor/conf.d/laravel-worker.conf)
  • update and restart supervisor

If you still haven’t been able to get it to work, check out Laravel’s documentation.

Leave a Reply

Your email address will not be published. Required fields are marked *